MADARA
3.4.1
|
Provides an interface for external functions into the MADARA KaRL variable settings. More...
#include <Variables.h>
Public Member Functions | |
Variables (const Variables &rhs) | |
Constructor. More... | |
Variables (ThreadSafeContext *new_context=0) | |
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, 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 KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings()) |
Evaluates an expression. 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... | |
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 (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... | |
void | print (unsigned int level=0) const |
Prints all variables and values in the context. 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, 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 madara::knowledge::KnowledgeRecord &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 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 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 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 std::string &key, double value, const KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings(false, true, false, false)) |
Sets the value of a variable. 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, 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 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::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 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::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< 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, double 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... | |
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 52 of file Variables.h.
|
inline |
Constructor.
Definition at line 61 of file Variables.h.
|
inline |
Constructor.
Definition at line 66 of file Variables.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 97 of file Variables.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 |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 650 of file Variables.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 467 of file Variables.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 484 of file Variables.cpp.
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
boost::python::object | callable | ||
) |
Defines a named python function.
name | name of the function |
callable | external python function to call with this name |
Definition at line 596 of file Variables.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 636 of file Variables.cpp.
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 617 of file Variables.cpp.
void madara::knowledge::Variables::define_function | ( | const std::string & | name, |
jobject | callable | ||
) |
Defines a named java function.
name | name of the function |
callable | external java object to call with this name |
Definition at line 578 of file Variables.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, |
knowledge::KnowledgeRecord(*)(FunctionArguments &, Variables &) | func | ||
) |
Defines a function.
name | name of the function |
func | external function to call with this name |
Definition at line 562 of file Variables.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 evaluate (result of compile) |
settings | Settings for updating knowledge |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 683 of file Variables.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 |
exceptions::KarlException | failure during compile/evaluate |
Definition at line 666 of file Variables.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 61 of file Variables.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 79 of file Variables.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 543 of file Variables.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 23 of file Variables.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 42 of file Variables.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 17 of file Variables.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 719 of file Variables.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 146 of file Variables.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 434 of file Variables.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 451 of file Variables.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 807 of file Variables.cpp.
void madara::knowledge::Variables::operator= | ( | Variables & | rhs | ) |
Assignment operator.
Definition at line 9 of file Variables.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 529 of file Variables.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 516 of file Variables.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 111 of file Variables.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 129 of file Variables.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 768 of file Variables.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 786 of file Variables.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 751 of file Variables.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 335 of file Variables.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 267 of file Variables.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 197 of file Variables.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 401 of file Variables.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 368 of file Variables.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 232 of file Variables.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 302 of file Variables.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 162 of file Variables.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 352 of file Variables.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 285 of file Variables.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 215 of file Variables.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 418 of file Variables.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 385 of file Variables.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 250 of file Variables.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 319 of file Variables.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 180 of file Variables.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 733 of file Variables.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 500 of file Variables.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 701 of file Variables.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 826 of file Variables.cpp.
|
friend |
Definition at line 55 of file Variables.h.
|
friend |
Definition at line 56 of file Variables.h.
|
private |
Variables context that is directly used by the KaRL engine.
Definition at line 633 of file Variables.h.