MADARA  3.4.1
madara::knowledge::KnowledgeBase Class Reference

This class provides a distributed knowledge base to users. More...

#include <KnowledgeBase.h>

Public Member Functions

 KnowledgeBase ()
 Constructor. More...
 
 KnowledgeBase (const KnowledgeBase &original)=default
 Copy constructor. More...
 
 KnowledgeBase (const std::string &host, const madara::transport::TransportSettings &config)
 Constructor. More...
 
 KnowledgeBase (const std::string &host, int transport)
 Constructor. More...
 
 KnowledgeBase (const std::string &host, int transport, const std::string &domain)
 Constructor. More...
 
 ~KnowledgeBase ()=default
 Destructor. More...
 
void acquire (void)
 Acquires the recursive lock on the knowledge base. More...
 
void activate_transport (void)
 Starts the transport mechanism for dissemination if it is closed. More...
 
void add_modifieds (const VariableReferences &modifieds) const
 Adds a list of VariableReferences to the current modified list. More...
 
int apply_modified (const EvalSettings &settings=EvalSettings())
 Applies current time and modified to all global variables and tries to send them. More...
 
void attach_logger (logger::Logger &logger) const
 Attaches a logger to be used for printing. More...
 
std::unique_ptr< BaseStreamerattach_streamer (std::unique_ptr< BaseStreamer > streamer)
 Attach a streaming provider object, inherited from BaseStreamer, such as CheckpointStreamer. More...
 
size_t attach_transport (const std::string &id, transport::TransportSettings &settings)
 Adds a built-in transport with the specified settings. More...
 
size_t attach_transport (madara::transport::Base *transport)
 Attaches a transport to the Knowledge Engine. More...
 
