MADARA  3.4.1
madara::knowledge::KnowledgeRecord Class Reference

This class encapsulates an entry in a KnowledgeBase. More...

#include <KnowledgeRecord.h>

Public Types

enum  { UNCREATED = 0 , MODIFIED = 1 }
 
enum  { OWNED = 0 , SHARED = 1 }
 
using CircBuf = utility::CircularBuffer< KnowledgeRecord >
 
typedef int64_t Integer
 
enum  ValueTypes : uint32_t {
  EMPTY = 0 , INTEGER = 1 , STRING = 2 , DOUBLE = 4 ,
  FLOAT = 4 , UNKNOWN_FILE_TYPE = 8 , XML = 16 , TEXT_FILE = 32 ,
  INTEGER_ARRAY = 64 , DOUBLE_ARRAY = 128 , IMAGE_JPEG = 256 , ALL_ARRAYS = INTEGER_ARRAY | DOUBLE_ARRAY ,
  ALL_INTEGERS = INTEGER | INTEGER_ARRAY , ALL_DOUBLES = DOUBLE | DOUBLE_ARRAY , ALL_PRIMITIVE_TYPES , ALL_FILE_TYPES = UNKNOWN_FILE_TYPE | XML | TEXT_FILE | IMAGE_JPEG ,
  ALL_IMAGES = IMAGE_JPEG , ALL_TEXT_FORMATS = XML | TEXT_FILE | STRING , ALL_TYPES = ALL_PRIMITIVE_TYPES | ALL_FILE_TYPES , ALL_CLEARABLES = ALL_ARRAYS | ALL_TEXT_FORMATS | ALL_FILE_TYPES ,
  BUFFER = (1UL << 31)
}
 

