MADARA  3.2.3
madara::knowledge::KnowledgeBaseImpl Class Reference

This class provides a distributed knowledge base implementation. More...

#include <KnowledgeBaseImpl.h>

Public Member Functions

 KnowledgeBaseImpl ()
 Constructor. More...
 
 KnowledgeBaseImpl (const std::string &host, int transport)
 Constructor. More...
 
 KnowledgeBaseImpl (const std::string &host, int transport, const std::string &domain)
 Constructor. More...
 
 KnowledgeBaseImpl (const std::string &host, const madara::transport::TransportSettings &config)
 Constructor. More...
 
 ~KnowledgeBaseImpl ()
 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...
 
size_t attach_transport (madara::transport::Base *transport)
 Attaches a transport to the Knowledge Engine. More...
 
size_t attach_transport (const std::string &id, transport::TransportSettings &settings)
 Adds a built-in transport with the specified settings. More...
 
bool clear (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Clears a variable. More...
 
void clear (bool erase=false)
 Clears the knowledge base. More...
 
void clear_map (void)
 Clears the knowledge base. More...
 
void clear_modifieds (void)
 Clear all modifications to the knowledge base. More...
 
void clear_rules (void)
 Clears the permanent knowledge rules (unimplemented) 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 KnowledgeBaseImpl &source, const KnowledgeRequirements &reqs)
 Copies variables and values from source to this context. More...
 
void copy (const KnowledgeBaseImpl &source, const CopySet &copy_set=CopySet(), bool clean_copy=false)
 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, knowledge::KnowledgeRecord(*func)(FunctionArguments &, Variables &))
 Defines a 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, jobject callable)
 Defines a named python function. 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 std::string &expression)
 Defines a MADARA KaRL function. More...
 
void define_function (const std::string &name, const CompiledExpression &expression)
 Defines a MADARA KaRL function. More...
 
madara::knowledge::KnowledgeRecord evaluate (const std::string &expression)
 Evaluates an expression. More...
 
madara::knowledge::KnowledgeRecord evaluate (const std::string &expression, const EvalSettings &settings)
 Evaluates an expression. More...
 
madara::knowledge::KnowledgeRecord evaluate (CompiledExpression &expression, const EvalSettings &settings)
 Evaluates an expression. More...
 
madara::knowledge::KnowledgeRecord evaluate (expression::ComponentNode *root, const EvalSettings &settings=EvalSettings())
 Evaluates a root-based tree (result of compile) More...
 
bool exists (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) 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) const
 Expands a statement using variable expansion. More...
 