template<typename Callable >
auto cinvoke (const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
template<typename Callable >
auto cinvoke (const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
void clear (bool erase=false)
 Clears the knowledge base. More...
 
bool clear (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Clears a variable. More...
 
void clear_history (const std::string &key, const EvalSettings &settings=EvalSettings())
 Clear all history for this record, keeping the current value. More...
 
void clear_history (const VariableReference &key, const EvalSettings &settings=EvalSettings())
 Clear all history for this record, keeping the current value. More...
 
void clear_map (void)
 Clears the knowledge base. More...
 
void clear_modifieds (void)
 Clear all modifications to the knowledge base. More...
 
void close_transport (void)
 Closes the transport mechanism so no dissemination is possible. More...
 
CompiledExpression compile (const std::string &expression)
 Compiles a KaRL expression into an expression tree. More...
 
void copy (const KnowledgeBase &source, const CopySet &copy_set=CopySet(), bool clean_copy=false, const EvalSettings &settings=EvalSettings())
 Copies variables and values from source to this context. More...
 
void copy (const KnowledgeBase &source, const KnowledgeRequirements &reqs, const EvalSettings &settings=EvalSettings())
 Copies variables and values from source to this context. More...
 
std::string debug_modifieds (void) const
 Retrieves a stringified list of all modified variables that are ready to send over transport on next send_modifieds call. More...
 
void define_function (const std::string &name, boost::python::object callable)
 Defines a named python function. More...
 
void define_function (const std::string &name, const CompiledExpression &expression)
 Defines a MADARA KaRL function. More...
 
void define_function (const std::string &name, const std::string &expression)
 Defines a MADARA KaRL function. More...
 
void define_function (const std::string &name, jobject callable)
 Defines a named java function. More...
 
void define_function (const std::string &name, knowledge::KnowledgeRecord(*func)(const char *, FunctionArguments &, Variables &))
 Defines a named function that can distinguish the name it was called with in MADARA. More...
 
void define_function (const std::string &name, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &))
 Defines a function. More...
 
madara::knowledge::KnowledgeRecord evaluate (CompiledExpression &expression, const EvalSettings &settings=EvalSettings())
 Evaluates an expression. More...
 
madara::knowledge::KnowledgeRecord evaluate (const std::string &expression, const EvalSettings &settings=EvalSettings())
 Evaluates an expression. More...
 
madara::knowledge::KnowledgeRecord evaluate (expression::ComponentNode *root, const EvalSettings &settings=EvalSettings())
 Evaluates a root-based tree (result of compile) More...
 
KnowledgeRecord evaluate_file (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false))
 Loads and evaluates a karl script from a file. More...
 
bool exists (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) const
 Checks if a knowledge location exists in the context. More...
 
bool exists (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) const
 Checks if a knowledge variable exists in the context. More...
 
std::string expand_statement (const std::string &statement)
 Expands a statement using variable expansion. More...
 
void facade_for (ThreadSafeContext &target)
 Change the knowledge base to become a facade for another context. More...
 
std::string file_to_string (CheckpointSettings &checkpoint_settings)
 Loads and returns a karl script from a file with encode/decode. More...
 
template<typename Func >
void for_each (Func &&func) const
 Call given Callable on each element in this KB. More...
 
madara::knowledge::KnowledgeRecord get (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Atomically gets the current value of a variable (without any history). More...
 
madara::knowledge::KnowledgeRecord get (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Atomically gets the current value of a variable (without any history). More...
 
ThreadSafeContextget_context (void)
 Returns the ThreadSafeContext associated with this Knowledge Base. More...
 
const ThreadSafeContextget_context (void) const
 Returns the ThreadSafeContext associated with this Knowledge Base. More...
 
std::vector< KnowledgeRecordget_history (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Get a copy of the entire stored history of this record. More...
 
template<typename T >
std::vector< T > get_history (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const std::string &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const std::string &key, OutputIterator out, ssize_t index, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Copy the given range of history to the output iterator given. More...
 
KnowledgeRecord get_history (const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the given entry in this record's history. More...
 
std::vector< KnowledgeRecordget_history (const std::string &key, size_t index, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return a copy of the given range of history in a vector. More...
 
std::vector< KnowledgeRecordget_history (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Get a copy of the entire stored history of this record. More...
 
template<typename T >
std::vector< T > get_history (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const VariableReference &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const VariableReference &key, OutputIterator out, ssize_t index, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Copy the given range of history to the output iterator given. More...
 
KnowledgeRecord get_history (const VariableReference &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the given entry in this record's history. More...
 
std::vector< KnowledgeRecordget_history (const VariableReference &key, size_t index, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return a copy of the given range of history in a vector. More...
 
size_t get_history_capacity (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the maximum amount of history this record can hold. More...
 
size_t get_history_capacity (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the maximum amount of history this record can hold. More...
 
size_t get_history_size (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the amount of history this record holds. More...
 
size_t get_history_size (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the amount of history this record holds. More...
 
std::string get_id (void)
 Returns the unique host and ephemeral binding for this Knowlede Base. More...
 
int get_log_level (void)
 Gets the log level. More...
 
logger::Loggerget_logger (void) const
 Gets the logger used for information printing. More...
 
void get_matches (const std::string &prefix, const std::string &suffix, VariableReferences &matches)
 Creates an iteration of VariableReferences to all keys matching the prefix and suffix. More...
 
KnowledgeRecord get_newest (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the newest stored history entry of this record. More...
 
template<typename T >
get_newest (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the newest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord) More...
 
template<typename OutputIterator >
auto get_newest (const std::string &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(*out, size_t{})
 Copy the newest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator , typename ConstOutputIterator >
auto get_newest (const std::string &key, OutputIterator out, ConstOutputIterator out_end, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> utility::enable_if_<!std::is_arithmetic< ConstOutputIterator >::value, size_t >
 Copy the newest stored history entries of this record to the given output iterator, up to the given ending iterator, in order from oldest to newest. More...
 
template<typename OutputIterator >
size_t get_newest (const std::string &key, OutputIterator out, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const std::string &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the count newest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_newest (const std::string &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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_newest (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the newest stored history entry of this record. More...
 
template<typename T >
get_newest (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the newest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord) More...
 
template<typename OutputIterator >
auto get_newest (const VariableReference &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(*out, size_t{})
 Copy the newest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator , typename ConstOutputIterator >
auto get_newest (const VariableReference &key, OutputIterator out, ConstOutputIterator out_end, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> utility::enable_if_<!std::is_arithmetic< ConstOutputIterator >::value, size_t >
 Copy the newest stored history entries of this record to the given output iterator, up to the given ending iterator, in order from oldest to newest. More...
 
template<typename OutputIterator >
size_t get_newest (const VariableReference &key, OutputIterator out, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const VariableReference &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the count newest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_newest (const VariableReference &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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...
 
size_t get_num_transports (void)
 Gets the number of transports. More...
 
KnowledgeRecord get_oldest (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the oldest stored history entry of this record. More...
 
template<typename T >
get_oldest (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the oldest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord) More...
 
template<typename OutputIterator >
auto get_oldest (const std::string &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(*out, size_t{})
 Copy the oldest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator , typename ConstOutputIterator >
auto get_oldest (const std::string &key, OutputIterator out, ConstOutputIterator out_end, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> utility::enable_if_<!std::is_arithmetic< ConstOutputIterator >::value, size_t >
 Copy the oldest stored history entries of this record to the given output iterator, up to the given ending iterator, in order from oldest to newest. More...
 
template<typename OutputIterator >
size_t get_oldest (const std::string &key, OutputIterator out, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const std::string &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the count oldest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_oldest (const std::string &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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...
 
KnowledgeRecord get_oldest (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the oldest stored history entry of this record. More...
 
template<typename T >
get_oldest (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the oldest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord) More...
 
template<typename OutputIterator >
auto get_oldest (const VariableReference &key, OutputIterator out, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(*out, size_t{})
 Copy the oldest stored history entry of this record to the given output iterator. More...
 
template<typename OutputIterator , typename ConstOutputIterator >
auto get_oldest (const VariableReference &key, OutputIterator out, ConstOutputIterator out_end, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> utility::enable_if_<!std::is_arithmetic< ConstOutputIterator >::value, size_t >
 Copy the oldest stored history entries of this record to the given output iterator, up to the given ending iterator, in order from oldest to newest. More...
 
template<typename OutputIterator >
size_t get_oldest (const VariableReference &key, OutputIterator out, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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 (const VariableReference &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return the count oldest stored history entries of this record in a vector. More...
 
template<typename T >
std::vector< T > get_oldest (const VariableReference &key, size_t count, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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...
 
VariableReference get_ref (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Atomically returns a reference to the variable. More...
 
bool has_history (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return true if this record has a circular buffer history. More...
 
bool has_history (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Return true if this record has a circular buffer history. More...
 
template<typename Callable >
auto invoke (const std::string &key, Callable &&callable, const EvalSettings &settings=EvalSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
template<typename Callable >
auto invoke (const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
template<typename Callable >
auto invoke (const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
template<typename Callable >
auto invoke (VariableReference key, Callable &&callable, const EvalSettings &settings=EvalSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
 
int64_t load_context (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_settings=KnowledgeUpdateSettings(true, true, true, false))
 Loads the context from a file. More...
 
int64_t load_context (const std::string &filename, bool use_id=true, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
 Loads the context from a file. More...
 
int64_t load_context (const std::string &filename, FileHeader &meta, bool use_id=true, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
 Loads the context from a file. More...
 
void lock (void)
 Locks the context to prevent updates over the network. More...
 
void mark_modified (const std::string &name, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Marks the variable as updated. More...
 
void mark_modified (const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Marks the variable reference as updated. More...
 
int modify (const EvalSettings &settings=EvalSettings())
 Alias for apply_modified. More...
 
KnowledgeBaseoperator= (const KnowledgeBase &original)=default
 Assigns another instance's knowledge and settings to this instance. More...
 
void print (const std::string &statement, unsigned int level=0) const
 Expands and prints a user provided statement at a logging level. More...
 
void print (unsigned int level=0) const
 Prints all knowledge variables and values in the context. More...
 
void print_knowledge (unsigned int level=0) const
 Deprecated alias for. More...
 
int read_file (const std::string &knowledge_key, const std::string &filename, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Read a file into the knowledge base. More...
 
int read_file (const VariableReference &variable, const std::string &filename, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically reads a file into a variable. More...
 
void release (void)
 Releases a recursive lock on the knowledge base. More...
 
size_t remove_transport (size_t index)
 Removes a transport. More...
 
void reset_checkpoint (void) const
 Resets the local changed map, which tracks checkpointing modifieds. More...
 
madara::knowledge::KnowledgeRecord retrieve_index (const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Retrieves a value at a specified index within a knowledge array. More...
 
madara::knowledge::KnowledgeRecord retrieve_index (const VariableReference &variable, size_t index, const KnowledgeReferenceSettings &settings=EvalSettings(true, false, true, false, false))
 Retrieves a value at a specified index within a knowledge array. More...
 
int64_t save_as_json (const CheckpointSettings &settings) const
 Saves the context to a file as JSON. More...
 
int64_t save_as_json (const std::string &filename) const
 Saves the context to a file as JSON. More...
 
int64_t save_as_karl (const CheckpointSettings &settings) const
 Saves the context to a file as karl assignments, rather than binary. More...
 
int64_t save_as_karl (const std::string &filename) const
 Saves the context to a file as karl assignments, rather than binary. More...
 
int64_t save_checkpoint (CheckpointSettings &settings) const
 Saves a checkpoint of a list of changes to a file. More...
 
int64_t save_checkpoint (const std::string &filename, bool reset_modifieds=true)
 Saves a checkpoint of a list of changes to a file. More...
 
int64_t save_context (CheckpointSettings &settings) const
 Saves the context to a file. More...
 
int64_t save_context (const std::string &filename) const
 Saves the context to a file. More...
 
VariableReferences save_modifieds (void) const
 Saves the list of modified records to use later for resending. More...
 
int send_modifieds (const std::string &prefix="KnowledgeBase::send_modifieds", const EvalSettings &settings=EvalSettings::SEND)
 Sends all modified variables through the attached transports. More...
 
int set (const std::string &key, const double *value, uint32_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer 1. More...
 
int set (const std::string &key, const KnowledgeRecord &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a KnowledgeRecord. More...
 
int set (const std::string &key, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, const std::string &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, const std::vector< double > &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, const std::vector< KnowledgeRecord::Integer > &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, KnowledgeRecord &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a KnowledgeRecord. More...
 
int set (const std::string &key, std::string &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, std::vector< double > &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const std::string &key, std::vector< KnowledgeRecord::Integer > &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
template<typename T , typename std::enable_if< std::is_integral< T >::value, void * >::type = nullptr>
int set (const std::string &key, T value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
int set (const std::string &key, T value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets a knowledge variable to a specified value. More...
 
int set (const VariableReference &variable, const double *value, uint32_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a double array. More...
 
int set (const VariableReference &variable, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer 1. More...
 
int set (const VariableReference &variable, const KnowledgeRecord &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a KnowledgeRecord. More...
 
int set (const VariableReference &variable, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer array. More...
 
int set (const VariableReference &variable, const std::string &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a string. More...
 
int set (const VariableReference &variable, const std::vector< double > &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a double array. More...
 
int set (const VariableReference &variable, const std::vector< KnowledgeRecord::Integer > &value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer array. More...
 
int set (const VariableReference &variable, KnowledgeRecord &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a KnowledgeRecord. More...
 
int set (const VariableReference &variable, std::string &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a string. More...
 
int set (const VariableReference &variable, std::vector< double > &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a double array. More...
 
int set (const VariableReference &variable, std::vector< KnowledgeRecord::Integer > &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer array. More...
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
int set (const VariableReference &variable, T value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a double. More...
 
template<typename T , typename std::enable_if< std::is_integral< T >::value, void * >::type = nullptr>
int set (const VariableReference &variable, T value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an integer. More...
 
int set_file (const std::string &key, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an arbitrary string. More...
 
int set_file (const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an arbitrary string. More...
 
void set_history_capacity (const std::string &key, size_t size, const EvalSettings &settings=EvalSettings())
 Set the capacity of this record's history circular buffer. More...
 
void set_history_capacity (const VariableReference &key, size_t size, const EvalSettings &settings=EvalSettings())
 Set the capacity of this record's history circular buffer. More...
 
template<typename T >
int set_index (const std::string &key, size_t index, T &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Sets an index within an array to a specified value. More...
 
template<typename T >
int set_index (const VariableReference &variable, size_t index, T &&value, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of an array index to a value. More...
 
int set_jpeg (const std::string &key, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a JPEG image. More...
 
int set_jpeg (const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a JPEG image. More...
 
void set_log_level (int level)
 Sets the log level. More...
 
void set_quality (const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Sets the quality of writing to a certain variable from this entity. More...
 
int set_text (const VariableReference &variable, const char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to a text file's contents. More...
 
int set_xml (const VariableReference &variable, const char *value, size_t size, const EvalSettings &settings=EvalSettings(true, false, true, false, false))
 Atomically sets the value of a variable to an XML string. More...
 
std::string setup_unique_hostport (const std::string &host="")
 Binds to an ephemeral port for unique tie breakers in global ordering. More...
 
std::shared_ptr< const std::vector< unsigned char > > share_binary (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::vector< unsigned char > > share_binary (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::vector< double > > share_doubles (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::vector< double > > share_doubles (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > share_integers (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > share_integers (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::string > share_string (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
std::shared_ptr< const std::string > share_string (const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 
knowledge::KnowledgeMap to_map (const std::string &prefix) const
 Creates a variable map with Knowledge Records that begin with the given prefix. More...
 
size_t to_map (const std::string &prefix, const std::string &delimiter, const std::string &suffix, std::vector< std::string > &next_keys, std::map< std::string, knowledge::KnowledgeRecord > &result, bool just_keys=false)
 Fills a variable map with list of keys according to a matching prefix, suffix, and delimiter hierarchy. More...
 
size_t to_map (const std::string &subject, std::map< std::string, knowledge::KnowledgeRecord > &target)
 Fills a variable map with Knowledge Records that match an expression. More...
 
knowledge::KnowledgeMap to_map_stripped (const std::string &prefix) const
 Creates a map with Knowledge Records that begin with the given prefix. More...
 
void to_string (std::string &target, const std::string &array_delimiter=",", const std::string &record_delimiter=";\n", const std::string &key_val_delimiter="=") const
 Saves all keys and values into a string, using the underlying knowledge::KnowledgeRecord::to_string function. More...
 
size_t to_vector (const std::string &subject, unsigned int start, unsigned int end, std::vector< KnowledgeRecord > &target)
 Fills a vector with Knowledge Records that begin with a common subject and have a finite range of integer values. More...
 
madara::transport::TransportSettingstransport_settings (void)
 
void unlock (void)
 Unlocks the context to allow updates over the network (is only necessary if the context has been explicitly locked) More...
 
void use (ThreadSafeContext &original)
 Refer to and use another knowledge base's context. More...
 
madara::knowledge::KnowledgeRecord wait (CompiledExpression &expression, const WaitSettings &settings=WaitSettings())
 Waits for an expression to be non-zero. More...
 
madara::knowledge::KnowledgeRecord wait (const std::string &expression, const WaitSettings &settings=WaitSettings())
 Waits for an expression to be non-zero. More...
 
void wait_for_change (void)
 Wait for a change to happen to the context (e.g., from transports) More...
 
ssize_t write_file (const std::string &knowledge_key, const std::string &filename)
 Write a file from the knowledge base to a specified location. More...
 

Private Member Functions

void throw_null_context () const
 

Private Attributes

ThreadSafeContextcontext_
 A knowledge base can also be a facade for another knowledge base. More...
 
std::shared_ptr< KnowledgeBaseImplimpl_
 Pointer to actual implementation, i.e., the "bridge", which is reference counted to automate memory management. More...
 

Detailed Description

This class provides a distributed knowledge base to users.

Definition at line 44 of file KnowledgeBase.h.

Constructor & Destructor Documentation

◆ KnowledgeBase() [1/5]

madara::knowledge::KnowledgeBase::KnowledgeBase ( )
inline

Constructor.

Definition at line 17 of file KnowledgeBase.inl.

◆ KnowledgeBase() [2/5]

madara::knowledge::KnowledgeBase::KnowledgeBase ( const std::string &  host,
int  transport 
)
inline

Constructor.

Parameters
hosthostname/ip of this machine
transporttransport to use for knowledge dissemination

Definition at line 22 of file KnowledgeBase.inl.

◆ KnowledgeBase() [3/5]

madara::knowledge::KnowledgeBase::KnowledgeBase ( const std::string &  host,
int  transport,
const std::string &  domain 
)
inline

Constructor.

Parameters
hosthostname/ip of this machine
transporttransport to use for knowledge dissemination
domainknowledge domain we want to join

Definition at line 27 of file KnowledgeBase.inl.

◆ KnowledgeBase() [4/5]

madara::knowledge::KnowledgeBase::KnowledgeBase ( const std::string &  host,
const madara::transport::TransportSettings config 
)
inline

Constructor.

Parameters
hosthostname/ip of this machine
configtransport settings to use for dissemination

Definition at line 33 of file KnowledgeBase.inl.

◆ KnowledgeBase() [5/5]

madara::knowledge::KnowledgeBase::KnowledgeBase ( const KnowledgeBase original)
default

Copy constructor.

Parameters
originalknowledge base to copy

◆ ~KnowledgeBase()

madara::knowledge::KnowledgeBase::~KnowledgeBase ( )
default

Destructor.

Member Function Documentation

◆ acquire()

void madara::knowledge::KnowledgeBase::acquire ( void  )
inline

Acquires the recursive lock on the knowledge base.

This will block any other thread from updating or using the knowledge base until you call @ release.

Definition at line 1038 of file KnowledgeBase.inl.

◆ activate_transport()

void madara::knowledge::KnowledgeBase::activate_transport ( void  )
inline

Starts the transport mechanism for dissemination if it is closed.

Definition at line 1248 of file KnowledgeBase.inl.

◆ add_modifieds()

void madara::knowledge::KnowledgeBase::add_modifieds ( const VariableReferences modifieds) const
inline

Adds a list of VariableReferences to the current modified list.

Parameters
modifiedsa list of variables to add to modified list

Definition at line 1350 of file KnowledgeBase.inl.

◆ apply_modified()

int madara::knowledge::KnowledgeBase::apply_modified ( const EvalSettings settings = EvalSettings())
inline

Applies current time and modified to all global variables and tries to send them.

Parameters
settingsSettings for evaluating and printing
Returns
0 if there was not a problem.

Definition at line 231 of file KnowledgeBase.inl.

◆ attach_logger()

void madara::knowledge::KnowledgeBase::attach_logger ( logger::Logger logger) const
inline

Attaches a logger to be used for printing.

Parameters
loggerthe logger the context should lose

Definition at line 173 of file KnowledgeBase.inl.

◆ attach_streamer()

std::unique_ptr<BaseStreamer> madara::knowledge::KnowledgeBase::attach_streamer ( std::unique_ptr< BaseStreamer streamer)
inline

Attach a streaming provider object, inherited from BaseStreamer, such as CheckpointStreamer.

Once attached, all updates to records in this ThreadSafeContext will be provided to the streamer. May pass nullptr to stop streaming.

Parameters
streamerthe new streamer to attach
Returns
the old streamer, or nullptr if there wasn't any.

Definition at line 1385 of file KnowledgeBase.h.

◆ attach_transport() [1/2]

size_t madara::knowledge::KnowledgeBase::attach_transport ( const std::string &  id,
transport::TransportSettings settings 
)
inline

Adds a built-in transport with the specified settings.

Parameters
idunique identifier for this agent (empty string will use default generated id)
settingssettings for the new transport
Returns
the number of transports now attached

Definition at line 1281 of file KnowledgeBase.inl.

◆ attach_transport() [2/2]

size_t madara::knowledge::KnowledgeBase::attach_transport ( madara::transport::Base transport)
inline

Attaches a transport to the Knowledge Engine.

Note that the transport should use the same ThreadSafeContext as the Knowledge Engine.

Parameters
transporta new transport to attach to the Knowledge Base
Returns
the number of transports now attached

Definition at line 1256 of file KnowledgeBase.inl.

◆ cinvoke() [1/2]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::cinvoke ( const std::string &  key,
Callable &&  callable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1590 of file KnowledgeBase.h.

◆ cinvoke() [2/2]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::cinvoke ( const VariableReference key,
Callable &&  callable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1607 of file KnowledgeBase.h.

◆ clear() [1/2]

void madara::knowledge::KnowledgeBase::clear ( bool  erase = false)
inline

Clears the knowledge base.

Parameters
eraseIf true, completely erase keys. If false, reset knowledge

Definition at line 1014 of file KnowledgeBase.inl.

◆ clear() [2/2]

bool madara::knowledge::KnowledgeBase::clear ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
)
inline

Clears a variable.

This is safer than erasing the variable. It clears the memory used in the variable and marks it as UNCREATED, meaning that it is effectively deleted, will not show up in

See also
print statements or
save_checkpoint.
Parameters
keyunique identifier of the variable
settingssettings for referring to variables
Returns
true if variable exists

Definition at line 997 of file KnowledgeBase.inl.

◆ clear_history() [1/2]

void madara::knowledge::KnowledgeBase::clear_history ( const std::string &  key,
const EvalSettings settings = EvalSettings() 
)
inline

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

Definition at line 1672 of file KnowledgeBase.h.

◆ clear_history() [2/2]

void madara::knowledge::KnowledgeBase::clear_history ( const VariableReference key,
const EvalSettings settings = EvalSettings() 
)
inline

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

Definition at line 2017 of file KnowledgeBase.h.

◆ clear_map()

void madara::knowledge::KnowledgeBase::clear_map ( void  )
inline

Clears the knowledge base.

Definition at line 1026 of file KnowledgeBase.inl.

◆ clear_modifieds()

void madara::knowledge::KnowledgeBase::clear_modifieds ( void  )
inline

Clear all modifications to the knowledge base.

This action may be useful if you are wanting to keep local changes but not inform other agents (possibly due to a need to further process and verify the information). The knowledge stays in its current form (i.e., this does not roll back state or anything like that)

Definition at line 1338 of file KnowledgeBase.inl.

◆ close_transport()

void madara::knowledge::KnowledgeBase::close_transport ( void  )
inline

Closes the transport mechanism so no dissemination is possible.

Definition at line 247 of file KnowledgeBase.inl.

◆ compile()

CompiledExpression madara::knowledge::KnowledgeBase::compile ( const std::string &  expression)
inline

Compiles a KaRL expression into an expression tree.

Parameters
expressionexpression to compile
Returns
compiled, optimized expression tree
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

Definition at line 1064 of file KnowledgeBase.inl.

◆ copy() [1/2]

void madara::knowledge::KnowledgeBase::copy ( const KnowledgeBase source,
const CopySet copy_set = CopySet(),
bool  clean_copy = false,
const EvalSettings settings = EvalSettings() 
)
inline

Copies variables and values from source to this context.

PERFORMANCE NOTES: worst case depends on size of copy_set. If empty, performance is always O (n), where n is number of variables in the source context. If copy_set is not empty, then performance is O (m log n) where m is the number of variables in copy_set and n is number of variables in the source context.
 
Note that this is a deep copy due to the fact that source and destination are expected to have their own thread management (ref-counted variables can be problematic if shallow copy).

Parameters
sourcethe source knowledge base to copy from
copy_seta map of variables that should be copied. If empty, then everything is copied. If not empty, only the supplied variables will be copied.
clean_copyif true, clear the destination context (this) before copying.
settingssettings for appplying updates to context

Definition at line 213 of file KnowledgeBase.inl.

◆ copy() [2/2]

void madara::knowledge::KnowledgeBase::copy ( const KnowledgeBase source,
const KnowledgeRequirements reqs,
const EvalSettings settings = EvalSettings() 
)
inline

Copies variables and values from source to this context.

PERFORMANCE NOTES: predicates with prefixes can limit copying to O(log n). predices with suffixes and no prefix force O(n) copy cost since all records could fit requirements

Parameters
sourcethe source context to copy from
reqsrequirements that must be met
settingssettings for appplying updates to context

Definition at line 197 of file KnowledgeBase.inl.

◆ debug_modifieds()

std::string madara::knowledge::KnowledgeBase::debug_modifieds ( void  ) const
inline

Retrieves a stringified list of all modified variables that are ready to send over transport on next send_modifieds call.

Returns
stringified list of the modified knowledge records

Definition at line 1392 of file KnowledgeBase.inl.

◆ define_function() [1/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
boost::python::object  callable 
)
inline

Defines a named python function.

Parameters
namename of the function
callableexternal python function to call with this name

Definition at line 1178 of file KnowledgeBase.inl.

◆ define_function() [2/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
const CompiledExpression expression 
)
inline

Defines a MADARA KaRL function.

Parameters
namename of the function
expressionKaRL function body

Definition at line 1216 of file KnowledgeBase.inl.

◆ define_function() [3/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
const std::string &  expression 
)
inline

Defines a MADARA KaRL function.

Parameters
namename of the function
expressionKaRL function body

Definition at line 1198 of file KnowledgeBase.inl.

◆ define_function() [4/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
jobject  callable 
)
inline

Defines a named java function.

Parameters
namename of the function
callableexternal java object to call with this name

Definition at line 1161 of file KnowledgeBase.inl.

◆ define_function() [5/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
knowledge::KnowledgeRecord(*)(const char *, FunctionArguments &, Variables &)  func 
)
inline

Defines a named function that can distinguish the name it was called with in MADARA.

Parameters
namename of the function
funcexternal function to call with this name

Definition at line 1132 of file KnowledgeBase.inl.

◆ define_function() [6/6]

void madara::knowledge::KnowledgeBase::define_function ( const std::string &  name,
knowledge::KnowledgeRecord(*)(FunctionArguments &, Variables &)  func 
)
inline

Defines a function.

Parameters
namename of the function
funcexternal function to call with this name

Definition at line 1146 of file KnowledgeBase.inl.

◆ evaluate() [1/3]

KnowledgeRecord madara::knowledge::KnowledgeBase::evaluate ( CompiledExpression expression,
const EvalSettings settings = EvalSettings() 
)
inline

Evaluates an expression.

Parameters
expressionKaRL expression to evaluate (result of compile)
settingsSettings for evaluating and printing
Returns
value of expression
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

Definition at line 1096 of file KnowledgeBase.inl.

◆ evaluate() [2/3]

KnowledgeRecord madara::knowledge::KnowledgeBase::evaluate ( const std::string &  expression,
const EvalSettings settings = EvalSettings() 
)
inline

Evaluates an expression.

Parameters
expressionKaRL expression to evaluate
settingsSettings for evaluating and printing
Returns
value of expression
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

Definition at line 1077 of file KnowledgeBase.inl.

◆ evaluate() [3/3]

KnowledgeRecord madara::knowledge::KnowledgeBase::evaluate ( expression::ComponentNode root,
const EvalSettings settings = EvalSettings() 
)
inline

Evaluates a root-based tree (result of compile)

Parameters
rootroot-based tree
settingsSettings for evaluating and printing
Returns
value of expression
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

Definition at line 1114 of file KnowledgeBase.inl.

◆ evaluate_file()

madara::knowledge::KnowledgeRecord madara::knowledge::KnowledgeBase::evaluate_file ( CheckpointSettings checkpoint_settings,
const KnowledgeUpdateSettings update_settings = KnowledgeUpdateSettings(          true, true, true, false) 
)
inline

Loads and evaluates a karl script from a file.

Parameters
checkpoint_settingscheckpoint settings to load
update_settingssettings for applying the updates
Returns
result of evaluation
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1726 of file KnowledgeBase.inl.

◆ exists() [1/2]

bool madara::knowledge::KnowledgeBase::exists ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
) const
inline

Checks if a knowledge location exists in the context.

Parameters
keyknowledge variable location
settingssettings for referring to knowledge variables
Returns
true if location has been set

Definition at line 904 of file KnowledgeBase.inl.

◆ exists() [2/2]

bool madara::knowledge::KnowledgeBase::exists ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
) const
inline

Checks if a knowledge variable exists in the context.

Parameters
variableknowledge variable reference
settingssettings for referring to knowledge variables
Returns
true if location has been set

Definition at line 921 of file KnowledgeBase.inl.

◆ expand_statement()

std::string madara::knowledge::KnowledgeBase::expand_statement ( const std::string &  statement)
inline

Expands a statement using variable expansion.

For example, if the statement were MyKnowledge.{.id}, and .id==1, then the statement would be expanded to MyKnowledge.1

Parameters
statementstatement to expand
Returns
expanded statement

Definition at line 466 of file KnowledgeBase.inl.

◆ facade_for()

void madara::knowledge::KnowledgeBase::facade_for ( ThreadSafeContext target)
inline

Change the knowledge base to become a facade for another context.

It is extremely important that the context stays within scope for the duration of the life of this Knowledge Base. Otherwise, the Knowledge Base will eventually point to invalid memory

Parameters
targetthe target context to manipulate

Definition at line 1468 of file KnowledgeBase.inl.

◆ file_to_string()

std::string madara::knowledge::KnowledgeBase::file_to_string ( CheckpointSettings checkpoint_settings)
inline

Loads and returns a karl script from a file with encode/decode.

Parameters
checkpoint_settingscheckpoint settings to load
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1742 of file KnowledgeBase.inl.

◆ for_each()

template<typename Func >
void madara::knowledge::KnowledgeBase::for_each ( Func &&  func) const
inline

Call given Callable on each element in this KB.

Note that the context will be locked for the entire duration of this iteration. The Callable must accept one argument, a const std::pair<const std::string, KnowledgeRecord>&, and it's return value is ignored.

Template Parameters
Funca callable type as described above
Parameters
functhe callable object; either function pointer or functor

Definition at line 2327 of file KnowledgeBase.h.

◆ get() [1/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::get ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Atomically gets the current value of a variable (without any history).

Parameters
keyknowledge location
settingssettings for referring to knowledge variables
Returns
value at knowledge location

Definition at line 255 of file KnowledgeBase.inl.

◆ get() [2/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::get ( const VariableReference variable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Atomically gets the current value of a variable (without any history).

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingsthe settings for referring to variables
Returns
the madara::knowledge::KnowledgeRecord::Integer value for the variable

Definition at line 289 of file KnowledgeBase.inl.

◆ get_context() [1/2]

ThreadSafeContext & madara::knowledge::KnowledgeBase::get_context ( void  )
inline

Returns the ThreadSafeContext associated with this Knowledge Base.

This is necessary for creating custom transports.

Returns
the context used by the knowledge base

Definition at line 1306 of file KnowledgeBase.inl.

◆ get_context() [2/2]

const ThreadSafeContext & madara::knowledge::KnowledgeBase::get_context ( void  ) const
inline

Returns the ThreadSafeContext associated with this Knowledge Base.

This is necessary for creating custom transports.

Returns
the context used by the knowledge base

Definition at line 1322 of file KnowledgeBase.inl.

◆ get_history() [1/12]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 1881 of file KnowledgeBase.h.

◆ get_history() [2/12]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1896 of file KnowledgeBase.h.

◆ get_history() [3/12]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1928 of file KnowledgeBase.h.

◆ get_history() [4/12]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
OutputIterator  out,
ssize_t  index,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1911 of file KnowledgeBase.h.

◆ get_history() [5/12]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1959 of file KnowledgeBase.h.

◆ get_history() [6/12]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_history ( const std::string &  key,
size_t  index,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1942 of file KnowledgeBase.h.

◆ get_history() [7/12]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 2230 of file KnowledgeBase.h.

◆ get_history() [8/12]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2245 of file KnowledgeBase.h.

◆ get_history() [9/12]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2277 of file KnowledgeBase.h.

◆ get_history() [10/12]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
OutputIterator  out,
ssize_t  index,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2260 of file KnowledgeBase.h.

◆ get_history() [11/12]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2308 of file KnowledgeBase.h.

◆ get_history() [12/12]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_history ( const VariableReference key,
size_t  index,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2291 of file KnowledgeBase.h.

◆ get_history_capacity() [1/2]

size_t madara::knowledge::KnowledgeBase::get_history_capacity ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the maximum amount of history this record can hold.

Use set_history_capacity to adjust this.

Definition at line 1648 of file KnowledgeBase.h.

◆ get_history_capacity() [2/2]

size_t madara::knowledge::KnowledgeBase::get_history_capacity ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the maximum amount of history this record can hold.

Use set_history_capacity to adjust this.

Definition at line 1993 of file KnowledgeBase.h.

◆ get_history_size() [1/2]

size_t madara::knowledge::KnowledgeBase::get_history_size ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the amount of history this record holds.

Definition at line 1637 of file KnowledgeBase.h.

◆ get_history_size() [2/2]

size_t madara::knowledge::KnowledgeBase::get_history_size ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the amount of history this record holds.

Definition at line 1982 of file KnowledgeBase.h.

◆ get_id()

std::string madara::knowledge::KnowledgeBase::get_id ( void  )
inline

Returns the unique host and ephemeral binding for this Knowlede Base.

Returns
host:port identifier for this knowledge base

Definition at line 1412 of file KnowledgeBase.inl.

◆ get_log_level()

int madara::knowledge::KnowledgeBase::get_log_level ( void  )
inline

Gets the log level.

Returns
the maximum detail level to print

Definition at line 145 of file KnowledgeBase.inl.

◆ get_logger()

madara::logger::Logger & madara::knowledge::KnowledgeBase::get_logger ( void  ) const
inline

Gets the logger used for information printing.

Returns
the context's logger

Definition at line 161 of file KnowledgeBase.inl.

◆ get_matches()

void madara::knowledge::KnowledgeBase::get_matches ( const std::string &  prefix,
const std::string &  suffix,
VariableReferences matches 
)
inline

Creates an iteration of VariableReferences to all keys matching the prefix and suffix.

Parameters
prefixstring that the key must start with
suffixstring that the key must end with
matchesall VariableReferences matching the prefix and suffix

Definition at line 1455 of file KnowledgeBase.inl.

◆ get_newest() [1/14]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the newest stored history entry of this record.

Definition at line 1800 of file KnowledgeBase.h.

◆ get_newest() [2/14]

template<typename T >
T madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the newest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord)

Definition at line 1813 of file KnowledgeBase.h.

◆ get_newest() [3/14]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(*out, size_t{})
inline

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

Definition at line 1763 of file KnowledgeBase.h.

◆ get_newest() [4/14]

template<typename OutputIterator , typename ConstOutputIterator >
auto madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
OutputIterator  out,
ConstOutputIterator  out_end,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> utility::enable_if_<!std::is_arithmetic<ConstOutputIterator>::value, size_t>
inline

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

Definition at line 1745 of file KnowledgeBase.h.

◆ get_newest() [5/14]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
OutputIterator  out,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1730 of file KnowledgeBase.h.

◆ get_newest() [6/14]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 1854 of file KnowledgeBase.h.

◆ get_newest() [7/14]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_newest ( const std::string &  key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1869 of file KnowledgeBase.h.

◆ get_newest() [8/14]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the newest stored history entry of this record.

Definition at line 2147 of file KnowledgeBase.h.

◆ get_newest() [9/14]

template<typename T >
T madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the newest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord)

Definition at line 2160 of file KnowledgeBase.h.

◆ get_newest() [10/14]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(*out, size_t{})
inline

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

Definition at line 2110 of file KnowledgeBase.h.

◆ get_newest() [11/14]

template<typename OutputIterator , typename ConstOutputIterator >
auto madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
OutputIterator  out,
ConstOutputIterator  out_end,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> utility::enable_if_<!std::is_arithmetic<ConstOutputIterator>::value, size_t>
inline

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

Definition at line 2092 of file KnowledgeBase.h.

◆ get_newest() [12/14]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
OutputIterator  out,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2076 of file KnowledgeBase.h.

◆ get_newest() [13/14]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 2202 of file KnowledgeBase.h.

◆ get_newest() [14/14]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_newest ( const VariableReference key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2218 of file KnowledgeBase.h.

◆ get_num_transports()

size_t madara::knowledge::KnowledgeBase::get_num_transports ( void  )
inline

Gets the number of transports.

Returns
the number of transports

Definition at line 1269 of file KnowledgeBase.inl.

◆ get_oldest() [1/14]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the oldest stored history entry of this record.

Definition at line 1775 of file KnowledgeBase.h.

◆ get_oldest() [2/14]

template<typename T >
T madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the oldest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord)

Definition at line 1788 of file KnowledgeBase.h.

◆ get_oldest() [3/14]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(*out, size_t{})
inline

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

Definition at line 1716 of file KnowledgeBase.h.

◆ get_oldest() [4/14]

template<typename OutputIterator , typename ConstOutputIterator >
auto madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
OutputIterator  out,
ConstOutputIterator  out_end,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> utility::enable_if_<!std::is_arithmetic<ConstOutputIterator>::value, size_t>
inline

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

Definition at line 1698 of file KnowledgeBase.h.

◆ get_oldest() [5/14]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
OutputIterator  out,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1683 of file KnowledgeBase.h.

◆ get_oldest() [6/14]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 1826 of file KnowledgeBase.h.

◆ get_oldest() [7/14]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_oldest ( const std::string &  key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 1841 of file KnowledgeBase.h.

◆ get_oldest() [8/14]

KnowledgeRecord madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the oldest stored history entry of this record.

Definition at line 2122 of file KnowledgeBase.h.

◆ get_oldest() [9/14]

template<typename T >
T madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return the oldest stored history entry of this record as the type given (which must support knowledge_cast<> from a KnowledgeRecord)

Definition at line 2135 of file KnowledgeBase.h.

◆ get_oldest() [10/14]

template<typename OutputIterator >
auto madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
OutputIterator  out,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(*out, size_t{})
inline

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

Definition at line 2062 of file KnowledgeBase.h.

◆ get_oldest() [11/14]

template<typename OutputIterator , typename ConstOutputIterator >
auto madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
OutputIterator  out,
ConstOutputIterator  out_end,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> utility::enable_if_<!std::is_arithmetic<ConstOutputIterator>::value, size_t>
inline

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

Definition at line 2044 of file KnowledgeBase.h.

◆ get_oldest() [12/14]

template<typename OutputIterator >
size_t madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
OutputIterator  out,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2028 of file KnowledgeBase.h.

◆ get_oldest() [13/14]

std::vector<KnowledgeRecord> madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

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

Definition at line 2173 of file KnowledgeBase.h.

◆ get_oldest() [14/14]

template<typename T >
std::vector<T> madara::knowledge::KnowledgeBase::get_oldest ( const VariableReference key,
size_t  count,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 2189 of file KnowledgeBase.h.

◆ get_ref()

VariableReference madara::knowledge::KnowledgeBase::get_ref ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Atomically returns a reference to the variable.

Variable references are efficient mechanisms for reference variables individually–similar to speedups seen from CompiledExpression.

Parameters
keyunique identifier of the variable
settingssettings for referring to knowledge variables
Returns
reference to the variable in the context

Definition at line 272 of file KnowledgeBase.inl.

◆ has_history() [1/2]

bool madara::knowledge::KnowledgeBase::has_history ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return true if this record has a circular buffer history.

Use set_history_capacity to add a buffer

Definition at line 1627 of file KnowledgeBase.h.

◆ has_history() [2/2]

bool madara::knowledge::KnowledgeBase::has_history ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline

Return true if this record has a circular buffer history.

Use set_history_capacity to add a buffer

Definition at line 1972 of file KnowledgeBase.h.

◆ invoke() [1/4]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::invoke ( const std::string &  key,
Callable &&  callable,
const EvalSettings settings = EvalSettings() 
) -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1522 of file KnowledgeBase.h.

◆ invoke() [2/4]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::invoke ( const std::string &  key,
Callable &&  callable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1556 of file KnowledgeBase.h.

◆ invoke() [3/4]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::invoke ( const VariableReference key,
Callable &&  callable,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1573 of file KnowledgeBase.h.

◆ invoke() [4/4]

template<typename Callable >
auto madara::knowledge::KnowledgeBase::invoke ( VariableReference  key,
Callable &&  callable,
const EvalSettings settings = EvalSettings() 
) -> decltype(utility::invoke_( std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
inline

Definition at line 1539 of file KnowledgeBase.h.

◆ load_context() [1/3]

int64_t madara::knowledge::KnowledgeBase::load_context ( CheckpointSettings checkpoint_settings,
const KnowledgeUpdateSettings update_settings = KnowledgeUpdateSettings(          true, true, true, false) 
)
inline

Loads the context from a file.

Parameters
checkpoint_settingscheckpoint settings to load
update_settingssettings for applying the updates
Returns
-1 if file open failed
-2 if file read failed
>0 if successful (number of bytes written)
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1708 of file KnowledgeBase.inl.

◆ load_context() [2/3]

int64_t madara::knowledge::KnowledgeBase::load_context ( const std::string &  filename,
bool  use_id = true,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings(          true, true, true, false) 
)
inline

Loads the context from a file.

Parameters
filenamename of the file to open
use_idif true, sets the unique identifier to the one found in the saved context. If false, keeps the default identifier.
settingssettings to use when applying updates to context
Returns
total bytes read
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1673 of file KnowledgeBase.inl.

◆ load_context() [3/3]

int64_t madara::knowledge::KnowledgeBase::load_context ( const std::string &  filename,
FileHeader meta,
bool  use_id = true,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings(          true, true, true, false) 
)
inline

Loads the context from a file.

Parameters
filenamename of the file to open
metaa file header that will contain metadata such as originator, timestamp, lamport clock, etc.
use_idif true, sets the unique identifier to the one found in the saved context. If false, keeps the default identifier.
settingssettings for applying the update
Returns
-1 if file open failed
-2 if file read failed
>0 if successful (number of bytes written)
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1691 of file KnowledgeBase.inl.

◆ lock()

void madara::knowledge::KnowledgeBase::lock ( void  )
inline

Locks the context to prevent updates over the network.

Definition at line 121 of file KnowledgeBase.inl.

◆ mark_modified() [1/2]

void madara::knowledge::KnowledgeBase::mark_modified ( const std::string &  name,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Marks the variable as updated.

Parameters
namename of the variable
settingssettings for applying the update

Definition at line 495 of file KnowledgeBase.inl.

◆ mark_modified() [2/2]

void madara::knowledge::KnowledgeBase::mark_modified ( const VariableReference variable,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Marks the variable reference as updated.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingssettings for applying the update

Definition at line 482 of file KnowledgeBase.inl.

◆ modify()

int madara::knowledge::KnowledgeBase::modify ( const EvalSettings settings = EvalSettings())
inline

Alias for apply_modified.

See also
apply_modified
Parameters
settingsSettings for evaluating and printing
Returns
0 if there was not a problem.

Definition at line 1793 of file KnowledgeBase.inl.

◆ operator=()

KnowledgeBase& madara::knowledge::KnowledgeBase::operator= ( const KnowledgeBase original)
default

Assigns another instance's knowledge and settings to this instance.

Parameters
originalknowledge base to copy

◆ print() [1/2]

void madara::knowledge::KnowledgeBase::print ( const std::string &  statement,
unsigned int  level = 0 
) const
inline

Expands and prints a user provided statement at a logging level.

For example, if the statement were MyKnowledge.{.id}, and .id==1, then the statement would be expanded to MyKnowledge.1

Parameters
statementstatement to expand with variable values
levellevel to log the knowledge at

Definition at line 984 of file KnowledgeBase.inl.

◆ print() [2/2]

void madara::knowledge::KnowledgeBase::print ( unsigned int  level = 0) const
inline

Prints all knowledge variables and values in the context.

Parameters
levellevel to log the knowledge at

Definition at line 944 of file KnowledgeBase.inl.

◆ print_knowledge()

void madara::knowledge::KnowledgeBase::print_knowledge ( unsigned int  level = 0) const
inline

Deprecated alias for.

See also
print with only level. This class member will print all knowledge in the context.
Parameters
levellevel to log the knowledge at

Definition at line 956 of file KnowledgeBase.inl.

◆ read_file() [1/2]

int madara::knowledge::KnowledgeBase::read_file ( const std::string &  knowledge_key,
const std::string &  filename,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Read a file into the knowledge base.

Parameters
filenamefile to read
knowledge_keykey to store the file into
settingssettings to use when evaluating/updating

Definition at line 341 of file KnowledgeBase.inl.

◆ read_file() [2/2]

int madara::knowledge::KnowledgeBase::read_file ( const VariableReference variable,
const std::string &  filename,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically reads a file into a variable.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
filenamefile to read
settingssettings for applying the update
Returns
0 if the value was set. -1 if unsuccessful

Definition at line 358 of file KnowledgeBase.inl.

◆ release()

void madara::knowledge::KnowledgeBase::release ( void  )
inline

Releases a recursive lock on the knowledge base.

This will allow other thread to access the knowledge base if you had previously called @ acquire.

Definition at line 1050 of file KnowledgeBase.inl.

◆ remove_transport()

size_t madara::knowledge::KnowledgeBase::remove_transport ( size_t  index)
inline

Removes a transport.

Parameters
indexindex of the transport to remove. If invalid, nothing is removed.
Returns
the size of transports now attached

Definition at line 1294 of file KnowledgeBase.inl.

◆ reset_checkpoint()

void madara::knowledge::KnowledgeBase::reset_checkpoint ( void  ) const
inline

Resets the local changed map, which tracks checkpointing modifieds.

Definition at line 1769 of file KnowledgeBase.inl.

◆ retrieve_index() [1/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::retrieve_index ( const std::string &  key,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Retrieves a value at a specified index within a knowledge array.

Parameters
keyknowledge location
indexindex within the array
settingssettings for referring to knowledge variables
Returns
value at knowledge location

Definition at line 306 of file KnowledgeBase.inl.

◆ retrieve_index() [2/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::retrieve_index ( const VariableReference variable,
size_t  index,
const KnowledgeReferenceSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Retrieves a value at a specified index within a knowledge array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
indexindex within the array
settingssettings for referring to knowledge variables
Returns
value at knowledge location

Definition at line 323 of file KnowledgeBase.inl.

◆ save_as_json() [1/2]

int64_t madara::knowledge::KnowledgeBase::save_as_json ( const CheckpointSettings settings) const
inline

Saves the context to a file as JSON.

Parameters
settingsthe settings to save
Returns
total bytes written

Definition at line 1589 of file KnowledgeBase.inl.

◆ save_as_json() [2/2]

int64_t madara::knowledge::KnowledgeBase::save_as_json ( const std::string &  filename) const
inline

Saves the context to a file as JSON.

Parameters
filenamename of the file to save to
Returns
total bytes written

Definition at line 1573 of file KnowledgeBase.inl.

◆ save_as_karl() [1/2]

int64_t madara::knowledge::KnowledgeBase::save_as_karl ( const CheckpointSettings settings) const
inline

Saves the context to a file as karl assignments, rather than binary.

Parameters
settingsthe settings to save
Returns
total bytes written

Definition at line 1622 of file KnowledgeBase.inl.

◆ save_as_karl() [2/2]

int64_t madara::knowledge::KnowledgeBase::save_as_karl ( const std::string &  filename) const
inline

Saves the context to a file as karl assignments, rather than binary.

Parameters
filenamename of the file to save to
Returns
total bytes written

Definition at line 1606 of file KnowledgeBase.inl.

◆ save_checkpoint() [1/2]

int64_t madara::knowledge::KnowledgeBase::save_checkpoint ( CheckpointSettings settings) const
inline

Saves a checkpoint of a list of changes to a file.

Parameters
settingscheckpoint settings to load
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1656 of file KnowledgeBase.inl.

◆ save_checkpoint() [2/2]

int64_t madara::knowledge::KnowledgeBase::save_checkpoint ( const std::string &  filename,
bool  reset_modifieds = true 
)
inline

Saves a checkpoint of a list of changes to a file.

Parameters
filenamename of the file to open
reset_modifiedsif true, resets the modified list to empty.
Returns
total bytes written
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1639 of file KnowledgeBase.inl.

◆ save_context() [1/2]

int64_t madara::knowledge::KnowledgeBase::save_context ( CheckpointSettings settings) const
inline

Saves the context to a file.

Parameters
settingsthe settings to save
Returns
-1 if file open failed
-2 if file write failed
>0 if successful (number of bytes written)
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1557 of file KnowledgeBase.inl.

◆ save_context() [2/2]

int64_t madara::knowledge::KnowledgeBase::save_context ( const std::string &  filename) const
inline

Saves the context to a file.

Parameters
filenamename of the file to save to
Returns
total bytes written
Exceptions
exceptions::MemoryExceptionnot enough buffer to encode

Definition at line 1541 of file KnowledgeBase.inl.

◆ save_modifieds()

VariableReferences madara::knowledge::KnowledgeBase::save_modifieds ( void  ) const
inline

Saves the list of modified records to use later for resending.

This does not clear the modified list. This feature is useful if you want to remember what has been modified and then resend later, e.g., if you believe packets may be dropped and want to resend information. Use this function in conjunction with

See also
add_modifieds to remodify
Returns
a vector of VariableReferences to the current modified list

Definition at line 1363 of file KnowledgeBase.inl.

◆ send_modifieds()

int madara::knowledge::KnowledgeBase::send_modifieds ( const std::string &  prefix = "KnowledgeBase::send_modifieds",
const EvalSettings settings = EvalSettings::SEND 
)
inline

Sends all modified variables through the attached transports.

Parameters
prefixfor logging purposes, the descriptor prefix for calling method
settingssettings for sending modifications
Returns
number of transports the modifications were sent to

Definition at line 1379 of file KnowledgeBase.inl.

◆ set() [1/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const double *  value,
uint32_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of doubles to set at the location
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 720 of file KnowledgeBase.inl.

◆ set() [2/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const EvalSettings settings = EvalSettings(                                      true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an integer 1.

Parameters
keythe name of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 906 of file KnowledgeBase.h.

◆ set() [3/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const KnowledgeRecord value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a KnowledgeRecord.

Parameters
keythe variable name
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 525 of file KnowledgeBase.inl.

◆ set() [4/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const madara::knowledge::KnowledgeRecord::Integer value,
uint32_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of integers to set at the location
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 614 of file KnowledgeBase.inl.

◆ set() [5/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const std::string &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 822 of file KnowledgeBase.inl.

◆ set() [6/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const std::vector< double > &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of doubles to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 754 of file KnowledgeBase.inl.

◆ set() [7/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
const std::vector< KnowledgeRecord::Integer > &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of integers to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 650 of file KnowledgeBase.inl.

◆ set() [8/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
KnowledgeRecord &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a KnowledgeRecord.

Parameters
keythe variable name
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 542 of file KnowledgeBase.inl.

◆ set() [9/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
std::string &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 856 of file KnowledgeBase.inl.

◆ set() [10/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
std::vector< double > &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of doubles to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 771 of file KnowledgeBase.inl.

◆ set() [11/26]

int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
std::vector< KnowledgeRecord::Integer > &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuearray of integers to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 686 of file KnowledgeBase.inl.

◆ set() [12/26]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type >
int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 41 of file KnowledgeBase.inl.

◆ set() [13/26]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type = nullptr>
int madara::knowledge::KnowledgeBase::set ( const std::string &  key,
value,
const EvalSettings settings = EvalSettings(true, false, true, false, false) 
)

Sets a knowledge variable to a specified value.

Parameters
keyknowledge variable location
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

◆ set() [14/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const double *  value,
uint32_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a double array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuean array of doubles
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 737 of file KnowledgeBase.inl.

◆ set() [15/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an integer 1.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 476 of file KnowledgeBase.h.

◆ set() [16/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const KnowledgeRecord value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a KnowledgeRecord.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 559 of file KnowledgeBase.inl.

◆ set() [17/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const madara::knowledge::KnowledgeRecord::Integer value,
uint32_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an integer array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuean array of Integers
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 632 of file KnowledgeBase.inl.

◆ set() [18/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const std::string &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a string.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 839 of file KnowledgeBase.inl.

◆ set() [19/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const std::vector< double > &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a double array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuea STL vector of doubles
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 788 of file KnowledgeBase.inl.

◆ set() [20/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
const std::vector< KnowledgeRecord::Integer > &  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an integer array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuea STL vector of Integers
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 668 of file KnowledgeBase.inl.

◆ set() [21/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
KnowledgeRecord &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a KnowledgeRecord.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 508 of file KnowledgeBase.inl.

◆ set() [22/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
std::string &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a string.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 873 of file KnowledgeBase.inl.

◆ set() [23/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
std::vector< double > &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a double array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuea STL vector of doubles
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 805 of file KnowledgeBase.inl.

◆ set() [24/26]

int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
std::vector< KnowledgeRecord::Integer > &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an integer array.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuea STL vector of Integers
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 703 of file KnowledgeBase.inl.

◆ set() [25/26]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, void * >::type >
int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a double.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 60 of file KnowledgeBase.inl.

◆ set() [26/26]

template<typename T , typename std::enable_if< std::is_integral< T >::value, void * >::type = nullptr>
int madara::knowledge::KnowledgeBase::set ( const VariableReference variable,
value,
const EvalSettings settings = EvalSettings(true, false, true, false, false) 
)

Atomically sets the value of a variable to an integer.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

◆ set_file() [1/2]

int madara::knowledge::KnowledgeBase::set_file ( const std::string &  key,
const unsigned char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an arbitrary string.

Parameters
keyname of a variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 375 of file KnowledgeBase.inl.

◆ set_file() [2/2]

int madara::knowledge::KnowledgeBase::set_file ( const VariableReference variable,
const unsigned char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to an arbitrary string.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 397 of file KnowledgeBase.inl.

◆ set_history_capacity() [1/2]

void madara::knowledge::KnowledgeBase::set_history_capacity ( const std::string &  key,
size_t  size,
const EvalSettings settings = EvalSettings() 
)
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.

Definition at line 1661 of file KnowledgeBase.h.

◆ set_history_capacity() [2/2]

void madara::knowledge::KnowledgeBase::set_history_capacity ( const VariableReference key,
size_t  size,
const EvalSettings settings = EvalSettings() 
)
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.

Definition at line 2006 of file KnowledgeBase.h.

◆ set_index() [1/2]

template<typename T >
int madara::knowledge::KnowledgeBase::set_index ( const std::string &  key,
size_t  index,
T &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Sets an index within an array to a specified value.

Parameters
keyknowledge variable location
indexindex of the location in the array
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 577 of file KnowledgeBase.inl.

◆ set_index() [2/2]

template<typename T >
int madara::knowledge::KnowledgeBase::set_index ( const VariableReference variable,
size_t  index,
T &&  value,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of an array index to a value.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
indexindex within array
valuenew value of the array index
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 595 of file KnowledgeBase.inl.

◆ set_jpeg() [1/2]

int madara::knowledge::KnowledgeBase::set_jpeg ( const std::string &  key,
const unsigned char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a JPEG image.

Parameters
keyname of a variable
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 414 of file KnowledgeBase.inl.

◆ set_jpeg() [2/2]

int madara::knowledge::KnowledgeBase::set_jpeg ( const VariableReference variable,
const unsigned char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(          true, false, true, false, false) 
)
inline

Atomically sets the value of a variable to a JPEG image.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 436 of file KnowledgeBase.inl.

◆ set_log_level()

void madara::knowledge::KnowledgeBase::set_log_level ( int  level)
inline

Sets the log level.

Parameters
levelthe maximum detail level to print

Definition at line 185 of file KnowledgeBase.inl.

◆ set_quality()

void madara::knowledge::KnowledgeBase::set_quality ( const std::string &  key,
uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Sets the quality of writing to a certain variable from this entity.

Set quality of writing to a variable.

Parameters
keyknowledge variable location
qualityquality of writing to this location
settingssettings for referring to knowledge variables

Definition at line 891 of file KnowledgeBase.inl.

◆ set_text()

int madara::knowledge::KnowledgeBase::set_text ( const VariableReference variable,
const char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(true, false, true, false, false) 
)

Atomically sets the value of a variable to a text file's contents.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

◆ set_xml()

int madara::knowledge::KnowledgeBase::set_xml ( const VariableReference variable,
const char *  value,
size_t  size,
const EvalSettings settings = EvalSettings(true, false, true, false, false) 
)

Atomically sets the value of a variable to an XML string.

Parameters
variablereference to a variable (
See also
get_ref)
Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

◆ setup_unique_hostport()

std::string madara::knowledge::KnowledgeBase::setup_unique_hostport ( const std::string &  host = "")
inline

Binds to an ephemeral port for unique tie breakers in global ordering.

Call this function if you want to generate a unique id for a custom transport to use (or a built-in transport if you are creating one outside of the KnowledgeBase.

Parameters
hostunique host identifier string ("" if requesting a generated id.
Returns
unique host id (same as host param if host is not "")

Definition at line 1781 of file KnowledgeBase.inl.

◆ share_binary() [1/2]

std::shared_ptr<const std::vector<unsigned char> > madara::knowledge::KnowledgeBase::share_binary ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not a binary file, returns NULL shared_ptr

Definition at line 319 of file KnowledgeBase.h.

◆ share_binary() [2/2]

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

Definition at line 339 of file KnowledgeBase.h.

◆ share_doubles() [1/2]

std::shared_ptr<const std::vector<double> > madara::knowledge::KnowledgeBase::share_doubles ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 279 of file KnowledgeBase.h.

◆ share_doubles() [2/2]

std::shared_ptr<const std::vector<double> > madara::knowledge::KnowledgeBase::share_doubles ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 299 of file KnowledgeBase.h.

◆ share_integers() [1/2]

std::shared_ptr<const std::vector<KnowledgeRecord::Integer> > madara::knowledge::KnowledgeBase::share_integers ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) const
inline
Returns
a shared_ptr, sharing with the internal one. If this record is not an integer array, returns NULL shared_ptr

Definition at line 239 of file KnowledgeBase.h.

◆ share_integers() [2/2]

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

Definition at line 259 of file KnowledgeBase.h.

◆ share_string() [1/2]

std::shared_ptr<const std::string> madara::knowledge::KnowledgeBase::share_string ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 199 of file KnowledgeBase.h.

◆ share_string() [2/2]

std::shared_ptr<const std::string> madara::knowledge::KnowledgeBase::share_string ( const VariableReference key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings() 
) 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 219 of file KnowledgeBase.h.

◆ throw_null_context()

void madara::knowledge::KnowledgeBase::throw_null_context ( ) const
inlineprivate

Definition at line 1514 of file KnowledgeBase.h.

◆ to_map() [1/3]

KnowledgeMap madara::knowledge::KnowledgeBase::to_map ( const std::string &  prefix) const
inline

Creates a variable map with Knowledge Records that begin with the given prefix.

Runs in O(log n + m) time, where n is the size of the KnowledgeBase, and m is the number of matching records

Parameters
prefixPrefix string to match with
Returns
A new map with just entries starting with prefix

Definition at line 1512 of file KnowledgeBase.inl.

◆ to_map() [2/3]

size_t madara::knowledge::KnowledgeBase::to_map ( const std::string &  prefix,
const std::string &  delimiter,
const std::string &  suffix,
std::vector< std::string > &  next_keys,
std::map< std::string, knowledge::KnowledgeRecord > &  result,
bool  just_keys = false 
)
inline

Fills a variable map with list of keys according to a matching prefix, suffix, and delimiter hierarchy.

This is useful for understanding the logical hierarchy of your variables (and also a key utility of containers like

See also
containers::FlexMap).
Parameters
prefixText that must be present at the front of the key
delimiterText that signifies a logical boundary in hierarchy If empty, no check is performed.
suffixText that must be present at the end of the key. If empty, no check is performed.
next_keysThe immediate keys in the hierarchy after prefix
resultThe map that will be filled with full variable names and the Knowledge Records that correspond to
just_keysif true, do not fill result, only next_keys
Returns
entries in the resulting map

Definition at line 1491 of file KnowledgeBase.inl.

◆ to_map() [3/3]

size_t madara::knowledge::KnowledgeBase::to_map ( const std::string &  subject,
std::map< std::string, knowledge::KnowledgeRecord > &  target 
)
inline

Fills a variable map with Knowledge Records that match an expression.

At the moment, this expression must be of the form "subject*"

Parameters
subjectAn expression that matches the variable names that are of interest. Wildcards may only be at the end.
targetThe map that will be filled with variable names and the Knowledge Records they correspond to
Returns
entries in the resulting map

Definition at line 1474 of file KnowledgeBase.inl.

◆ to_map_stripped()

KnowledgeMap madara::knowledge::KnowledgeBase::to_map_stripped ( const std::string &  prefix) const
inline

Creates a map with Knowledge Records that begin with the given prefix.

Runs in O(log n + m) time, where n is the size of the KnowledgeBase, and m is the number of matching records

All key names have the "prefix" portion stripped off their front in the returned map.

Parameters
prefixPrefix string to match with
Returns
A new map with just entries starting with prefix

Definition at line 1526 of file KnowledgeBase.inl.

◆ to_string()

void madara::knowledge::KnowledgeBase::to_string ( std::string &  target,
const std::string &  array_delimiter = ",",
const std::string &  record_delimiter = ";\n",
const std::string &  key_val_delimiter = "=" 
) const
inline

Saves all keys and values into a string, using the underlying knowledge::KnowledgeRecord::to_string function.

This is an optimized version that allows the specification of a target string to avoid string copying (which can be expensive with longer strings across multiple function boundaries). This function differs from knowledge::KnowledgeRecord to_string in that it is intended to save the database in a format that can be easily parseable. Consequently, strings are delineated in this function by being included in single quotes. Arrays are delineated with array indices [].

This is not appropriate for saving the context if it has binary data inside of it, as only the size of the data entry would be saved.

Parameters
targetwhere to store the resulting string operation.
array_delimiterfor any arrays, the characters in between data elements.
record_delimiterthe characters to place between individual key/value pairs
key_val_delimiterthe characters to place between keys and values.

Definition at line 968 of file KnowledgeBase.inl.

◆ to_vector()

size_t madara::knowledge::KnowledgeBase::to_vector ( const std::string &  subject,
unsigned int  start,
unsigned int  end,
std::vector< KnowledgeRecord > &  target 
)
inline

Fills a vector with Knowledge Records that begin with a common subject and have a finite range of integer values.

Parameters
subjectThe common subject of the variable names. For instance, if we are looking for a range of vars like "var0", "var1", "var2", then the common subject would be "var".
startAn inclusive start index
endAn inclusive end index
targetThe vector that will be filled with Knowledge Record instances within the subject range.
Returns
entries in the resulting vector

Definition at line 1438 of file KnowledgeBase.inl.

◆ transport_settings()

madara::transport::TransportSettings & madara::knowledge::KnowledgeBase::transport_settings ( void  )
inline
Returns
a non-const reference to the Transport Settings
settings reference

Definition at line 938 of file KnowledgeBase.inl.

◆ unlock()

void madara::knowledge::KnowledgeBase::unlock ( void  )
inline

Unlocks the context to allow updates over the network (is only necessary if the context has been explicitly locked)

Definition at line 133 of file KnowledgeBase.inl.

◆ use()

void madara::knowledge::KnowledgeBase::use ( ThreadSafeContext original)
inline

Refer to and use another knowledge base's context.

Parameters
originalknowledge base to refer to

Definition at line 115 of file KnowledgeBase.inl.

◆ wait() [1/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::wait ( CompiledExpression expression,
const WaitSettings settings = WaitSettings() 
)

Waits for an expression to be non-zero.

Provides additional settings for fine-tuning the time to wait and atomic print statements.

Parameters
expressionKaRL expression to wait on (result of compile)
settingsSettings for the underlying expression evaluation and printing
Returns
value of expression
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

The only situation this can be useful will be if the thread safe context is being used as a shared memory structure between threads. This should not be used for processes communicating together because the wait statement is unable to send modifieds as it has zero concept of transports. The type of knowledge base handled here is a facade for another knowledge base's context.

Definition at line 24 of file KnowledgeBase.cpp.

◆ wait() [2/2]

KnowledgeRecord madara::knowledge::KnowledgeBase::wait ( const std::string &  expression,
const WaitSettings settings = WaitSettings() 
)
inline

Waits for an expression to be non-zero.

Always disseminates modifications.

Parameters
expressionKaRL expression to wait on
settingsSettings for the underlying expression evaluation and printing
Returns
value of expression
Exceptions
exceptions::KarlExceptionfailure during compile/evaluate

Definition at line 1229 of file KnowledgeBase.inl.

◆ wait_for_change()

void madara::knowledge::KnowledgeBase::wait_for_change ( void  )
inline

Wait for a change to happen to the context (e.g., from transports)

Definition at line 1757 of file KnowledgeBase.inl.

◆ write_file()

ssize_t madara::knowledge::KnowledgeBase::write_file ( const std::string &  knowledge_key,
const std::string &  filename 
)
inline

Write a file from the knowledge base to a specified location.

Parameters
filenamefile to write to
knowledge_keykey to read the file from

Definition at line 453 of file KnowledgeBase.inl.

Member Data Documentation

◆ context_

ThreadSafeContext* madara::knowledge::KnowledgeBase::context_
private

A knowledge base can also be a facade for another knowledge base.

Definition at line 2345 of file KnowledgeBase.h.

◆ impl_

std::shared_ptr<KnowledgeBaseImpl> madara::knowledge::KnowledgeBase::impl_
private

Pointer to actual implementation, i.e., the "bridge", which is reference counted to automate memory management.

Definition at line 2342 of file KnowledgeBase.h.


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