Public Member Functions

 KnowledgeRecord () noexcept
 
 KnowledgeRecord (CircBuf &&buffer, logger::Logger &logger= *logger::global_logger.get()) noexcept
 Construct using CircularBuffer directly. More...
 
 KnowledgeRecord (const char *value, logger::Logger &logger= *logger::global_logger.get())
 
 KnowledgeRecord (const CircBuf &buffer, logger::Logger &logger= *logger::global_logger.get())
 Construct using CircularBuffer directly. More...
 
 KnowledgeRecord (const KnowledgeRecord &rhs)
 copy constructor More...
 
 KnowledgeRecord (const std::string &value, logger::Logger &logger= *logger::global_logger.get())
 
 KnowledgeRecord (const std::vector< double > &value, logger::Logger &logger= *logger::global_logger.get())
 
 KnowledgeRecord (const std::vector< Integer > &value, logger::Logger &logger= *logger::global_logger.get())
 
 KnowledgeRecord (KnowledgeRecord &&rhs) noexcept
 move constructor More...
 
 KnowledgeRecord (logger::Logger &logger) noexcept
 
 KnowledgeRecord (std::string &&value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::unique_ptr< std::string > value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::unique_ptr< std::vector< double >> value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::unique_ptr< std::vector< Integer >> value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::unique_ptr< std::vector< unsigned char >> value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::vector< double > &&value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
 KnowledgeRecord (std::vector< Integer > &&value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
template<typename T , utility::enable_if_< utility::is_int_numeric< T >(), int > = 0>
 KnowledgeRecord (T value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
 KnowledgeRecord (T value, logger::Logger &logger= *logger::global_logger.get()) noexcept
 
template<typename... Args>
 KnowledgeRecord (tags::binary_t, Args &&... args)
 Forwarding constructor for binary files (blobs) Each argument past the first will be forwarded to construct a std::vector<unsigned char> in-place within the new record. More...
 
template<typename... Args>
 KnowledgeRecord (tags::doubles_t, Args &&... args)
 Forwarding constructor for double arrays Each argument past the first will be forwarded to construct a std::vector<double> in-place within the new record. More...
 
template<typename... Args>
 KnowledgeRecord (tags::integers_t, Args &&... args)
 Forwarding constructor for integer arrays Each argument past the first will be forwarded to construct a std::vector<Integer> in-place within the new record. More...
 
template<typename... Args>
 KnowledgeRecord (tags::string_t, Args &&... args)
 Forwarding constructor for strings Each argument past the first will be forwarded to construct a std::string in-place within the new record. More...
 
 ~KnowledgeRecord () noexcept
 
int apply (madara::knowledge::ThreadSafeContext &context, const std::string &key, unsigned int quality, uint64_t clock, bool perform_lock)
 Apply the knowledge record to a context, given some quality and clock. More...
 
void clear_history ()
 Clear all history for this record, keeping the current value. More...
 
void clear_value (void) noexcept
 clears any dynamic values. More...
 
KnowledgeRecordclone (void) const
 clones the record. More...
 
void copy_metadata (const KnowledgeRecord &new_value)
 Set metadata of this record equal to that of new_value, but doesn't change value. More...
 
KnowledgeRecord dec_index (size_t index)
 decrements the value at the index to the specified value. More...
 
KnowledgeRecord deep_copy () const
 Creates a deep copy of this knowledge record. More...
 
void deep_copy (const KnowledgeRecord &source)
 Creates a deep copy of the knowledge record. More...
 
template<typename... Args>
void emplace (tags::binary_t, Args &&... args)
 Construct a binary (vector of unsigned char) within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace (tags::doubles_t, Args &&... args)
 Construct a vector of doubles within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace (tags::integers_t, Args &&... args)
 Construct a vector of integers within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace (tags::string_t, Args &&... args)
 Construct a string within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace_doubles (Args &&... args)
 Construct a vector of doubles within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace_file (Args &&... args)
 Construct a file (vector of unsigned char) within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace_integers (Args &&... args)
 Construct a vector of integers within this KnowledgeRecord. More...
 
template<typename... Args>
void emplace_string (Args &&... args)
 Construct a string within this KnowledgeRecord. More...
 
bool exists (void) const
 Checks if record exists (i.e., is not uncreated) More...
 
template<typename Func >
size_t for_history_range (Func &&func, size_t index, size_t count) const
 Execute a callable for each history element. More...
 
KnowledgeRecord fragment (unsigned int first, unsigned int last)
 returns a record containing a fragment of the character buffer. More...
 
int64_t get_encoded_size (const std::string &key) const
 Returns the encoded size of the record. More...
 
int64_t get_encoded_size (void) const
 Returns the encoded size of the record. More...
 
std::vector< KnowledgeRecordget_history () const
 Get a copy of the entire stored history of this record. More...
 
template<typename T >
std::vector< T > get_history () const
 Get a copy of the entire stored history of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord. More...
 
template<typename OutputIterator >
auto get_history (OutputIterator out) const -> decltype(*out, size_t{})
 Copy the stored history of this record to the given output iterator, in order from oldest to newest. More...
 
template<typename OutputIterator >
size_t get_history (OutputIterator out, ssize_t index, size_t count) const
 Copy the given range of history to the output iterator given. More...
 
KnowledgeRecord get_history (size_t index) const
 Return the given entry in this record's history. More...
 
std::vector< KnowledgeRecordget_history (size_t index, size_t count) const
 Return a copy of the given range of history in a vector. More...
 
size_t get_history_capacity () const
 Return the maximum amount of history this record can hold. More...
 
size_t get_history_newest_index () const
 Gets the absolute index of the newest element in stored history. More...
 
size_t get_history_oldest_index () const
 Gets the absolute index of the oldest element in stored history. More...
 
template<typename OutputIterator >
size_t get_history_range (OutputIterator out, size_t index, size_t count) const
 Copy the given absolute range of history to the output iterator given. More...
 
size_t get_history_size () const
 Return the amount of history this record holds. More...
 
KnowledgeRecord get_newest () const
 Return the newest stored history entry of this record. More...
 
template<typename OutputIterator >
auto get_newest (OutputIterator out) const -> decltype(*out, size_t{})
 Copy the newest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator >
size_t get_newest (OutputIterator out, size_t count) const
 Copy the count newest stored history entries of this record to the given output iterator, in order from oldest to newest. More...
 
std::vector< KnowledgeRecordget_newest (size_t count) const
 Return the count newest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_newest (size_t count) const
 Return the count newest stored history entries of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord. More...
 
KnowledgeRecord get_oldest () const
 Return the oldest stored history entry of this record. More...
 
template<typename OutputIterator >
auto get_oldest (OutputIterator out) const -> decltype(*out, size_t{})
 Copy the oldest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator >
size_t get_oldest (OutputIterator out, size_t count) const
 Copy the count oldest stored history entries of this record to the given output iterator, in order from oldest to newest. More...
 
std::vector< KnowledgeRecordget_oldest (size_t count) const
 Return the count oldest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_oldest (size_t count) const
 Return the count oldest stored history entries of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord. More...
 
bool has_history () const
 Return true if this record has a circular buffer history. More...
 
KnowledgeRecord inc_index (size_t index)
 increments the value at the index to the specified value. More...
 
bool is_array_type (void) const
 returns if the record is an array type (DOUBLE_ARRAY, INTEGER_ARRAY) More...
 
bool is_binary_file_type (void) const
 returns true if the knowledge record has a binary file type More...
 
bool is_double_type (void) const
 returns if the record is a double type (DOUBLE, DOUBLE_ARRAY) More...
 
bool is_false (void) const
 Checks to see if the record is false. More...
 
bool is_file_type (void) const
 returns true if the knowledge record has a file type More...
 
bool is_image_type (void) const
 returns true if the knowledge record has an image type More...
 
bool is_integer_type (void) const
 returns if the record is a integer type (INTEGER, INTEGER_ARRAY) More...
 
bool is_ref_counted (void) const
 returns if the record has a reference-counted type More...
 
bool is_string_type (void) const
 returns true if the record is a string type (STRING, XML, TEXT_FILE) More...
 
bool is_true (void) const
 Checks to see if the record is true. More...
 
bool is_valid (void) const
 Checks to see if the record is valid. More...
 
 operator bool (void) const
 Explicit bool cast. More...
 
bool operator! (void) const
 Logical not. More...
 
bool operator!= (const KnowledgeRecord &rhs) const
 Unequal to. More...
 
KnowledgeRecord operator% (const KnowledgeRecord &rhs) const
 Modulus operator. More...
 
KnowledgeRecordoperator%= (const KnowledgeRecord &rhs)
 In-place modulus operator. More...
 
KnowledgeRecord operator* (const KnowledgeRecord &rhs) const
 Times operator. More...
 
KnowledgeRecordoperator*= (const KnowledgeRecord &rhs)
 In-place multiplication operator. More...
 
KnowledgeRecord operator+ (const KnowledgeRecord &rhs) const
 Plus operator. More...
 
KnowledgeRecordoperator++ (void)
 Preincrement operator. More...
 
KnowledgeRecordoperator+= (const KnowledgeRecord &rhs)
 In-place addition operator. More...
 
KnowledgeRecord operator- (const KnowledgeRecord &rhs) const
 Minus operator. More...
 
KnowledgeRecord operator- (void) const
 Negate. More...
 
KnowledgeRecordoperator-- (void)
 Predecrement operator. More...
 
KnowledgeRecordoperator-= (const KnowledgeRecord &rhs)
 In-place subtraction operator. More...
 
KnowledgeRecord operator/ (const KnowledgeRecord &rhs) const
 Divides operator. More...
 
KnowledgeRecordoperator/= (const KnowledgeRecord &rhs)
 In-place division operator. More...
 
bool operator< (const KnowledgeRecord &rhs) const
 Less than. More...
 
bool operator<= (const KnowledgeRecord &rhs) const
 Less than or equal to. More...
 
KnowledgeRecordoperator= (const KnowledgeRecord &rhs)
 Assignment. More...
 
KnowledgeRecordoperator= (KnowledgeRecord &&rhs) noexcept
 Move Assignment. More...
 
template<typename T >
auto operator= (T &&t) -> typename std::enable_if<!std::is_convertible< T, KnowledgeRecord >::value, decltype(this->set_value(std::forward< T >(t)), *this)>::type
 Assigns a convertible value to the knowledge record. More...
 
bool operator== (const KnowledgeRecord &rhs) const
 Equal to. More...
 
bool operator> (const KnowledgeRecord &rhs) const
 Greater than. More...
 
bool operator>= (const KnowledgeRecord &rhs) const
 Greater than or equal to. More...
 
void overwrite (const KnowledgeRecord &new_value)
 Clears everything including history, but excluding metadata (e.g., toi, clock) and copies value from new_value into this recod. More...
 
void overwrite (KnowledgeRecord &&new_value)
 Clears everything including history, but excluding metadata (e.g., toi, clock) and moves value from new_value into this recod. More...
 
template<typename... Args>
void overwrite_circular_buffer (Args &&... args)
 Construct a CircularBuffer within this KnowledgeRecord directly. More...
 
const char * read (const char *buffer, int64_t &buffer_remaining)
 Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining. More...
 
const char * read (const char *buffer, std::string &key, int64_t &buffer_remaining)
 Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining. More...
 
const char * read (const char *buffer, uint32_t &key_id, int64_t &buffer_remaining)
 Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining. More...
 
int read_file (const std::string &filename, uint32_t read_as_type=0)
 reads a file and sets the type appropriately according to the extension More...
 
void reset_value (void) noexcept
 resets the variable to an integer More...
 
void resize (size_t new_size)
 resizes an array to a new size More...
 
KnowledgeRecord retrieve_index (size_t index) const
 retrieves the value at an array index. More...
 
void set_file (const std::vector< unsigned char > &new_value)
 sets the value to an unknown file type More...
 
void set_file (const unsigned char *new_value, size_t size)
 sets the value to an unknown file type More...
 
void set_file (std::unique_ptr< std::vector< unsigned char >> new_value)
 sets the value to an unknown file type, without copying More...
 
void set_file (std::vector< unsigned char > &&new_value)
 sets the value to an unknown file type, without copying More...
 
void set_full (const KnowledgeRecord &new_value)
 Sets the value and meta data from another KnowledgeRecord. More...
 
void set_full (KnowledgeRecord &&new_value)
 Sets the value and meta data from another KnowledgeRecord. More...
 
void set_history_capacity (size_t size)
 Set the capacity of this record's history circular buffer. More...
 
template<typename T , utility::enable_if_< utility::is_int_numeric< T >(), int > = 0>
void set_index (size_t index, T value)
 sets the value at the index to the specified value. More...
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
void set_index (size_t index, T value)
 sets the value at the index to the specified value. More...
 
void set_jpeg (const std::vector< unsigned char > &new_value)
 sets the value to a jpeg More...
 
void set_jpeg (const unsigned char *new_value, size_t size)
 sets the value to a jpeg More...
 
void set_jpeg (std::unique_ptr< std::vector< unsigned char >> new_value)
 sets the value to a jpeg, without copying More...
 
void set_jpeg (std::vector< unsigned char > &&new_value)
 sets the value to a jpeg, without copying More...
 
void set_modified (void)
 sets the status to modified More...
 
void set_text (const char *new_value, size_t size)
 sets the value to a plaintext string More...
 
void set_text (const std::string &new_value)
 sets the value to a plaintext string More...
 
void set_text (std::string &&new_value)
 sets the value to a plaintext string More...
 
void set_text (std::unique_ptr< std::string > new_value)
 sets the value to a plaintext string. More...
 
void set_toi (uint64_t new_toi)
 
bool set_type (uint32_t type)
 Modify the type, but only if it's compatible with current type without changing any actual data stored. More...
 
void set_value (const char *new_value, uint32_t size)
 sets the value to a string, from a buffer More...
 
void set_value (const double *new_value, uint32_t size)
 sets the value to an array of doubles More...
 
void set_value (const Integer *new_value, uint32_t size)
 sets the value to an array of integers More...
 
void set_value (const KnowledgeRecord &new_value)
 Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality. More...
 
void set_value (const std::string &new_value)
 sets the value to a string More...
 
void set_value (const std::vector< double > &new_value)
 sets the value to an array of doubles More...
 
void set_value (const std::vector< Integer > &new_value)
 sets the value to an array of integers More...
 
void set_value (double new_value)
 sets the value to a double More...
 
void set_value (float new_value)
 sets the value to a float More...
 
void set_value (int new_value)
 sets the value to an integer More...
 
void set_value (Integer new_value)
 sets the value to an integer More...
 
void set_value (KnowledgeRecord &&new_value)
 Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality. More...
 
void set_value (size_t new_value)
 sets the value to an integer More...
 
void set_value (std::string &&new_value)
 sets the value to a string More...
 
void set_value (std::unique_ptr< std::string > new_value)
 sets the value to a string. More...
 
void set_value (std::unique_ptr< std::vector< double >> new_value)
 sets the value to an array of doubles, without copying More...
 
void set_value (std::unique_ptr< std::vector< Integer >> new_value)
 sets the value to an array of integers, without copying More...
 
void set_value (std::vector< double > &&new_value)
 sets the value to an array of doubles More...
 
void set_value (std::vector< Integer > &&new_value)
 sets the value to an array of integers More...
 
void set_xml (const char *new_value, size_t size)
 sets the value to an xml string More...
 
void set_xml (const std::string &new_value)
 sets the value to an xml string More...
 
void set_xml (std::string &&new_value)
 sets the value to an xml string More...
 
void set_xml (std::unique_ptr< std::string > new_value)
 sets the value to an xml string. More...
 
std::shared_ptr< const std::vector< unsigned char > > share_binary () const
 
std::shared_ptr< CircBufshare_circular_buffer () const
 Get a shared_ptr to the history buffer inside this record. More...
 
std::shared_ptr< const std::vector< double > > share_doubles () const
 
std::shared_ptr< const std::vector< Integer > > share_integers () const
 
std::shared_ptr< const std::string > share_string () const
 
uint32_t size (void) const
 returns the size of the value More...
 
int status (void) const
 returns the status of the record. More...
 
double to_double (void) const
 converts the value to a float/double. More...
 
std::vector< double > to_doubles (void) const
 converts the value to a vector of doubles More...
 
ssize_t to_file (const std::string &filename) const
 writes the value to a file More...
 
Integer to_integer (void) const
 converts the value to an integer. More...
 
std::vector< Integerto_integers (void) const
 converts the value to a vector of integers More...
 
size_t to_managed_buffer (char *buffer, size_t buf_size) const
 converts the value to a c string. More...
 
size_t to_managed_string (char *buffer, size_t buf_size) const
 converts the value to a c string. More...
 
std::string to_string (const std::string &delimiter=", ") const
 converts the value to a string. More...
 
unsigned char * to_unmanaged_buffer (size_t &size) const
 returns an unmanaged buffer that the user will have to take care of (this is a copy of the internal value). More...
 
uint64_t toi () const
 
uint32_t type (void) const
 returns the type of the value More...
 
void unshare (void)
 If this record holds a shared_ptr, make a copy of the underlying value so it has an exclusive copy. More...
 
char * write (char *buffer, const std::string &key, int64_t &buffer_remaining) const
 Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining. More...
 
char * write (char *buffer, int64_t &buffer_remaining) const
 Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining. More...
 
char * write (char *buffer, uint32_t key_id, int64_t &buffer_remaining) const
 Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining. More...
 

Static Public Member Functions

static int get_precision (void)
 Gets the current double precision for double to string conversion. More...
 
static bool is_array_type (uint32_t type)
 returns if the record is a array type (DOUBLE_ARRAY, INTEGER_ARRAY) More...
 
static bool is_binary_file_type (uint32_t type)
 returns true if the knowledge record has a binary file type More...
 
static bool is_double_type (uint32_t type)
 returns if the record is a double type (DOUBLE, DOUBLE_ARRAY) More...
 
static bool is_file_type (uint32_t type)
 returns true if the knowledge record has a file type More...
 
static bool is_image_type (uint32_t type)
 returns true if the knowledge record has an image type More...
 
static bool is_integer_type (uint32_t type)
 returns if the record is a integer type (INTEGER, INTEGER_ARRAY) More...
 
static bool is_ref_counted (uint32_t type)
 returns if the record has a reference-counted type More...
 
static bool is_string_type (uint32_t type)
 returns if the record is a string type (STRING, XML, TEXT_FILE) More...
 
static void set_fixed (void)
 Sets the output format for doubles to std::fixed. More...
 
static void set_precision (int new_precision)
 Sets the double precision of a double record when using to_string (). More...
 
static void set_scientific (void)
 Sets the output format for doubles to std::scientific. More...
 

Public Attributes

uint64_t clock = 0
 last modification lamport clock time More...
 
uint32_t quality = 0
 priority of the update More...
 
uint32_t write_quality = 0
 write priority for any local updates More...
 
std::shared_ptr< CircBufbuf_
 
std::shared_ptr< std::vector< double > > double_array_
 
double double_value_
 
std::shared_ptr< std::vector< unsigned char > > file_value_
 
std::shared_ptr< std::vector< Integer > > int_array_
 
Integer int_value_ = 0
 
std::shared_ptr< std::string > str_value_
 

Private Types

template<typename T >
using MemberType = std::shared_ptr< T > KnowledgeRecord::*
 

Private Member Functions

size_t absolute_index (ssize_t index) const
 
void clear_union (void) noexcept
 
template<typename... Args>
KnowledgeRecordemplace_hist (Args &&... args)
 
template<typename T , uint32_t Type, MemberType< T > Member, bool Overwrite = false, typename... Args>
std::shared_ptr< const T > emplace_shared_val (Args &&... args)
 
template<typename T , uint32_t Type, MemberType< std::vector< T >> Member, bool Overwrite = false, typename... Args>
std::shared_ptr< const std::vector< T > > emplace_shared_vec (Args &&... args)
 
template<typename T , uint32_t Type, MemberType< T > Member, bool Overwrite = false, typename... Args>
std::shared_ptr< const T > emplace_val (Args &&... args)
 
template<typename T , uint32_t Type, MemberType< std::vector< T >> Member, bool Overwrite = false, typename... Args>
std::shared_ptr< const std::vector< T > > emplace_vec (Args &&... args)
 
KnowledgeRecordref_newest ()
 
const KnowledgeRecordref_newest () const
 

Private Attributes

union {
   std::shared_ptr< CircBuf >   buf_
 
   std::shared_ptr< std::vector< double > >   double_array_
 
   double   double_value_
 
   std::shared_ptr< std::vector< unsigned char > >   file_value_
 
   std::shared_ptr< std::vector< Integer > >   int_array_
 
   Integer   int_value_ = 0
 
   std::shared_ptr< std::string >   str_value_
 
}; 
 Non-array versions of double/integer. More...
 
logger::Loggerlogger_ = logger::global_logger.get()
 the logger used for any internal debugging information More...
 
bool shared_ = OWNED
 is this knowledge record's shared_ptr, if any, exposed to outside holders? More...
 
uint64_t toi_ = 0
 last modification system clock time More...
 
uint32_t type_ = EMPTY
 type of variable (INTEGER, DOUBLE, STRING, FILE, IMAGE) More...
 

Friends

class ThreadSafeContext
 

Detailed Description

This class encapsulates an entry in a KnowledgeBase.

Definition at line 87 of file KnowledgeRecord.h.

Member Typedef Documentation

◆ CircBuf

◆ Integer

Definition at line 131 of file KnowledgeRecord.h.

◆ MemberType

template<typename T >
using madara::knowledge::KnowledgeRecord::MemberType = std::shared_ptr<T> KnowledgeRecord::*
private

Definition at line 1772 of file KnowledgeRecord.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
UNCREATED 
MODIFIED 

Definition at line 93 of file KnowledgeRecord.h.

◆ anonymous enum

anonymous enum
Enumerator
OWNED 
SHARED 

Definition at line 99 of file KnowledgeRecord.h.

◆ ValueTypes

Enumerator
EMPTY 
INTEGER 
STRING 
DOUBLE 
FLOAT 
UNKNOWN_FILE_TYPE 
XML 
TEXT_FILE 
INTEGER_ARRAY 
DOUBLE_ARRAY 
IMAGE_JPEG 
ALL_ARRAYS 
ALL_INTEGERS 
ALL_DOUBLES 
ALL_PRIMITIVE_TYPES 
ALL_FILE_TYPES 
ALL_IMAGES 
ALL_TEXT_FORMATS 
ALL_TYPES 
ALL_CLEARABLES 
BUFFER 

Definition at line 105 of file KnowledgeRecord.h.

Constructor & Destructor Documentation

◆ KnowledgeRecord() [1/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( )
inlinenoexcept

Definition at line 205 of file KnowledgeRecord.h.

◆ KnowledgeRecord() [2/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( logger::Logger logger)
inlineexplicitnoexcept

Definition at line 25 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [3/23]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type >
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 32 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [4/23]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( value,
logger::Logger logger = *logger::global_logger.get() 
)
explicitnoexcept

◆ KnowledgeRecord() [5/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const std::vector< Integer > &  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicit

Definition at line 46 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [6/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::vector< Integer > &&  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 53 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [7/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::unique_ptr< std::vector< Integer >>  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 60 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [8/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const std::vector< double > &  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicit

Definition at line 68 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [9/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::vector< double > &&  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 75 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [10/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::unique_ptr< std::vector< double >>  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 82 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [11/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const std::string &  value,
logger::Logger logger = *logger::global_logger.get() 
)
inline

Definition at line 89 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [12/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::string &&  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 96 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [13/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::unique_ptr< std::string >  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 103 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [14/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const char *  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicit

Definition at line 110 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [15/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( std::unique_ptr< std::vector< unsigned char >>  value,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Definition at line 117 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [16/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const CircBuf buffer,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicit

Construct using CircularBuffer directly.

This buffer will be treated as the history of this record, and used as such going forward.

Parameters
bufferbuffer that will be copied into this record
loggerthe logger to use for logging

Definition at line 125 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [17/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( CircBuf &&  buffer,
logger::Logger logger = *logger::global_logger.get() 
)
inlineexplicitnoexcept

Construct using CircularBuffer directly.

This buffer will be treated as the history of this record, and used as such going forward.

Parameters
bufferbuffer that will be copied into this record
loggerthe logger to use for logging

Definition at line 132 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [18/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( const KnowledgeRecord rhs)
inline

copy constructor

Parameters
rhsvalue to copy

Definition at line 138 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [19/23]

madara::knowledge::KnowledgeRecord::KnowledgeRecord ( knowledge::KnowledgeRecord &&  rhs)
inlinenoexcept

move constructor

Parameters
rhsvalue to copy

Definition at line 168 of file KnowledgeRecord.inl.

◆ ~KnowledgeRecord()

madara::knowledge::KnowledgeRecord::~KnowledgeRecord ( )
inlinenoexcept

Definition at line 202 of file KnowledgeRecord.inl.

◆ KnowledgeRecord() [20/23]

template<typename... Args>
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( tags::integers_t  ,
Args &&...  args 
)
inline

Forwarding constructor for integer arrays Each argument past the first will be forwarded to construct a std::vector<Integer> in-place within the new record.

Definition at line 414 of file KnowledgeRecord.h.

◆ KnowledgeRecord() [21/23]

template<typename... Args>
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( tags::doubles_t  ,
Args &&...  args 
)
inline

Forwarding constructor for double arrays Each argument past the first will be forwarded to construct a std::vector<double> in-place within the new record.

Definition at line 427 of file KnowledgeRecord.h.

◆ KnowledgeRecord() [22/23]

template<typename... Args>
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( tags::string_t  ,
Args &&...  args 
)
inline

Forwarding constructor for strings Each argument past the first will be forwarded to construct a std::string in-place within the new record.

For example: KnowledgeRecord rec (tags::string, "Hello World");

Definition at line 443 of file KnowledgeRecord.h.

◆ KnowledgeRecord() [23/23]

template<typename... Args>
madara::knowledge::KnowledgeRecord::KnowledgeRecord ( tags::binary_t  ,
Args &&...  args 
)
inline

Forwarding constructor for binary files (blobs) Each argument past the first will be forwarded to construct a std::vector<unsigned char> in-place within the new record.

Definition at line 455 of file KnowledgeRecord.h.

Member Function Documentation

◆ absolute_index()

size_t madara::knowledge::KnowledgeRecord::absolute_index ( ssize_t  index) const
inlineprivate

Definition at line 1460 of file KnowledgeRecord.h.

◆ apply()

int madara::knowledge::KnowledgeRecord::apply ( madara::knowledge::ThreadSafeContext context,
const std::string &  key,
unsigned int  quality,
uint64_t  clock,
bool  perform_lock 
)

Apply the knowledge record to a context, given some quality and clock.

Definition at line 1308 of file KnowledgeRecord.cpp.

◆ clear_history()

void madara::knowledge::KnowledgeRecord::clear_history ( )
inline

Clear all history for this record, keeping the current value.

Definition at line 1454 of file KnowledgeRecord.h.

◆ clear_union()

void madara::knowledge::KnowledgeRecord::clear_union ( void  )
inlineprivatenoexcept

Definition at line 966 of file KnowledgeRecord.inl.

◆ clear_value()

void madara::knowledge::KnowledgeRecord::clear_value ( void  )
inlinenoexcept

clears any dynamic values.

This method does not attempt to set the value of the Knowledge Record, as clear does, and is consequently more efficient.

Definition at line 984 of file KnowledgeRecord.inl.

◆ clone()

KnowledgeRecord * madara::knowledge::KnowledgeRecord::clone ( void  ) const
inline

clones the record.

Caller must ensure returned pointer is deleted.

Definition at line 707 of file KnowledgeRecord.inl.

◆ copy_metadata()

void madara::knowledge::KnowledgeRecord::copy_metadata ( const KnowledgeRecord new_value)
inline

Set metadata of this record equal to that of new_value, but doesn't change value.

Metadata is toi, clock, quality, write_quality, and logger.

Definition at line 207 of file KnowledgeRecord.inl.

◆ dec_index()

KnowledgeRecord madara::knowledge::KnowledgeRecord::dec_index ( size_t  index)

decrements the value at the index to the specified value.

If the record was previously not an array or if the array is not large enough, a new array is created.

Parameters
indexindex of the value to set

Definition at line 1188 of file KnowledgeRecord.cpp.

◆ deep_copy() [1/2]

KnowledgeRecord madara::knowledge::KnowledgeRecord::deep_copy ( ) const
inline

Creates a deep copy of this knowledge record.

Because each Knowledge Record may contain non-thread-safe ref counted values, user threads that reference knowledge records will want to use their own ref counts, which can be accomplished via this method.

Returns
a deep copy of this knowledge record

Definition at line 722 of file KnowledgeRecord.inl.

◆ deep_copy() [2/2]

void madara::knowledge::KnowledgeRecord::deep_copy ( const KnowledgeRecord source)
inline

Creates a deep copy of the knowledge record.

Because each Knowledge Record may contain non-thread-safe ref counted values, user threads that reference knowledge records will want to use their own ref counts, which can be accomplished via this method.

Parameters
sourcethe Knowledge Record we wish to copy

Definition at line 716 of file KnowledgeRecord.inl.

◆ emplace() [1/4]

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace ( tags::binary_t  ,
Args &&...  args 
)
inline

Construct a binary (vector of unsigned char) within this KnowledgeRecord.

Parameters
argsarguments forwarded to the vector constructor

Definition at line 388 of file KnowledgeRecord.h.

◆ emplace() [2/4]

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace ( tags::doubles_t  ,
Args &&...  args 
)
inline

Construct a vector of doubles within this KnowledgeRecord.

Parameters
argsarguments forwarded to the vector constructor

Definition at line 342 of file KnowledgeRecord.h.

◆ emplace() [3/4]

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace ( tags::integers_t  ,
Args &&...  args 
)
inline

Construct a vector of integers within this KnowledgeRecord.

Parameters
argsarguments forwarded to the vector constructor

Definition at line 319 of file KnowledgeRecord.h.

◆ emplace() [4/4]

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace ( tags::string_t  ,
Args &&...  args 
)
inline

Construct a string within this KnowledgeRecord.

Parameters
argsarguments forwarded to the string constructor

Definition at line 365 of file KnowledgeRecord.h.

◆ emplace_doubles()

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace_doubles ( Args &&...  args)
inline

Construct a vector of doubles within this KnowledgeRecord.

Parameters
argsAll arguments are forwarded to the vector constructor

Definition at line 330 of file KnowledgeRecord.h.

◆ emplace_file()

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace_file ( Args &&...  args)
inline

Construct a file (vector of unsigned char) within this KnowledgeRecord.

Parameters
argsAll arguments are forwarded to the vector constructor

Definition at line 376 of file KnowledgeRecord.h.

◆ emplace_hist()

template<typename... Args>
KnowledgeRecord& madara::knowledge::KnowledgeRecord::emplace_hist ( Args &&...  args)
inlineprivate

Definition at line 1765 of file KnowledgeRecord.h.

◆ emplace_integers()

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace_integers ( Args &&...  args)
inline

Construct a vector of integers within this KnowledgeRecord.

Parameters
argsAll arguments are forwarded to the vector constructor

Definition at line 307 of file KnowledgeRecord.h.

◆ emplace_shared_val()

template<typename T , uint32_t Type, MemberType< T > Member, bool Overwrite = false, typename... Args>
std::shared_ptr<const T> madara::knowledge::KnowledgeRecord::emplace_shared_val ( Args &&...  args)
inlineprivate

Definition at line 1776 of file KnowledgeRecord.h.

◆ emplace_shared_vec()

template<typename T , uint32_t Type, MemberType< std::vector< T >> Member, bool Overwrite = false, typename... Args>
std::shared_ptr<const std::vector<T> > madara::knowledge::KnowledgeRecord::emplace_shared_vec ( Args &&...  args)
inlineprivate

Definition at line 1803 of file KnowledgeRecord.h.

◆ emplace_string()

template<typename... Args>
void madara::knowledge::KnowledgeRecord::emplace_string ( Args &&...  args)
inline

Construct a string within this KnowledgeRecord.

Parameters
argsAll arguments are forwarded to the string constructor

Definition at line 353 of file KnowledgeRecord.h.

◆ emplace_val()

template<typename T , uint32_t Type, MemberType< T > Member, bool Overwrite = false, typename... Args>
std::shared_ptr<const T> madara::knowledge::KnowledgeRecord::emplace_val ( Args &&...  args)
inlineprivate

Definition at line 1795 of file KnowledgeRecord.h.

◆ emplace_vec()

template<typename T , uint32_t Type, MemberType< std::vector< T >> Member, bool Overwrite = false, typename... Args>
std::shared_ptr<const std::vector<T> > madara::knowledge::KnowledgeRecord::emplace_vec ( Args &&...  args)
inlineprivate

Definition at line 1811 of file KnowledgeRecord.h.

◆ exists()

bool madara::knowledge::KnowledgeRecord::exists ( void  ) const
inline

Checks if record exists (i.e., is not uncreated)

Returns
true if record exists, false otherwise

Definition at line 729 of file KnowledgeRecord.inl.

◆ for_history_range()

template<typename Func >
size_t madara::knowledge::KnowledgeRecord::for_history_range ( Func &&  func,
size_t  index,
size_t  count 
) const
inline

Execute a callable for each history element.

Definition at line 1478 of file KnowledgeRecord.h.

◆ fragment()

KnowledgeRecord madara::knowledge::KnowledgeRecord::fragment ( unsigned int  first,
unsigned int  last 
)

returns a record containing a fragment of the character buffer.

For strings, this is equivalent to substring. For files, this is like an unsigned char * equivalent to substring. For other types, this will return host-specific byte values up to the size of the value.

Parameters
firstfirst index (inclusive, >= 0)
lastlast index (inclusive, < size)

Definition at line 586 of file KnowledgeRecord.cpp.

◆ get_encoded_size() [1/2]

int64_t madara::knowledge::KnowledgeRecord::get_encoded_size ( const std::string &  key) const
inline

Returns the encoded size of the record.

This size is what is required to write the key_size, key, type, value size, and all associated information in the read () and write () methods.

Definition at line 840 of file KnowledgeRecord.inl.

◆ get_encoded_size() [2/2]

int64_t madara::knowledge::KnowledgeRecord::get_encoded_size ( void  ) const
inline

Returns the encoded size of the record.

This size is what is required to write the type, value size, and all associated information in the read () and write () methods.

Definition at line 804 of file KnowledgeRecord.inl.

◆ get_history() [1/6]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeRecord::get_history ( ) const
inline

Get a copy of the entire stored history of this record.

Definition at line 1643 of file KnowledgeRecord.h.

◆ get_history() [2/6]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeRecord::get_history ( ) const
inline

Get a copy of the entire stored history of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord.

Definition at line 1677 of file KnowledgeRecord.h.

◆ get_history() [3/6]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeRecord::get_history ( OutputIterator  out) const -> decltype(*out, size_t{})
inline

Copy the stored history of this record to the given output iterator, in order from oldest to newest.

Definition at line 1666 of file KnowledgeRecord.h.

◆ get_history() [4/6]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeRecord::get_history ( OutputIterator  out,
ssize_t  index,
size_t  count 
) const
inline

Copy the given range of history to the output iterator given.

Indexing starts from oldest history entry in the buffer at index 0. Negative indices count from newest entries (-1 is newest).

Definition at line 1656 of file KnowledgeRecord.h.

◆ get_history() [5/6]

KnowledgeRecord madara::knowledge::KnowledgeRecord::get_history ( size_t  index) const
inline

Return the given entry in this record's history.

Indexing starts from oldest history entry in the buffer at index 0. Negative indices count from newest entries (-1 is newest).

Definition at line 1701 of file KnowledgeRecord.h.

◆ get_history() [6/6]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeRecord::get_history ( size_t  index,
size_t  count 
) const
inline

Return a copy of the given range of history in a vector.

Indexing starts from oldest history entry in the buffer at index 0. Negative indices count from newest entries (-1 is newest).

Definition at line 1689 of file KnowledgeRecord.h.

◆ get_history_capacity()

size_t madara::knowledge::KnowledgeRecord::get_history_capacity ( ) const
inline

Return the maximum amount of history this record can hold.

Use set_history_capacity to adjust this.

Definition at line 1395 of file KnowledgeRecord.h.

◆ get_history_newest_index()

size_t madara::knowledge::KnowledgeRecord::get_history_newest_index ( ) const
inline

Gets the absolute index of the newest element in stored history.

If this record doesn't have history capacity, throws IndexException

Definition at line 1712 of file KnowledgeRecord.h.

◆ get_history_oldest_index()

size_t madara::knowledge::KnowledgeRecord::get_history_oldest_index ( ) const
inline

Gets the absolute index of the oldest element in stored history.

If this record doesn't have history capacity, throws IndexException

Definition at line 1727 of file KnowledgeRecord.h.

◆ get_history_range()

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeRecord::get_history_range ( OutputIterator  out,
size_t  index,
size_t  count 
) const

Copy the given absolute range of history to the output iterator given.

Indexing is absolute, starting with the initial value of the record, not relative to the circular buffer contents. You likely want to use get_history instead.

Definition at line 526 of file KnowledgeCast.h.

◆ get_history_size()

size_t madara::knowledge::KnowledgeRecord::get_history_size ( ) const
inline

Return the amount of history this record holds.

Definition at line 1376 of file KnowledgeRecord.h.

◆ get_newest() [1/5]

KnowledgeRecord madara::knowledge::KnowledgeRecord::get_newest ( ) const
inline

Return the newest stored history entry of this record.

Definition at line 1573 of file KnowledgeRecord.h.

◆ get_newest() [2/5]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeRecord::get_newest ( OutputIterator  out) const -> decltype(*out, size_t{})
inline

Copy the newest stored history entry of this record to the given output iterator.

Definition at line 1555 of file KnowledgeRecord.h.

◆ get_newest() [3/5]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeRecord::get_newest ( OutputIterator  out,
size_t  count 
) const
inline

Copy the count newest stored history entries of this record to the given output iterator, in order from oldest to newest.

Definition at line 1545 of file KnowledgeRecord.h.

◆ get_newest() [4/5]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeRecord::get_newest ( size_t  count) const
inline

Return the count newest stored history entries of this record in a vector.

Definition at line 1620 of file KnowledgeRecord.h.

◆ get_newest() [5/5]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeRecord::get_newest ( size_t  count) const
inline

Return the count newest stored history entries of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord.

Definition at line 1633 of file KnowledgeRecord.h.

◆ get_oldest() [1/5]

KnowledgeRecord madara::knowledge::KnowledgeRecord::get_oldest ( ) const
inline

Return the oldest stored history entry of this record.

Definition at line 1563 of file KnowledgeRecord.h.

◆ get_oldest() [2/5]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeRecord::get_oldest ( OutputIterator  out) const -> decltype(*out, size_t{})
inline

Copy the oldest stored history entry of this record to the given output iterator.

Definition at line 1535 of file KnowledgeRecord.h.

◆ get_oldest() [3/5]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeRecord::get_oldest ( OutputIterator  out,
size_t  count 
) const
inline

Copy the count oldest stored history entries of this record to the given output iterator, in order from oldest to newest.

Definition at line 1525 of file KnowledgeRecord.h.

◆ get_oldest() [4/5]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeRecord::get_oldest ( size_t  count) const
inline

Return the count oldest stored history entries of this record in a vector.

Definition at line 1596 of file KnowledgeRecord.h.

◆ get_oldest() [5/5]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeRecord::get_oldest ( size_t  count) const
inline

Return the count oldest stored history entries of this record in a vector of the given element type, which must support knoweldge_cast<> from KnowledgeRecord.

Definition at line 1609 of file KnowledgeRecord.h.

◆ get_precision()

int madara::knowledge::KnowledgeRecord::get_precision ( void  )
static

Gets the current double precision for double to string conversion.

Returns
the double precision for double to string conversion

Definition at line 27 of file KnowledgeRecord.cpp.

◆ has_history()

bool madara::knowledge::KnowledgeRecord::has_history ( ) const
inline

Return true if this record has a circular buffer history.

Use set_history_capacity to add a buffer

Definition at line 1368 of file KnowledgeRecord.h.

◆ inc_index()

KnowledgeRecord madara::knowledge::KnowledgeRecord::inc_index ( size_t  index)

increments the value at the index to the specified value.

If the record was previously not an array or if the array is not large enough, a new array is created.

Parameters
indexindex of the value to set

Definition at line 1222 of file KnowledgeRecord.cpp.

◆ is_array_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_array_type ( uint32_t  type)
inlinestatic

returns if the record is a array type (DOUBLE_ARRAY, INTEGER_ARRAY)

Parameters
typethe type to check
Returns
true if the record is an integer

Definition at line 898 of file KnowledgeRecord.inl.

◆ is_array_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_array_type ( void  ) const
inline

returns if the record is an array type (DOUBLE_ARRAY, INTEGER_ARRAY)

Returns
true if the record is an integer

Definition at line 893 of file KnowledgeRecord.inl.

◆ is_binary_file_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_binary_file_type ( uint32_t  type)
inlinestatic

returns true if the knowledge record has a binary file type

Parameters
typethe type of the record
Returns
true if type is a file type

Definition at line 929 of file KnowledgeRecord.inl.

◆ is_binary_file_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_binary_file_type ( void  ) const
inline

returns true if the knowledge record has a binary file type

Returns
true if type is a file type

Definition at line 924 of file KnowledgeRecord.inl.

◆ is_double_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_double_type ( uint32_t  type)
inlinestatic

returns if the record is a double type (DOUBLE, DOUBLE_ARRAY)

Parameters
typethe type to check
Returns
true if the record is a double

Definition at line 878 of file KnowledgeRecord.inl.

◆ is_double_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_double_type ( void  ) const
inline

returns if the record is a double type (DOUBLE, DOUBLE_ARRAY)

Returns
true if the record is a double

Definition at line 873 of file KnowledgeRecord.inl.

◆ is_false()

bool madara::knowledge::KnowledgeRecord::is_false ( void  ) const
inline

Checks to see if the record is false.

For integers and boules, false means the value is zero. For strings, it means the value is "".

Returns
true if the record is zero or "". False otherwise.

Definition at line 640 of file KnowledgeRecord.inl.

◆ is_file_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_file_type ( uint32_t  type)
inlinestatic

returns true if the knowledge record has a file type

Parameters
typethe type of the record
Returns
true if type is a file type

Definition at line 918 of file KnowledgeRecord.inl.

◆ is_file_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_file_type ( void  ) const
inline

returns true if the knowledge record has a file type

Returns
true if type is a file type

Definition at line 913 of file KnowledgeRecord.inl.

◆ is_image_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_image_type ( uint32_t  type)
inlinestatic

returns true if the knowledge record has an image type

Parameters
typethe type of the record
Returns
true if type is an image type

Definition at line 908 of file KnowledgeRecord.inl.

◆ is_image_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_image_type ( void  ) const
inline

returns true if the knowledge record has an image type

Returns
true if type is an image type

Definition at line 903 of file KnowledgeRecord.inl.

◆ is_integer_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_integer_type ( uint32_t  type)
inlinestatic

returns if the record is a integer type (INTEGER, INTEGER_ARRAY)

Parameters
typethe type to check
Returns
true if the record is an integer

Definition at line 888 of file KnowledgeRecord.inl.

◆ is_integer_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_integer_type ( void  ) const
inline

returns if the record is a integer type (INTEGER, INTEGER_ARRAY)

Returns
true if the record is an integer

Definition at line 883 of file KnowledgeRecord.inl.

◆ is_ref_counted() [1/2]

bool madara::knowledge::KnowledgeRecord::is_ref_counted ( uint32_t  type)
inlinestatic

returns if the record has a reference-counted type

Parameters
typethe type to check
Returns
true if the record is reference-counted

Definition at line 858 of file KnowledgeRecord.inl.

◆ is_ref_counted() [2/2]

bool madara::knowledge::KnowledgeRecord::is_ref_counted ( void  ) const
inline

returns if the record has a reference-counted type

Returns
true if the record is reference-counted

Definition at line 853 of file KnowledgeRecord.inl.

◆ is_string_type() [1/2]

bool madara::knowledge::KnowledgeRecord::is_string_type ( uint32_t  type)
inlinestatic

returns if the record is a string type (STRING, XML, TEXT_FILE)

Parameters
typethe type to check
Returns
true if the record is a string

Definition at line 868 of file KnowledgeRecord.inl.

◆ is_string_type() [2/2]

bool madara::knowledge::KnowledgeRecord::is_string_type ( void  ) const
inline

returns true if the record is a string type (STRING, XML, TEXT_FILE)

Returns
true if the record is a string

Definition at line 863 of file KnowledgeRecord.inl.

◆ is_true()

bool madara::knowledge::KnowledgeRecord::is_true ( void  ) const

Checks to see if the record is true.

For integers and doubles, true means the value is non-zero. For strings, it means the value is non "";

Returns
true if the record is non-zero or not-"". False otherwise.

Definition at line 1381 of file KnowledgeRecord.cpp.

◆ is_valid()

bool madara::knowledge::KnowledgeRecord::is_valid ( void  ) const
inline

Checks to see if the record is valid.

Valid records have a status that is not UNCREATED.

Returns
true if the record is valid. False otherwise.

Definition at line 1345 of file KnowledgeRecord.h.

◆ operator bool()

madara::knowledge::KnowledgeRecord::operator bool ( void  ) const
inlineexplicit

Explicit bool cast.

Returns
the value of is_true()

Definition at line 1632 of file KnowledgeRecord.inl.

◆ operator!()

bool madara::knowledge::KnowledgeRecord::operator! ( void  ) const
inline

Logical not.

Definition at line 381 of file KnowledgeRecord.inl.

◆ operator!=()

Unequal to.

Definition at line 372 of file KnowledgeRecord.inl.

◆ operator%()

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator% ( const KnowledgeRecord rhs) const
inline

Modulus operator.

Definition at line 619 of file KnowledgeRecord.inl.

◆ operator%=()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator%= ( const KnowledgeRecord rhs)
inline

In-place modulus operator.

Definition at line 571 of file KnowledgeRecord.inl.

◆ operator*()

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator* ( const KnowledgeRecord rhs) const
inline

Times operator.

Definition at line 595 of file KnowledgeRecord.inl.

◆ operator*=()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator*= ( const KnowledgeRecord rhs)
inline

In-place multiplication operator.

Definition at line 507 of file KnowledgeRecord.inl.

◆ operator+()

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator+ ( const KnowledgeRecord rhs) const
inline

Plus operator.

Definition at line 631 of file KnowledgeRecord.inl.

◆ operator++()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator++ ( void  )
inline

Preincrement operator.

In-place preincrement.

Definition at line 461 of file KnowledgeRecord.inl.

◆ operator+=()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator+= ( const KnowledgeRecord rhs)
inline

In-place addition operator.

Definition at line 412 of file KnowledgeRecord.inl.

◆ operator-() [1/2]

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator- ( const KnowledgeRecord rhs) const
inline

Minus operator.

Definition at line 665 of file KnowledgeRecord.inl.

◆ operator-() [2/2]

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator- ( void  ) const
inline

Negate.

Definition at line 389 of file KnowledgeRecord.inl.

◆ operator--()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator-- ( void  )
inline

Predecrement operator.

In-place predecrement.

Definition at line 437 of file KnowledgeRecord.inl.

◆ operator-=()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator-= ( const KnowledgeRecord rhs)
inline

In-place subtraction operator.

Definition at line 485 of file KnowledgeRecord.inl.

◆ operator/()

KnowledgeRecord madara::knowledge::KnowledgeRecord::operator/ ( const KnowledgeRecord rhs) const
inline

Divides operator.

Definition at line 607 of file KnowledgeRecord.inl.

◆ operator/=()

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator/= ( const KnowledgeRecord rhs)
inline

In-place division operator.

Definition at line 529 of file KnowledgeRecord.inl.

◆ operator<()

bool madara::knowledge::KnowledgeRecord::operator< ( const KnowledgeRecord rhs) const

Less than.

Definition at line 669 of file KnowledgeRecord.cpp.

◆ operator<=()

bool madara::knowledge::KnowledgeRecord::operator<= ( const KnowledgeRecord rhs) const

Less than or equal to.

Definition at line 764 of file KnowledgeRecord.cpp.

◆ operator=() [1/3]

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator= ( const KnowledgeRecord rhs)
inline

Assignment.

Definition at line 350 of file KnowledgeRecord.inl.

◆ operator=() [2/3]

KnowledgeRecord & madara::knowledge::KnowledgeRecord::operator= ( knowledge::KnowledgeRecord &&  rhs)
inlinenoexcept

Move Assignment.

Definition at line 361 of file KnowledgeRecord.inl.

◆ operator=() [3/3]

template<typename T >
auto madara::knowledge::KnowledgeRecord::operator= ( T &&  t) -> typename std::enable_if<!std::is_convertible<T, KnowledgeRecord>::value, decltype(this->set_value(std::forward<T>(t)), *this)>::type
inline

Assigns a convertible value to the knowledge record.

Definition at line 1147 of file KnowledgeRecord.h.

◆ operator==()

bool madara::knowledge::KnowledgeRecord::operator== ( const KnowledgeRecord rhs) const

Equal to.

Definition at line 859 of file KnowledgeRecord.cpp.

◆ operator>()

bool madara::knowledge::KnowledgeRecord::operator> ( const KnowledgeRecord rhs) const

Greater than.

Definition at line 974 of file KnowledgeRecord.cpp.

◆ operator>=()

bool madara::knowledge::KnowledgeRecord::operator>= ( const KnowledgeRecord rhs) const

Greater than or equal to.

Definition at line 1070 of file KnowledgeRecord.cpp.

◆ overwrite() [1/2]

void madara::knowledge::KnowledgeRecord::overwrite ( const KnowledgeRecord new_value)
inline

Clears everything including history, but excluding metadata (e.g., toi, clock) and copies value from new_value into this recod.

Definition at line 281 of file KnowledgeRecord.inl.

◆ overwrite() [2/2]

void madara::knowledge::KnowledgeRecord::overwrite ( KnowledgeRecord &&  new_value)
inline

Clears everything including history, but excluding metadata (e.g., toi, clock) and moves value from new_value into this recod.

Definition at line 314 of file KnowledgeRecord.inl.

◆ overwrite_circular_buffer()

template<typename... Args>
void madara::knowledge::KnowledgeRecord::overwrite_circular_buffer ( Args &&...  args)
inline

Construct a CircularBuffer within this KnowledgeRecord directly.

This buffer will be treated as the history of this record, and used as such going forward.

Parameters
argsarguments forwarded to the madara::utility::CircularBuffer constructor

Definition at line 402 of file KnowledgeRecord.h.

◆ read() [1/3]

const char * madara::knowledge::KnowledgeRecord::read ( const char *  buffer,
int64_t &  buffer_remaining 
)
inline

Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining.

Parameters
bufferthe readable buffer where data is stored
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next read

Definition at line 991 of file KnowledgeRecord.inl.

◆ read() [2/3]

const char * madara::knowledge::KnowledgeRecord::read ( const char *  buffer,
std::string &  key,
int64_t &  buffer_remaining 
)
inline

Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining.

Parameters
bufferthe readable buffer where data is stored
keythe name of the variable
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next read

Definition at line 1125 of file KnowledgeRecord.inl.

◆ read() [3/3]

const char * madara::knowledge::KnowledgeRecord::read ( const char *  buffer,
uint32_t &  key_id,
int64_t &  buffer_remaining 
)
inline

Reads a KnowledgeRecord instance from a buffer and updates the amount of buffer room remaining.

Parameters
bufferthe readable buffer where data is stored
key_idthe keyed index for the name of a variable
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next read

Definition at line 1164 of file KnowledgeRecord.inl.

◆ read_file()

int madara::knowledge::KnowledgeRecord::read_file ( const std::string &  filename,
uint32_t  read_as_type = 0 
)

reads a file and sets the type appropriately according to the extension

Parameters
filenamelocation of the file to read from
read_as_typeforce a type (XML, TEXT, IMAGE_JPEG, or UNKNOWN_FILE_TYPE)
Returns
size of file

Definition at line 60 of file KnowledgeRecord.cpp.

◆ ref_newest() [1/2]

KnowledgeRecord& madara::knowledge::KnowledgeRecord::ref_newest ( )
inlineprivate

Definition at line 1581 of file KnowledgeRecord.h.

◆ ref_newest() [2/2]

const KnowledgeRecord& madara::knowledge::KnowledgeRecord::ref_newest ( ) const
inlineprivate

Definition at line 1586 of file KnowledgeRecord.h.

◆ reset_value()

void madara::knowledge::KnowledgeRecord::reset_value ( void  )
inlinenoexcept

resets the variable to an integer

Definition at line 1185 of file KnowledgeRecord.inl.

◆ resize()

void madara::knowledge::KnowledgeRecord::resize ( size_t  new_size)

resizes an array to a new size

Parameters
new_sizenew size of the array

Definition at line 1256 of file KnowledgeRecord.cpp.

◆ retrieve_index()

KnowledgeRecord madara::knowledge::KnowledgeRecord::retrieve_index ( size_t  index) const

retrieves the value at an array index.

If the knowledge record is not an array, false is returned.

Parameters
indexindex of the array item
Returns
value at the index

Definition at line 1166 of file KnowledgeRecord.cpp.

◆ set_file() [1/4]

void madara::knowledge::KnowledgeRecord::set_file ( const std::vector< unsigned char > &  new_value)
inline

sets the value to an unknown file type

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1321 of file KnowledgeRecord.inl.

◆ set_file() [2/4]

void madara::knowledge::KnowledgeRecord::set_file ( const unsigned char *  new_value,
size_t  size 
)
inline

sets the value to an unknown file type

Parameters
new_valuenew value of the Knowledge Record
sizesize of the new_value buffer

Definition at line 1308 of file KnowledgeRecord.inl.

◆ set_file() [3/4]

void madara::knowledge::KnowledgeRecord::set_file ( std::unique_ptr< std::vector< unsigned char >>  new_value)
inline

sets the value to an unknown file type, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1328 of file KnowledgeRecord.inl.

◆ set_file() [4/4]

void madara::knowledge::KnowledgeRecord::set_file ( std::vector< unsigned char > &&  new_value)
inline

sets the value to an unknown file type, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1315 of file KnowledgeRecord.inl.

◆ set_fixed()

void madara::knowledge::KnowledgeRecord::set_fixed ( void  )
static

Sets the output format for doubles to std::fixed.

Definition at line 42 of file KnowledgeRecord.cpp.

◆ set_full() [1/2]

void madara::knowledge::KnowledgeRecord::set_full ( const KnowledgeRecord new_value)
inline

Sets the value and meta data from another KnowledgeRecord.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 263 of file KnowledgeRecord.inl.

◆ set_full() [2/2]

void madara::knowledge::KnowledgeRecord::set_full ( KnowledgeRecord &&  new_value)
inline

Sets the value and meta data from another KnowledgeRecord.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 272 of file KnowledgeRecord.inl.

◆ set_history_capacity()

void madara::knowledge::KnowledgeRecord::set_history_capacity ( size_t  size)
inline

Set the capacity of this record's history circular buffer.

Every modification to this record will write a new entry in this history. Once the capacity is met, the oldest entry will be discarded as new entries are added.

Note that this capacity includes current value of the record. A capacity of zero indicates that this record holds no buffer, whereas one indicates that this record has a buffer of size 1.

Definition at line 1417 of file KnowledgeRecord.h.

◆ set_index() [1/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type >
void madara::knowledge::KnowledgeRecord::set_index ( size_t  index,
value 
)
inline

sets the value at the index to the specified value.

If the record was previously not an array or if the array is not large enough, a new array is created.

Parameters
indexindex of the value to set
valuethe value to set at the specified index

If the record was previously not an array or if the array is not large enough, a new array is created.

Definition at line 1485 of file KnowledgeRecord.inl.

◆ set_index() [2/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
void madara::knowledge::KnowledgeRecord::set_index ( size_t  index,
value 
)

sets the value at the index to the specified value.

If the record was previously not an array or if the array is not large enough, a new array is created.

Parameters
indexindex of the value to set
valuethe value to set at the specified index

◆ set_jpeg() [1/4]

void madara::knowledge::KnowledgeRecord::set_jpeg ( const std::vector< unsigned char > &  new_value)
inline

sets the value to a jpeg

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1293 of file KnowledgeRecord.inl.

◆ set_jpeg() [2/4]

void madara::knowledge::KnowledgeRecord::set_jpeg ( const unsigned char *  new_value,
size_t  size 
)
inline

sets the value to a jpeg

Parameters
new_valuenew value of the Knowledge Record
sizesize of the new_value buffer

Definition at line 1280 of file KnowledgeRecord.inl.

◆ set_jpeg() [3/4]

void madara::knowledge::KnowledgeRecord::set_jpeg ( std::unique_ptr< std::vector< unsigned char >>  new_value)
inline

sets the value to a jpeg, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1300 of file KnowledgeRecord.inl.

◆ set_jpeg() [4/4]

void madara::knowledge::KnowledgeRecord::set_jpeg ( std::vector< unsigned char > &&  new_value)
inline

sets the value to a jpeg, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1287 of file KnowledgeRecord.inl.

◆ set_modified()

void madara::knowledge::KnowledgeRecord::set_modified ( void  )
inline

sets the status to modified

Definition at line 742 of file KnowledgeRecord.inl.

◆ set_precision()

void madara::knowledge::KnowledgeRecord::set_precision ( int  new_precision)
static

Sets the double precision of a double record when using to_string ().

All doubles will have this fixed precision. To return to default precision, set new_precision to a negative number.

Parameters
new_precisionnew double precision to use

Definition at line 32 of file KnowledgeRecord.cpp.

◆ set_scientific()

void madara::knowledge::KnowledgeRecord::set_scientific ( void  )
static

Sets the output format for doubles to std::scientific.

Definition at line 51 of file KnowledgeRecord.cpp.

◆ set_text() [1/4]

void madara::knowledge::KnowledgeRecord::set_text ( const char *  new_value,
size_t  size 
)
inline

sets the value to a plaintext string

Parameters
new_valuenew value of the Knowledge Record
sizesize of the new_value buffer

Definition at line 1252 of file KnowledgeRecord.inl.

◆ set_text() [2/4]

void madara::knowledge::KnowledgeRecord::set_text ( const std::string &  new_value)
inline

sets the value to a plaintext string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1266 of file KnowledgeRecord.inl.

◆ set_text() [3/4]

void madara::knowledge::KnowledgeRecord::set_text ( std::string &&  new_value)
inline

sets the value to a plaintext string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1259 of file KnowledgeRecord.inl.

◆ set_text() [4/4]

void madara::knowledge::KnowledgeRecord::set_text ( std::unique_ptr< std::string >  new_value)
inline

sets the value to a plaintext string.

Does not copy the string.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1273 of file KnowledgeRecord.inl.

◆ set_toi()

void madara::knowledge::KnowledgeRecord::set_toi ( uint64_t  new_toi)
inline

Definition at line 156 of file KnowledgeRecord.h.

◆ set_type()

bool madara::knowledge::KnowledgeRecord::set_type ( uint32_t  type)
inline

Modify the type, but only if it's compatible with current type without changing any actual data stored.

I.e., STRING, TEXT_FILE, and XML can be converted between each other, and UKNOWN_BINARY_FILE, IMAGE_JPEG can be converted between each other.

Parameters
typethe new type
Returns
true if conversion successfully applied, or was already type, false if not

Definition at line 784 of file KnowledgeRecord.inl.

◆ set_value() [1/19]

void madara::knowledge::KnowledgeRecord::set_value ( const char *  new_value,
uint32_t  size 
)
inline

sets the value to a string, from a buffer

Parameters
new_valuenew value of the Knowledge Record
sizenum elements in the buffer

Definition at line 1217 of file KnowledgeRecord.inl.

◆ set_value() [2/19]

void madara::knowledge::KnowledgeRecord::set_value ( const double *  new_value,
uint32_t  size 
)
inline

sets the value to an array of doubles

Parameters
new_valuenew value of the Knowledge Record
sizenum elements in the array

Definition at line 1454 of file KnowledgeRecord.inl.

◆ set_value() [3/19]

void madara::knowledge::KnowledgeRecord::set_value ( const Integer new_value,
uint32_t  size 
)
inline

sets the value to an array of integers

Parameters
new_valuenew value of the Knowledge Record
sizenum elements in the array

Definition at line 1428 of file KnowledgeRecord.inl.

◆ set_value() [4/19]

void madara::knowledge::KnowledgeRecord::set_value ( const KnowledgeRecord new_value)
inline

Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 216 of file KnowledgeRecord.inl.

◆ set_value() [5/19]

void madara::knowledge::KnowledgeRecord::set_value ( const std::string &  new_value)
inline

sets the value to a string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1203 of file KnowledgeRecord.inl.

◆ set_value() [6/19]

void madara::knowledge::KnowledgeRecord::set_value ( const std::vector< double > &  new_value)
inline

sets the value to an array of doubles

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1466 of file KnowledgeRecord.inl.

◆ set_value() [7/19]

void madara::knowledge::KnowledgeRecord::set_value ( const std::vector< Integer > &  new_value)
inline

sets the value to an array of integers

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1440 of file KnowledgeRecord.inl.

◆ set_value() [8/19]

void madara::knowledge::KnowledgeRecord::set_value ( double  new_value)
inline

sets the value to a double

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1390 of file KnowledgeRecord.inl.

◆ set_value() [9/19]

void madara::knowledge::KnowledgeRecord::set_value ( float  new_value)
inline

sets the value to a float

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1409 of file KnowledgeRecord.inl.

◆ set_value() [10/19]

void madara::knowledge::KnowledgeRecord::set_value ( int  new_value)
inline

sets the value to an integer

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1353 of file KnowledgeRecord.inl.

◆ set_value() [11/19]

void madara::knowledge::KnowledgeRecord::set_value ( Integer  new_value)
inline

sets the value to an integer

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1335 of file KnowledgeRecord.inl.

◆ set_value() [12/19]

void madara::knowledge::KnowledgeRecord::set_value ( KnowledgeRecord &&  new_value)
inline

Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 236 of file KnowledgeRecord.inl.

◆ set_value() [13/19]

void madara::knowledge::KnowledgeRecord::set_value ( size_t  new_value)
inline

sets the value to an integer

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1371 of file KnowledgeRecord.inl.

◆ set_value() [14/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::string &&  new_value)
inline

sets the value to a string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1196 of file KnowledgeRecord.inl.

◆ set_value() [15/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::unique_ptr< std::string >  new_value)
inline

sets the value to a string.

Does not copy the string.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1210 of file KnowledgeRecord.inl.

◆ set_value() [16/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::unique_ptr< std::vector< double >>  new_value)
inline

sets the value to an array of doubles, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1472 of file KnowledgeRecord.inl.

◆ set_value() [17/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::unique_ptr< std::vector< Integer >>  new_value)
inline

sets the value to an array of integers, without copying

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1446 of file KnowledgeRecord.inl.

◆ set_value() [18/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::vector< double > &&  new_value)
inline

sets the value to an array of doubles

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1460 of file KnowledgeRecord.inl.

◆ set_value() [19/19]

void madara::knowledge::KnowledgeRecord::set_value ( std::vector< Integer > &&  new_value)
inline

sets the value to an array of integers

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1434 of file KnowledgeRecord.inl.

◆ set_xml() [1/4]

void madara::knowledge::KnowledgeRecord::set_xml ( const char *  new_value,
size_t  size 
)
inline

sets the value to an xml string

Parameters
new_valuenew value of the Knowledge Record
sizesize of the new_value buffer

Definition at line 1224 of file KnowledgeRecord.inl.

◆ set_xml() [2/4]

void madara::knowledge::KnowledgeRecord::set_xml ( const std::string &  new_value)
inline

sets the value to an xml string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1238 of file KnowledgeRecord.inl.

◆ set_xml() [3/4]

void madara::knowledge::KnowledgeRecord::set_xml ( std::string &&  new_value)
inline

sets the value to an xml string

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1231 of file KnowledgeRecord.inl.

◆ set_xml() [4/4]

void madara::knowledge::KnowledgeRecord::set_xml ( std::unique_ptr< std::string >  new_value)
inline

sets the value to an xml string.

Does not copy the string.

Parameters
new_valuenew value of the Knowledge Record

Definition at line 1245 of file KnowledgeRecord.inl.

◆ share_binary()

std::shared_ptr< const std::vector< unsigned char > > madara::knowledge::KnowledgeRecord::share_binary ( ) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not a binary file value, returns NULL shared_ptr

Definition at line 1607 of file KnowledgeRecord.inl.

◆ share_circular_buffer()

std::shared_ptr< KnowledgeRecord::CircBuf > madara::knowledge::KnowledgeRecord::share_circular_buffer ( ) const
inline

Get a shared_ptr to the history buffer inside this record.

Returns nullptr if this record has no history capacity.

Definition at line 1622 of file KnowledgeRecord.inl.

◆ share_doubles()

std::shared_ptr< const std::vector< double > > madara::knowledge::KnowledgeRecord::share_doubles ( ) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not a doubles array, returns NULL shared_ptr

Definition at line 1592 of file KnowledgeRecord.inl.

◆ share_integers()

std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > madara::knowledge::KnowledgeRecord::share_integers ( ) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not an int array, returns NULL shared_ptr

Definition at line 1577 of file KnowledgeRecord.inl.

◆ share_string()

std::shared_ptr< const std::string > madara::knowledge::KnowledgeRecord::share_string ( ) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not a string, returns NULL shared_ptr

Definition at line 1562 of file KnowledgeRecord.inl.

◆ size()

uint32_t madara::knowledge::KnowledgeRecord::size ( void  ) const
inline

returns the size of the value

Definition at line 750 of file KnowledgeRecord.inl.

◆ status()

int madara::knowledge::KnowledgeRecord::status ( void  ) const
inline

returns the status of the record.

Returns
1 if modified, 0 if uncreated

Definition at line 734 of file KnowledgeRecord.inl.

◆ to_double()

double madara::knowledge::KnowledgeRecord::to_double ( void  ) const

converts the value to a float/double.

This operation tries to convert as best as it can using reasonable conversions. For doubles and integers, it uses the scalar conversion to double. For int/double arrays, it will use the same scalar conversion of the first element. For strings, it will try to convert with a stringstream.

Definition at line 155 of file KnowledgeRecord.cpp.

◆ to_doubles()

std::vector< double > madara::knowledge::KnowledgeRecord::to_doubles ( void  ) const

converts the value to a vector of doubles

Returns
a vector of doubles

Definition at line 276 of file KnowledgeRecord.cpp.

◆ to_file()

ssize_t madara::knowledge::KnowledgeRecord::to_file ( const std::string &  filename) const

writes the value to a file

Parameters
filenamefile location to write to

Definition at line 126 of file KnowledgeRecord.cpp.

◆ to_integer()

KnowledgeRecord::Integer madara::knowledge::KnowledgeRecord::to_integer ( void  ) const

converts the value to an integer.

This operation tries to convert as best as it can using reasonable conversions. For doubles and integers, it uses the scalar conversion to integer (e.g., floor for double). For int/double arrays, it will use the same scalar conversion of the first element. For strings, it will try to convert with a stringstream.

Definition at line 188 of file KnowledgeRecord.cpp.

◆ to_integers()

std::vector< KnowledgeRecord::Integer > madara::knowledge::KnowledgeRecord::to_integers ( void  ) const

converts the value to a vector of integers

Returns
a vector of integers

Definition at line 221 of file KnowledgeRecord.cpp.

◆ to_managed_buffer()

size_t madara::knowledge::KnowledgeRecord::to_managed_buffer ( char *  buffer,
size_t  buf_size 
) const

converts the value to a c string.

Similar to unmanaged buffer except the user is expected to have malloc'd, new'd, etc. the buffer beforehand. Of note, this method is intended to provide an exact copy of a record's contents and not the string equivalent. In other words, this will not be a null-delimited string. This will be a raw string with no null ending unless a 0 was an actual element of the character buffer.

Parameters
bufferthe user-managed character buffer to fill
buf_sizethe character buffer max size
Returns
the number of characters placed in buffer

Definition at line 338 of file KnowledgeRecord.cpp.

◆ to_managed_string()

size_t madara::knowledge::KnowledgeRecord::to_managed_string ( char *  buffer,
size_t  buf_size 
) const

converts the value to a c string.

This is the equivalent to calling to_string and then copying it to the buffer. It just doesn't cause exceptions with STL errors (e.g., in Unreal Engine plugins)

Parameters
bufferthe user-managed character buffer to fill
buf_sizethe character buffer max size
Returns
the number of characters placed in buffer

Definition at line 329 of file KnowledgeRecord.cpp.

◆ to_string()

std::string madara::knowledge::KnowledgeRecord::to_string ( const std::string &  delimiter = ", ") const

converts the value to a string.

Parameters
delimitercharacters to insert in between elements of an array
Returns
the value as a string

Definition at line 401 of file KnowledgeRecord.cpp.

◆ to_unmanaged_buffer()

unsigned char * madara::knowledge::KnowledgeRecord::to_unmanaged_buffer ( size_t &  size) const

returns an unmanaged buffer that the user will have to take care of (this is a copy of the internal value).

If you use this function, you must explicitly delete the value returned. For instance:

char * my_value = record.to_unmanaged_buffer (); ... do some work on the buffer delete [] my_value;

Failure to do the above WILL result in a memory leak

Parameters
sizesize of the unmanaged buffer
Returns
the unmanaged buffer of size bytes

Definition at line 533 of file KnowledgeRecord.cpp.

◆ toi()

uint64_t madara::knowledge::KnowledgeRecord::toi ( ) const
inline

Definition at line 152 of file KnowledgeRecord.h.

◆ type()

uint32_t madara::knowledge::KnowledgeRecord::type ( void  ) const
inline

returns the type of the value

Definition at line 779 of file KnowledgeRecord.inl.

◆ unshare()

void madara::knowledge::KnowledgeRecord::unshare ( void  )
inline

If this record holds a shared_ptr, make a copy of the underlying value so it has an exclusive copy.

Definition at line 674 of file KnowledgeRecord.inl.

◆ write() [1/3]

char * madara::knowledge::KnowledgeRecord::write ( char *  buffer,
const std::string &  key,
int64_t &  buffer_remaining 
) const
inline

Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining.

Output Format:

[key_size | key | type | value_size | value]
key_size = 32 bit unsigned integer, length of the key
key = key_size characters, the ASCII key
type = 32 bit unsigned integer, the type of value
size = 32 bit unsigned integer, number of elements of the type
value = the stored value

Parameters
bufferthe readable buffer where data is stored
keythe name of the variable
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next write

Definition at line 1802 of file KnowledgeRecord.inl.

◆ write() [2/3]

char * madara::knowledge::KnowledgeRecord::write ( char *  buffer,
int64_t &  buffer_remaining 
) const
inline

Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining.

Output Format:

[type | value_size | value]
type = 32 bit unsigned integer, the type of value
size = 32 bit unsigned integer, number of elements of the type
value = the stored value

Parameters
bufferthe readable buffer where data is stored
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next write

note that we once converted doubles into strings to attempt portability, but we are now just assuming that the floating point units in the architecture are the same endianness as the integers. This is true of ARM, Intel/AMD, and most architectures. We are essentially no longer supporting an architecture that mixes and matches. Persons using such architectures should perform their own conversions on the knowledge records before using them.

Definition at line 1637 of file KnowledgeRecord.inl.

◆ write() [3/3]

char * madara::knowledge::KnowledgeRecord::write ( char *  buffer,
uint32_t  key_id,
int64_t &  buffer_remaining 
) const
inline

Writes a KnowledgeRecord instance to a buffer and updates the amount of buffer room remaining.

This is a write method intended for keyed indexes for variables, generally for perfect hashes

Output Format:

[key_size | key | type | value_size | value]
key_size = 32 bit unsigned integer, length of the key
key = key_size characters, the ASCII key
type = 32 bit unsigned integer, the type of value
size = 32 bit unsigned integer, number of elements of the type
value = the stored value

Parameters
bufferthe readable buffer where data is stored
key_idthe id of the variable
buffer_remainingthe count of bytes remaining in the buffer to read
Returns
current buffer position for next write

Definition at line 1856 of file KnowledgeRecord.inl.

Friends And Related Function Documentation

◆ ThreadSafeContext

friend class ThreadSafeContext
friend

Definition at line 91 of file KnowledgeRecord.h.

Member Data Documentation

◆ 

union { ... }

Non-array versions of double/integer.

About 10x faster than using the ref-counted arrays

◆ buf_

std::shared_ptr<CircBuf> madara::knowledge::KnowledgeRecord::buf_

Definition at line 189 of file KnowledgeRecord.h.

◆ clock

uint64_t madara::knowledge::KnowledgeRecord::clock = 0

last modification lamport clock time

Definition at line 143 of file KnowledgeRecord.h.

◆ double_array_

std::shared_ptr<std::vector<double> > madara::knowledge::KnowledgeRecord::double_array_

Definition at line 185 of file KnowledgeRecord.h.

◆ double_value_

double madara::knowledge::KnowledgeRecord::double_value_

Definition at line 182 of file KnowledgeRecord.h.

◆ file_value_

std::shared_ptr<std::vector<unsigned char> > madara::knowledge::KnowledgeRecord::file_value_

Definition at line 187 of file KnowledgeRecord.h.

◆ int_array_

std::shared_ptr<std::vector<Integer> > madara::knowledge::KnowledgeRecord::int_array_

Definition at line 184 of file KnowledgeRecord.h.

◆ int_value_

Integer madara::knowledge::KnowledgeRecord::int_value_ = 0

Definition at line 181 of file KnowledgeRecord.h.

◆ logger_

logger::Logger* madara::knowledge::KnowledgeRecord::logger_ = logger::global_logger.get()
private

the logger used for any internal debugging information

Definition at line 137 of file KnowledgeRecord.h.

◆ quality

uint32_t madara::knowledge::KnowledgeRecord::quality = 0

priority of the update

Definition at line 168 of file KnowledgeRecord.h.

◆ shared_

bool madara::knowledge::KnowledgeRecord::shared_ = OWNED
mutableprivate

is this knowledge record's shared_ptr, if any, exposed to outside holders?

Definition at line 201 of file KnowledgeRecord.h.

◆ str_value_

std::shared_ptr<std::string> madara::knowledge::KnowledgeRecord::str_value_

Definition at line 186 of file KnowledgeRecord.h.

◆ toi_

uint64_t madara::knowledge::KnowledgeRecord::toi_ = 0
private

last modification system clock time

Definition at line 149 of file KnowledgeRecord.h.

◆ type_

uint32_t madara::knowledge::KnowledgeRecord::type_ = EMPTY
private

type of variable (INTEGER, DOUBLE, STRING, FILE, IMAGE)

Definition at line 195 of file KnowledgeRecord.h.

◆ write_quality

uint32_t madara::knowledge::KnowledgeRecord::write_quality = 0

write priority for any local updates

Definition at line 173 of file KnowledgeRecord.h.


The documentation for this class was generated from the following files: