2 #ifndef _MADARA_NO_KARL_ 48 bool arg_can_change =
false;
49 result =
nodes_[0]->prune (arg_can_change);
51 if (!arg_can_change && dynamic_cast <LeafNode *> (
nodes_[0]) == 0)
57 else if (
nodes_.size () != 0)
60 "madara::expression::SystemCallPrintSystemCalls: " 62 "System call print_system_calls takes either 0" 65 throw KarlException (
"madara::expression::SystemCallPrintSystemCalls: " 66 "KARL COMPILE ERROR: " 67 "System call print_system_calls takes either 0" 74 calls_[
"#clear_variable"] =
75 "\n#clear_var (var) or #clear_variable (var):\n" 76 " Clears the variable var in the knowledge base. This is\n" 77 " the preferred way to delete variables. It masks the variable\n" 78 " from printouts and save_modifieds but leaves a phantom record\n" 79 " in the knowledge base to safely reference in VariableReference,\n" 80 " CompiledExpression, etc.\n";
84 " Returns the cosine of a term (radians)\n";
86 calls_[
"#delete_variable"] =
87 "\n#delete_var (var) or #delete_variable (var):\n" 88 " Deletes a variable named var from the knowledge base. \n" 89 " This is an extremely unsafe operation that must only\n" 90 " be used if the variable is never used in compiled\n" 91 " expressions or variable references (including container\n" 92 " classes such as Integer, Double, Vector, etc.)\n";
95 "\n#eval (expression) or #evaluate (expression):\n" 96 " Evaluates the KaRL expression and returns a result. Works similarly\n" 97 " to the KnowledgeBase::evaluate function except this function\n" 98 " inherits the KnowledgeUpdateSettings from the eval call.\n";
101 "\n#eval (expression) or #evaluate (expression):\n" 102 " Evaluates the KaRL expression and returns a result. Works similarly\n" 103 " to the KnowledgeBase::evaluate function except this function\n" 104 " inherits the KnowledgeUpdateSettings from the eval call.\n";
107 "\n#expand (statement) or #expand_statement (statement):\n" 108 " Expands a statement such as 'var{.i}' into 'var0', assuming .i=0\n";
111 "\n#expand_env (statement) or #expand_envs (statement):\n" 112 " Expands a statement such as 'env_var=$(VAR)' into\n" 113 " env_var=VAR CONTENTS, assuming VAR has been set in the OS.\n";
116 "\n#expand_env (statement) or #expand_envs (statement):\n" 117 " Expands a statement such as 'env_var=$(VAR)' into\n" 118 " env_var=VAR CONTENTS, assuming VAR has been set in the OS.\n";
120 calls_[
"#expand_statement"] =
121 "\n#expand (statement) or #expand_statement (statement):\n" 122 " Expands a statement such as 'var{.i}' into 'var0', assuming .i=0\n";
125 "\n#fragment (arg, first, last):\n" 126 " Returns a fragment of the arg, startin at first byte and extending\n" 130 "\n#get_clock () or #get_clock (variable):\n" 131 " Returns either the system clock or the variable clock. Note that\n" 132 " this is a Lamport clock value and not a wall time value.\n";
135 "\n#get_time () or #get_time_ns() or #get_time_nano():\n" 136 " Returns wall clock time on the local machine in nanoseconds.\n";
138 calls_[
"#get_time_seconds"] =
139 "\n#get_time_seconds () or #get_time_s ():\n" 140 " Returns wall clock time on the local machine in seconds.\n";
143 "\n#isinf (value):\n" 144 " Returns std::isinf of a value to check for infinity/-infinity.\n";
147 "\n#log_level () or #log_level (value):\n" 148 " Returns the logging level or sets the logging level. The logging\n" 149 " level determines the granularity of MADARA log messages. The value\n" 150 " should be an integer from 0-6.\n" 151 " 0: Emergency or always messages. Default setting.\n" 157 " 6. Detailed logging\n";
160 "\n#pow (base, power):\n" 161 " Returns the base taken to a power (exponent)\n";
164 "\n#print (statement):\n" 165 " Prints a statement that can contain MADARA KaRL variables.\n" 166 " Variables are expanding to include their values where applicable.\n" 167 " For instance, 'var{.id}' would result in printing 'var0' if .id\n" 168 " was set to 0. The same statement would print 'variable' if .id\n" 169 " was set to 'iable'.\n";
171 calls_[
"#print_system_calls"] =
172 "\n#print_system_calls () or #print_system_call (system_call):\n" 173 " Prints help for all system calls or a specific system call.\n";
176 "\n#rand_double (floor = 0.0, ceiling = 1.0, update_srand = true):\n" 177 " Generates a random double from a uniform distribution.\n";
180 "\n#rand_int (floor = 0, ceiling = RAND_MAX, update_srand = true):\n" 181 " Generates a random integer from a uniform distribution.\n";
184 "\n#read_file (filename) or #read_file (filename, type):\n" 185 " Reads a file and returns its contents. Default is to determine\n" 186 " file type by filname extension. Explicit type can be a string\n" 187 " or an integer of the following values:\n" 193 "\n#set_clock (value) or #set_clock (variable, value):\n" 194 " Sets the system clock or a variable clock. The value should be\n" 195 " a non-zero integer (Lamport clock) and is used to determine which\n" 196 " variable values are rejected at the transport layer. Returns the\n" 197 " new clock value.\n";
200 "\n#set_fixed () or #fixed ():\n" 201 " Sets the output format for doubles to fixed format (std::fixed).\n";
203 calls_[
"#set_precision"] =
204 "\n#set_precision (value) or #precision (value):\n" 205 " Sets the precision that is used to convert doubles to strings.\n" 206 " This is a fixed precision (e.g., 5 for pi would be 3.14159).\n" 207 " Negative value resets to default precision.\n";
209 calls_[
"#set_scientific"] =
210 "\n#set_scientific () or #scientific ():\n" 211 " Sets the output format for doubles to scientific format\n" 212 " (std::scientific).\n";
216 " Returns the sine of a term (radians)\n";
220 " Returns the size of the variable or value.\n";
223 "\n#sleep (double time_to_sleep in s):\n" 224 " Sleeps for at least the specified time and returns time\n" 225 " spent sleeping in seconds.\n";
229 " Returns the square root of a value\n";
233 " Returns the tangent of a term (radians)\n";
236 "\n#to_buffer (value) or #buffer (value):\n" 237 " Converts the value to an unsigned char array.\n";
240 "\n#to_double (value) or #double (value):\n" 241 " Converts the value to a double.\n";
244 "\n#to_doubles (value) or #doubles (value):\n" 245 " Converts the value to an array of doubles.\n";
248 "\n#to_host_dirs (directory):\n" 249 " Returns the host appropriate directory structure, e.g.,.\n" 250 " files/file.txt to files\file.txt on Windows.\n";
253 "\n#to_integer (value) or #integer (value):\n" 254 " Converts the value to an integer.\n";
257 "\n#to_integers (value) or #integers (value):\n" 258 " Converts the value to an array of integers.\n";
261 "\n#to_string (value, delimiter) or #string (value, delimiter):\n" 262 " Converts the value to an ASCII string. Delimiter is an optional\n" 263 " string sequence that separates elements of an integer or double" 268 " Returns the integer type of the variable or value.\n" 269 " Supported types are:\n" 270 " UNINITIALIZED = 0\n" 274 " UNKNOWN_FILE_TYPE = 8\n" 277 " INTEGER_ARRAY = 64\n" 278 " DOUBLE_ARRAY = 128\n" 279 " IMAGE_JPEG = 256\n";
282 "\n#write_file (filename, value):\n" 283 " Writes the value to a file. Supports all MADARA types.\n" 302 "madara::expression::SystemCallPrintSystemCalls: " 303 "System call print_system_calls is printing help\n");
310 else if (
nodes_.size () == 0)
313 "madara::expression::SystemCallPrintSystemCalls: " 314 "System call print_system_calls is printing help\n");
316 for (SystemCallsHelp::const_iterator i =
calls_.begin ();
319 if (i->first !=
"#delete_var" && i->first !=
"#eval" &&
320 i->first !=
"#expand" && i->first !=
"#expand_env")
327 "madara::expression::SystemCallPrintSystemCalls: " 328 "KARL RUNTIME ERROR:" 329 "System call print_system_calls takes either 0" 330 " or 1 arguments\n");
332 throw KarlException (
"madara::expression::SystemCallPrintSystemCalls: " 333 "KARL RUNTIME ERROR: " 334 "System call print_system_calls takes either 0" 335 " or 1 arguments\n");
346 visitor.
visit (*
this);
349 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
std::map< std::string, std::string > SystemCallsHelp
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
logger::Logger * logger_
handle the context
This class stores variables and their values for use by any entity needing state information in a thr...
void print(unsigned int level) const
Atomically prints all variables and values in the context.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
static SystemCallsHelp calls_
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
Abstract base class for all visitors to all classes that derive from ComponentNode.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
madara::knowledge::ThreadSafeContext & context_
An exception for unrecoverable KaRL compilation issues.
Interface for a MADARA system call.
Settings for applying knowledge updates.
SystemCallPrintSystemCalls(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual ~SystemCallPrintSystemCalls(void)
Destructor.