madara::knowledge::KnowledgeRecord get (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Retrieves a knowledge value. More...
 
madara::knowledge::KnowledgeRecord get (const VariableReference &variable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Atomically returns the value of a variable. More...
 
ThreadSafeContextget_context (void)
 Returns the ThreadSafeContext associated with this Knowledge Base. 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...
 
size_t get_num_transports (void)
 Gets the number of transports. More...
 
VariableReference get_ref (const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Atomically returns a reference to the variable. More...
 
int64_t load_context (const std::string &filename, bool use_id, 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...
 
int64_t load_context (CheckpointSettings &checkpoint_settings, const KnowledgeUpdateSettings &update_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 VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Marks the variable reference as updated. More...
 
void mark_modified (const std::string &name, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Marks the variable as updated. More...
 
void print (unsigned int level) const
 Prints all knowledge variables and values in the context. More...
 
void print (const std::string &statement, unsigned int level) const
 Expands and prints a user provided statement at a logging level. More...
 
int read_file (const std::string &knowledge_key, const std::string &filename, const EvalSettings &settings=EvalSettings())
 Read a file into the knowledge base. More...
 
int read_file (const VariableReference &variable, const std::string &filename, const EvalSettings &settings=EvalSettings())
 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())
 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=KnowledgeReferenceSettings())
 Retrieves a value at a specified index within a knowledge array. More...
 
int64_t save_as_json (const std::string &filename) const
 Saves the context to a file as JSON. More...
 
int64_t save_as_json (const CheckpointSettings &settings) const
 Saves the context to a file as JSON. 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_as_karl (const CheckpointSettings &settings) const
 Saves the context to a file as karl assignments, rather than binary. 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_checkpoint (CheckpointSettings &settings) const
 Saves a checkpoint of a list of changes to a file. More...
 
int64_t save_context (const std::string &filename) const
 Saves the context to a file. More...
 
int64_t save_context (CheckpointSettings &settings) 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...
 
MADARA_EXPORT int send_modifieds (const std::string &prefix, const EvalSettings &settings=EvalSettings())
 Sends all modified variables through the attached transports. More...
 
template<typename K , typename V >
int set (K &&key, V &&val, const EvalSettings &settings)
 
template<typename K , typename V >
int set (K &&key, const V *arr, size_t size, const EvalSettings &settings)
 
int set_file (const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings())
 Atomically sets the value of a variable to the contents of a file. More...
 
template<typename K , typename V >
int set_index (K &&key, size_t i, V &&val, const EvalSettings &settings)
 
int set_jpeg (const VariableReference &variable, const unsigned char *value, size_t size, const EvalSettings &settings=EvalSettings())
 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())
 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())
 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())
 Atomically sets the value of a variable to an XML string. More...
 
std::string setup_unique_hostport (std::string host="")
 Creates a random UUID for unique tie breakers in global ordering. More...
 
template<typename K >
std::shared_ptr< std::vector< unsigned char > > share_binary (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Returns a shared_ptr, sharing with the internal one. More...
 
template<typename K >
std::shared_ptr< std::vector< double > > share_doubles (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Returns a shared_ptr, sharing with the internal one. More...
 
template<typename K >
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > share_integers (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Returns a shared_ptr, sharing with the internal one. More...
 
template<typename K >
std::shared_ptr< std::string > share_string (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
 Returns a shared_ptr, sharing with the internal one. More...
 
template<typename K >
std::shared_ptr< std::vector< unsigned char > > take_binary (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Returns a shared_ptr, while resetting this record to empty. More...
 
template<typename K >
std::shared_ptr< std::vector< double > > take_doubles (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Returns a shared_ptr, while resetting this record to empty. More...
 
template<typename K >
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > take_integers (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Returns a shared_ptr, while resetting this record to empty. More...
 
template<typename K >
std::shared_ptr< std::string > take_string (K &&key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
 Returns a shared_ptr, while resetting this record to empty. 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...
 
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)
 Fills a variable map with list of keys according to a matching prefix, suffix, and delimiter hierarchy. More...
 
knowledge::KnowledgeMap to_map (const std::string &prefix) const
 Creates a variable map with Knowledge Records that begin with the given prefix. 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)
 Returns a non-const reference to the Transport Settings. More...
 
void unlock (void)
 Unlocks the context to allow updates over the network (is only necessary if the context has been explicitly locked) More...
 
madara::knowledge::KnowledgeRecord wait (const std::string &expression)
 Waits for an expression to be non-zero. More...
 
madara::knowledge::KnowledgeRecord wait (const std::string &expression, const WaitSettings &settings)
 Waits for an expression to be non-zero. More...
 
madara::knowledge::KnowledgeRecord wait (CompiledExpression &expression, const WaitSettings &settings)
 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 Attributes

std::string id_
 
ThreadSafeContext map_
 
transport::QoSTransportSettings settings_
 
std::vector< std::unique_ptr< transport::Base > > transports_
 

Detailed Description

This class provides a distributed knowledge base implementation.

Definition at line 38 of file KnowledgeBaseImpl.h.

Constructor & Destructor Documentation

madara::knowledge::KnowledgeBaseImpl::KnowledgeBaseImpl ( )
inline

Constructor.

Definition at line 20 of file KnowledgeBaseImpl.inl.

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

Constructor.

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

Definition at line 26 of file KnowledgeBaseImpl.inl.

madara::knowledge::KnowledgeBaseImpl::KnowledgeBaseImpl ( 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 realm we want to join

Definition at line 37 of file KnowledgeBaseImpl.inl.

madara::knowledge::KnowledgeBaseImpl::KnowledgeBaseImpl ( 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 50 of file KnowledgeBaseImpl.inl.

madara::knowledge::KnowledgeBaseImpl::~KnowledgeBaseImpl ( )
inline

Destructor.

Definition at line 59 of file KnowledgeBaseImpl.inl.

Member Function Documentation

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

Acquires the recursive lock on the knowledge base.

lock the underlying knowledge base against any updates until we release

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

Definition at line 376 of file KnowledgeBaseImpl.inl.

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

Starts the transport mechanism for dissemination if it is closed.

Definition at line 250 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 745 of file KnowledgeBaseImpl.inl.

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

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

Updates all global variables to current clock and then sends them if a transport is available.

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

This is useful when trying to synchronize to late joiners (this process will resend all global variables.

Definition at line 159 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 106 of file KnowledgeBaseImpl.inl.

size_t madara::knowledge::KnowledgeBaseImpl::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 This class takes ownership of this pointer and will close and delete the transport as needed.
Returns
the number of transports now attached

Definition at line 466 of file KnowledgeBaseImpl.inl.

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

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 66 of file KnowledgeBaseImpl.cpp.

bool madara::knowledge::KnowledgeBaseImpl::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 356 of file KnowledgeBaseImpl.inl.

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

Clears the knowledge base.

This is a very unsafe operation if erase is set to true. Setting erase to true could cause operations that were using the variable in CompiledExpression or VariableReference to fail catastrophically (e.g., illegal operation and segfaults) due to accessing memory that is no longer initialized. The absolute only reason you should ever set erase to true would be if you have absolutely no intention of using a CompiledExpression or VariableReference that had been previously accessing the memory, and that includes all of the knowledge::containers classes also!

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

Definition at line 363 of file KnowledgeBaseImpl.inl.

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

Clears the knowledge base.

Definition at line 369 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 647 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::clear_rules ( void  )

Clears the permanent knowledge rules (unimplemented)

void madara::knowledge::KnowledgeBaseImpl::close_transport ( void  )

Closes the transport mechanism so no dissemination is possible.

Definition at line 185 of file KnowledgeBaseImpl.cpp.

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

Compiles a KaRL expression into an expression tree.

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

Definition at line 208 of file KnowledgeBaseImpl.cpp.

void madara::knowledge::KnowledgeBaseImpl::copy ( const KnowledgeBaseImpl source,
const KnowledgeRequirements reqs 
)
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

Definition at line 268 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::copy ( const KnowledgeBaseImpl source,
const CopySet copy_set = CopySet (),
bool  clean_copy = false 
)
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.

Definition at line 276 of file KnowledgeBaseImpl.inl.

std::string madara::knowledge::KnowledgeBaseImpl::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 94 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 391 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 399 of file KnowledgeBaseImpl.inl.

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

Defines a named python function.

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

Definition at line 408 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 418 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 430 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 438 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::evaluate ( const std::string &  expression)
inline

Evaluates an expression.

Always disseminates modifications.

Parameters
expressionKaRL expression to evaluate
Returns
value of expression
Exceptions
expression::KarlExceptionfailure during compile/evaluate

Definition at line 455 of file KnowledgeBaseImpl.inl.

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

Evaluates an expression.

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

Definition at line 766 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::evaluate ( CompiledExpression expression,
const EvalSettings settings 
)

Evaluates an expression.

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

Definition at line 316 of file KnowledgeBaseImpl.cpp.

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

Evaluates a root-based tree (result of compile)

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

Definition at line 352 of file KnowledgeBaseImpl.cpp.

bool madara::knowledge::KnowledgeBaseImpl::exists ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) 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 137 of file KnowledgeBaseImpl.inl.

bool madara::knowledge::KnowledgeBaseImpl::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 145 of file KnowledgeBaseImpl.inl.

std::string madara::knowledge::KnowledgeBaseImpl::expand_statement ( const std::string &  statement) const
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 298 of file KnowledgeBaseImpl.inl.

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

Retrieves a knowledge value.

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

Definition at line 64 of file KnowledgeBaseImpl.inl.

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

Atomically returns the value of a variable.

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 72 of file KnowledgeBaseImpl.inl.

ThreadSafeContext & madara::knowledge::KnowledgeBaseImpl::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 513 of file KnowledgeBaseImpl.inl.

std::string madara::knowledge::KnowledgeBaseImpl::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 524 of file KnowledgeBaseImpl.inl.

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

Gets the log level.

Returns
the maximum detail level to print

Definition at line 88 of file KnowledgeBaseImpl.inl.

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

Gets the logger used for information printing.

Returns
the context's logger

Definition at line 100 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 559 of file KnowledgeBaseImpl.inl.

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

Gets the number of transports.

Returns
the number of transports

Definition at line 476 of file KnowledgeBaseImpl.inl.

VariableReference madara::knowledge::KnowledgeBaseImpl::get_ref ( const std::string &  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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 80 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::load_context ( const std::string &  filename,
bool  use_id,
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 for modifying context
Returns
total bytes read

Definition at line 682 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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)

Definition at line 701 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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)

Definition at line 723 of file KnowledgeBaseImpl.inl.

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

Locks the context to prevent updates over the network.

Definition at line 285 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 176 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 184 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::print ( unsigned int  level) const
inline

Prints all knowledge variables and values in the context.

Parameters
levellevel to log the knowledge at

Definition at line 328 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::print ( const std::string &  statement,
unsigned int  level 
) 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 349 of file KnowledgeBaseImpl.inl.

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

Read a file into the knowledge base.

Parameters
filenamefile to read
knowledge_keykey to store the file into
settingssettings for updating/evaluating
Returns
-1 if unsuccessful, 0 otherwise

Definition at line 193 of file KnowledgeBaseImpl.inl.

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

Atomically reads a file into a variable.

Read a file into the knowledge base.

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 237 of file KnowledgeBaseImpl.inl.

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

Releases a recursive lock on the knowledge base.

release the lock on the underlying knowledge base

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

Definition at line 382 of file KnowledgeBaseImpl.inl.

size_t madara::knowledge::KnowledgeBaseImpl::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 484 of file KnowledgeBaseImpl.inl.

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

Resets the local changed map, which tracks checkpointing modifieds.

Definition at line 654 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::retrieve_index ( const std::string &  key,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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 119 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::retrieve_index ( const VariableReference variable,
size_t  index,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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 128 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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 619 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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 626 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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 633 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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 640 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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

Definition at line 661 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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)

Definition at line 674 of file KnowledgeBaseImpl.inl.

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

Saves the context to a file.

Parameters
filenamename of the file to open
Returns
total bytes written

Definition at line 604 of file KnowledgeBaseImpl.inl.

int64_t madara::knowledge::KnowledgeBaseImpl::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)

Definition at line 611 of file KnowledgeBaseImpl.inl.

VariableReferences madara::knowledge::KnowledgeBaseImpl::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 752 of file KnowledgeBaseImpl.inl.

int madara::knowledge::KnowledgeBaseImpl::send_modifieds ( const std::string &  prefix,
const EvalSettings settings = EvalSettings () 
)

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 390 of file KnowledgeBaseImpl.cpp.

template<typename K , typename V >
int madara::knowledge::KnowledgeBaseImpl::set ( K &&  key,
V &&  val,
const EvalSettings settings 
)
inline

Definition at line 518 of file KnowledgeBaseImpl.h.

template<typename K , typename V >
int madara::knowledge::KnowledgeBaseImpl::set ( K &&  key,
const V *  arr,
size_t  size,
const EvalSettings settings 
)
inline

Definition at line 540 of file KnowledgeBaseImpl.h.

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

Atomically sets the value of a variable to the contents of a file.

Read a file into the knowledge base.

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 209 of file KnowledgeBaseImpl.inl.

template<typename K , typename V >
int madara::knowledge::KnowledgeBaseImpl::set_index ( K &&  key,
size_t  i,
V &&  val,
const EvalSettings settings 
)
inline

Definition at line 528 of file KnowledgeBaseImpl.h.

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

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

Read a file into the knowledge base.

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 223 of file KnowledgeBaseImpl.inl.

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

Sets the log level.

Parameters
levelthe maximum detail level to print

Definition at line 113 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::set_quality ( const std::string &  key,
uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
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 314 of file KnowledgeBaseImpl.inl.

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

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
int madara::knowledge::KnowledgeBaseImpl::set_xml ( const VariableReference variable,
const char *  value,
size_t  size,
const EvalSettings settings = EvalSettings() 
)

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
std::string madara::knowledge::KnowledgeBaseImpl::setup_unique_hostport ( std::string  host = "")

Creates a random UUID 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
hosthost identifier string (defaults to local hostname if "")
Returns
unique host id

Definition at line 36 of file KnowledgeBaseImpl.cpp.

template<typename K >
std::shared_ptr<std::vector<unsigned char> > madara::knowledge::KnowledgeBaseImpl::share_binary ( K &&  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
) const
inline

Returns a shared_ptr, sharing with the internal one.

If this record is not a binary files, returns NULL shared_ptr

Definition at line 248 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::vector<double> > madara::knowledge::KnowledgeBaseImpl::share_doubles ( K &&  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 224 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::KnowledgeBaseImpl::share_integers ( K &&  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 200 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::string> madara::knowledge::KnowledgeBaseImpl::share_string ( K &&  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 176 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::vector<unsigned char> > madara::knowledge::KnowledgeBaseImpl::take_binary ( K &&  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Returns a shared_ptr, while resetting this record to empty.

If this record is not a binary file, returns NULL shared_ptr

Definition at line 260 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::vector<double> > madara::knowledge::KnowledgeBaseImpl::take_doubles ( K &&  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Returns a shared_ptr, while resetting this record to empty.

If this record is not an integer array, returns NULL shared_ptr

Definition at line 236 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::vector<KnowledgeRecord::Integer> > madara::knowledge::KnowledgeBaseImpl::take_integers ( K &&  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Returns a shared_ptr, while resetting this record to empty.

If this record is not an integer array, returns NULL shared_ptr

Definition at line 212 of file KnowledgeBaseImpl.h.

template<typename K >
std::shared_ptr<std::string> madara::knowledge::KnowledgeBaseImpl::take_string ( K &&  key,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings () 
)
inline

Returns a shared_ptr, while resetting this record to empty.

If this record is not a string, returns NULL shared_ptr

Definition at line 188 of file KnowledgeBaseImpl.h.

size_t madara::knowledge::KnowledgeBaseImpl::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 568 of file KnowledgeBaseImpl.inl.

size_t madara::knowledge::KnowledgeBaseImpl::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 
)
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 576 of file KnowledgeBaseImpl.inl.

KnowledgeMap madara::knowledge::KnowledgeBaseImpl::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 589 of file KnowledgeBaseImpl.inl.

KnowledgeMap madara::knowledge::KnowledgeBaseImpl::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 596 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 338 of file KnowledgeBaseImpl.inl.

size_t madara::knowledge::KnowledgeBaseImpl::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 549 of file KnowledgeBaseImpl.inl.

madara::transport::TransportSettings & madara::knowledge::KnowledgeBaseImpl::transport_settings ( void  )
inline

Returns a non-const reference to the Transport Settings.

Returns
settings reference

Definition at line 322 of file KnowledgeBaseImpl.inl.

void madara::knowledge::KnowledgeBaseImpl::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 291 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::wait ( const std::string &  expression)
inline

Waits for an expression to be non-zero.

Always disseminates modifications.

Parameters
expressionKaRL expression to wait on
Returns
value of expression
Exceptions
expression::KarlExceptionfailure during compile/evaluate

Definition at line 446 of file KnowledgeBaseImpl.inl.

KnowledgeRecord madara::knowledge::KnowledgeBaseImpl::wait ( const std::string &  expression,
const WaitSettings settings 
)

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
settingsSettings for the underlying expression evaluation and printing
Returns
value of expression
Exceptions
expression::KarlExceptionfailure during compile/evaluate

Definition at line 219 of file KnowledgeBaseImpl.cpp.

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

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
expression::KarlExceptionfailure during compile/evaluate

Definition at line 227 of file KnowledgeBaseImpl.cpp.

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

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

Definition at line 760 of file KnowledgeBaseImpl.inl.

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

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

Write file from the knowledge base to a specified file.

Parameters
filenamefile to write to
knowledge_keykey to read the file from
Returns
-1 if unsuccessful, 0 otherwise

Definition at line 306 of file KnowledgeBaseImpl.inl.

Member Data Documentation

std::string madara::knowledge::KnowledgeBaseImpl::id_
private

Definition at line 1061 of file KnowledgeBaseImpl.h.

ThreadSafeContext madara::knowledge::KnowledgeBaseImpl::map_
private

Definition at line 1060 of file KnowledgeBaseImpl.h.

transport::QoSTransportSettings madara::knowledge::KnowledgeBaseImpl::settings_
private

Definition at line 1062 of file KnowledgeBaseImpl.h.

std::vector<std::unique_ptr<transport::Base> > madara::knowledge::KnowledgeBaseImpl::transports_
private

Definition at line 1064 of file KnowledgeBaseImpl.h.


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