MADARA
3.1.8
|
Provides an interface for external functions into the MADARA KaRL variable settings. More...
#include <ExternFunctionVariables.h>
Public Member Functions | |
Variables () | |
Constructor. More... | |
Variables (const Variables &rhs) | |
Constructor. More... | |
void | apply_modified (const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings()) |
Applies modified to all global variables. More... | |
CompiledExpression | compile (const std::string &expression) |
Compiles a KaRL expression into an expression tree. More... | |
knowledge::KnowledgeRecord | dec (const std::string &key, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Decrements the value of the variable. More... | |
knowledge::KnowledgeRecord | dec (const VariableReference &variable, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Decrements the value of the variable. 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, 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, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings()) |
Evaluates an expression (USE ONLY FOR PROTOTYPING; DO NOT USE IN PRODUCTION SYSTEMS). More... | |
madara::knowledge::KnowledgeRecord | evaluate (CompiledExpression &expression, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings()) |
Evaluates an expression. 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) const |
Expands a string with variable expansion. More... | |
knowledge::KnowledgeRecord | get (const std::string &key, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false)) |
Retrieves the value of a variable. More... | |
knowledge::KnowledgeRecord | get (const VariableReference &variable, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false)) |
Retrieves the value of a variable. More... | |
ThreadSafeContext * | get_context (void) |
Returns the ThreadSafeContext associated with this Variables facade. 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... | |
VariableReference | get_ref (const std::string &key, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false)) |
Retrieves the value of a variable. More... | |
knowledge::KnowledgeRecord | inc (const std::string &key, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically increments the value of the variable. More... | |
knowledge::KnowledgeRecord | inc (const VariableReference &variable, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically increments the value of the variable. More... | |
int64_t | load_context (const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false)) |
Loads the context from a file. More... | |
void | operator= (Variables &rhs) |
Assignment operator. More... | |
void | print (unsigned int level=0) const |
Prints all variables and values in the context. More... | |
void | print (const std::string &statement, unsigned int level=0) const |
Print a statement, similar to printf (variable expansions allowed) e.g., input = "MyVar{.id} = {MyVar{.id}}\n";. More... | |
madara::knowledge::KnowledgeRecord | retrieve_index (const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=knowledge::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=knowledge::KnowledgeReferenceSettings(false)) |
Retrieves a value at a specified index within a knowledge array. 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 (const std::string &filename, bool reset_modifieds=true) |
Saves a checkpoint of a list of changes to a file. More... | |
int64_t | save_context (const std::string &filename) |
Saves the context to a file. More... | |
int | set (const std::string &key, madara::knowledge::KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const VariableReference &variable, madara::knowledge::KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const std::string &key, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to an integer array. More... | |
int | set (const VariableReference &variable, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to an integer array. More... | |
int | set (const std::string &key, const std::vector< KnowledgeRecord::Integer > &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to an integer array. More... | |
int | set (const VariableReference &variable, const std::vector< KnowledgeRecord::Integer > &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to an integer array. More... | |
int | set (const std::string &key, double value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const VariableReference &variable, double value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const std::string &key, const double *value, uint32_t size, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to a double array. More... | |
int | set (const VariableReference &variable, const double *value, uint32_t size, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to a double array. More... | |
int | set (const std::string &key, const std::vector< double > &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to a double array. More... | |
int | set (const VariableReference &variable, const std::vector< double > &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Atomically sets the value of a variable to a double array. More... | |
int | set (const std::string &key, const std::string &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const VariableReference &variable, const std::string &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const std::string &key, const madara::knowledge::KnowledgeRecord &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. More... | |
int | set (const VariableReference &variable, const madara::knowledge::KnowledgeRecord &value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. 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... | |
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... | |
ssize_t | write_file (const std::string &knowledge_key, const std::string &filename) |
Write a file from the context to a specified location. More... | |
Private Attributes | |
ThreadSafeContext * | context_ |
Variables context that is directly used by the KaRL engine. More... | |
Friends | |
class | madara::expression::CompositeFunctionNode |
class | madara::knowledge::KnowledgeRecordFilters |
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition at line 51 of file ExternFunctionVariables.h.
|
inline |
Constructor.
Definition at line 60 of file ExternFunctionVariables.h.
|
inline |
Constructor.
Definition at line 68 of file ExternFunctionVariables.h.
void madara::knowledge::Variables::apply_modified | ( | const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings () | ) |
Applies modified to all global variables.
settings | Settings for evaluating and printing |
Definition at line 102 of file ExternFunctionVariables.cpp.
madara::knowledge::CompiledExpression madara::knowledge::Variables::compile | ( | const std::string & | expression | ) |
Compiles a KaRL expression into an expression tree.
Always do this before calling evaluate because it puts the expression into an optimized format. Best practice is to save the CompiledExpression in a global variable or in some kind of persistent store. Pair with expand_statement if you know that variable expansion is used but the variable values that are expanded never change (e.g. an id that is set through the command line and thus stays the same after it is initially set).
expression | expression to compile |
Definition at line 721 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::dec | ( | const std::string & | key, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Decrements the value of the variable.
key | unique identifier of the variable |
settings | Settings for updating knowledge |
Definition at line 522 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::dec | ( | const VariableReference & | variable, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Decrements the value of the variable.
variable | reference to a variable ( |
settings | Settings for updating knowledge |
Definition at line 541 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
knowledge::KnowledgeRecord(*)(FunctionArguments &, Variables &) | func | ||
) |
Defines a function.
name | name of the function |
func | external function to call with this name |
Definition at line 628 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
knowledge::KnowledgeRecord(*)(const char *, FunctionArguments &, Variables &) | func | ||
) |
Defines a named function that can distinguish the name it was called with in MADARA.
name | name of the function |
func | external function to call with this name |
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
const std::string & | expression | ||
) |
Defines a MADARA KaRL function.
name | name of the function |
expression | KaRL function body |
Definition at line 685 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
const CompiledExpression & | expression | ||
) |
Defines a MADARA KaRL function.
name | name of the function |
expression | KaRL function body |
Definition at line 705 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::evaluate | ( | const std::string & | expression, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings () |
||
) |
Evaluates an expression (USE ONLY FOR PROTOTYPING; DO NOT USE IN PRODUCTION SYSTEMS).
Consider compiling the expression first with a one-time compile call during an initialization phase for your program, and then using the evaluate CompiledExpression call in any function that must be called frequently or periodically. The difference in overhead between this function and the compiled version is orders of magnitude (generally nanoseconds versus microseconds every call).
expression | KaRL expression to evaluate |
settings | Settings for evaluating and printing |
Definition at line 737 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::evaluate | ( | CompiledExpression & | expression, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings () |
||
) |
Evaluates an expression.
Recommended best practices are to compile the expression into a global variable or persistent store outside of the function call and use a reference to this CompiledExpression from within the external function that you create.
expression | KaRL expression to wait on (result of compile) |
settings | Settings for updating knowledge |
Definition at line 756 of file ExternFunctionVariables.cpp.
bool madara::knowledge::Variables::exists | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings (false) |
||
) | const |
Checks if a knowledge location exists in the context.
key | knowledge variable location |
settings | settings for referring to knowledge variables |
Definition at line 64 of file ExternFunctionVariables.cpp.
bool madara::knowledge::Variables::exists | ( | const VariableReference & | variable, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings (false) |
||
) | const |
Checks if a knowledge variable exists in the context.
variable | knowledge variable reference |
settings | settings for referring to knowledge variables |
Definition at line 83 of file ExternFunctionVariables.cpp.
std::string madara::knowledge::Variables::expand_statement | ( | const std::string & | statement | ) | const |
Expands a string with variable expansion.
For instance, if .id == 5, and a statement of "MyVar{.id} = {.id} * 30" then then expanded statement would be "MyVar5 = 5 * 30".
statement | statement to expand. Useful for printing. |
Definition at line 608 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::get | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = knowledge::KnowledgeReferenceSettings (false) |
||
) |
Retrieves the value of a variable.
key | unique identifier of the variable |
settings | settings when referring to variables |
Definition at line 25 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::get | ( | const VariableReference & | variable, |
const KnowledgeReferenceSettings & | settings = knowledge::KnowledgeReferenceSettings (false) |
||
) |
Retrieves the value of a variable.
variable | reference to a variable ( |
settings | settings when referring to variables |
Definition at line 45 of file ExternFunctionVariables.cpp.
madara::knowledge::ThreadSafeContext * madara::knowledge::Variables::get_context | ( | void | ) |
Returns the ThreadSafeContext associated with this Variables facade.
This is necessary for creating custom transports.
Definition at line 19 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::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.
prefix | string that the key must start with |
suffix | string that the key must end with |
matches | all VariableReferences matching the prefix and suffix |
Definition at line 798 of file ExternFunctionVariables.cpp.
madara::knowledge::VariableReference madara::knowledge::Variables::get_ref | ( | const std::string & | key, |
const KnowledgeReferenceSettings & | settings = knowledge::KnowledgeReferenceSettings (false) |
||
) |
Retrieves the value of a variable.
key | unique identifier of the variable |
settings | settings when referring to variables |
Definition at line 156 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::inc | ( | const std::string & | key, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically increments the value of the variable.
key | unique identifier of the variable |
settings | Settings for updating knowledge |
Definition at line 486 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::inc | ( | const VariableReference & | variable, |
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically increments the value of the variable.
variable | reference to a variable ( |
settings | Settings for updating knowledge |
Definition at line 504 of file ExternFunctionVariables.cpp.
int64_t madara::knowledge::Variables::load_context | ( | const std::string & | filename, |
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings (true, true, true, false) |
||
) |
Loads the context from a file.
filename | name of the file to open |
settings | settings to use when applying updates to context |
Definition at line 898 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::operator= | ( | Variables & | rhs | ) |
Assignment operator.
Definition at line 10 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::print | ( | unsigned int | level = 0 | ) | const |
Prints all variables and values in the context.
level | log level. |
Definition at line 578 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::print | ( | const std::string & | statement, |
unsigned int | level = 0 |
||
) | const |
Print a statement, similar to printf (variable expansions allowed) e.g., input = "MyVar{.id} = {MyVar{.id}}\n";.
statement | templated statement to print from |
level | log level. |
Definition at line 593 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::retrieve_index | ( | const std::string & | key, |
size_t | index, | ||
const KnowledgeReferenceSettings & | settings = knowledge::KnowledgeReferenceSettings (false) |
||
) |
Retrieves a value at a specified index within a knowledge array.
key | variable name of the array |
index | index within the array |
settings | settings for referring to knowledge variables |
Definition at line 117 of file ExternFunctionVariables.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::Variables::retrieve_index | ( | const VariableReference & | variable, |
size_t | index, | ||
const KnowledgeReferenceSettings & | settings = knowledge::KnowledgeReferenceSettings (false) |
||
) |
Retrieves a value at a specified index within a knowledge array.
variable | reference to a variable ( |
index | index within the array |
settings | settings for referring to knowledge variables |
Definition at line 137 of file ExternFunctionVariables.cpp.
int64_t madara::knowledge::Variables::save_as_karl | ( | const std::string & | filename | ) | const |
Saves the context to a file as karl assignments, rather than binary.
filename | name of the file to save to |
Definition at line 856 of file ExternFunctionVariables.cpp.
int64_t madara::knowledge::Variables::save_checkpoint | ( | const std::string & | filename, |
bool | reset_modifieds = true |
||
) |
Saves a checkpoint of a list of changes to a file.
filename | name of the file to open |
reset_modifieds | if true, resets the modified list to empty. |
Definition at line 875 of file ExternFunctionVariables.cpp.
int64_t madara::knowledge::Variables::save_context | ( | const std::string & | filename | ) |
Saves the context to a file.
filename | name of the file to open |
Definition at line 837 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
madara::knowledge::KnowledgeRecord::Integer | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
key | unique identifier of the variable |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 173 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
madara::knowledge::KnowledgeRecord::Integer | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
variable | reference to a variable ( |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 192 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const madara::knowledge::KnowledgeRecord::Integer * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to an integer array.
key | unique identifier of the variable |
value | an array of Integers |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 211 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const madara::knowledge::KnowledgeRecord::Integer * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to an integer array.
variable | reference to a variable ( |
value | an array of Integers |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 231 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const std::vector< KnowledgeRecord::Integer > & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to an integer array.
key | unique identifier of the variable |
value | a STL vector of Integers |
settings | settings for applying the update |
Definition at line 251 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const std::vector< KnowledgeRecord::Integer > & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to an integer array.
variable | reference to a variable ( |
value | a STL vector of Integers |
settings | settings for applying the update |
Definition at line 271 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
double | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
key | unique identifier of the variable |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 329 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
double | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
variable | reference to a variable ( |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 349 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const double * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to a double array.
key | unique identifier of the variable |
value | an array of doubles |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 368 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const double * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to a double array.
variable | reference to a variable ( |
value | an array of doubles |
size | number of elements in the array |
settings | settings for applying the update |
Definition at line 389 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const std::vector< double > & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to a double array.
key | unique identifier of the variable |
value | a STL vector of doubles |
settings | settings for applying the update |
Definition at line 409 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const std::vector< double > & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Atomically sets the value of a variable to a double array.
variable | reference to a variable ( |
value | a STL vector of doubles |
settings | settings for applying the update |
Definition at line 429 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const std::string & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
key | unique identifier of the variable |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 448 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const std::string & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
variable | reference to a variable ( |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 467 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const std::string & | key, |
const madara::knowledge::KnowledgeRecord & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
key | unique identifier of the variable |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 290 of file ExternFunctionVariables.cpp.
int madara::knowledge::Variables::set | ( | const VariableReference & | variable, |
const madara::knowledge::KnowledgeRecord & | value, | ||
const KnowledgeUpdateSettings & | settings = knowledge::KnowledgeUpdateSettings ( false, true, false, false) |
||
) |
Sets the value of a variable.
variable | reference to a variable ( |
value | new value of the variable |
settings | Settings for updating knowledge |
Definition at line 310 of file ExternFunctionVariables.cpp.
size_t madara::knowledge::Variables::to_map | ( | const std::string & | subject, |
std::map< std::string, knowledge::KnowledgeRecord > & | target | ||
) |
Fills a variable map with Knowledge Records that match an expression.
At the moment, this expression must be of the form "subject*"
subject | An expression that matches the variable names that are of interest. Wildcards may only be at the end. |
target | The map that will be filled with variable names and the Knowledge Records they correspond to |
Definition at line 815 of file ExternFunctionVariables.cpp.
void madara::knowledge::Variables::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.
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.
target | where to store the resulting string operation. |
array_delimiter | for any arrays, the characters in between data elements. |
record_delimiter | the characters to place between individual key/value pairs |
key_val_delimiter | the characters to place between keys and values. |
Definition at line 559 of file ExternFunctionVariables.cpp.
size_t madara::knowledge::Variables::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.
subject | The 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". |
start | An inclusive start index |
end | An inclusive end index |
target | The vector that will be filled with Knowledge Record instances within the subject range. |
Definition at line 776 of file ExternFunctionVariables.cpp.
ssize_t madara::knowledge::Variables::write_file | ( | const std::string & | knowledge_key, |
const std::string & | filename | ||
) |
Write a file from the context to a specified location.
filename | file to write to |
knowledge_key | key to read the file from |
Definition at line 919 of file ExternFunctionVariables.cpp.
|
friend |
Definition at line 54 of file ExternFunctionVariables.h.
|
friend |
Definition at line 55 of file ExternFunctionVariables.h.
|
private |
Variables context that is directly used by the KaRL engine.
Definition at line 674 of file ExternFunctionVariables.h.