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 "KARL COMPILE ERROR: System call print_system_calls takes either 0" 61 " or 1 arguments.\n");
67 calls_[
"#clear_variable"] =
68 "\n#clear_var (var) or #clear_variable (var):\n" 69 " Clears the variable var in the knowledge base. This is\n" 70 " the preferred way to delete variables. It masks the variable\n" 71 " from printouts and save_modifieds but leaves a phantom record\n" 72 " in the knowledge base to safely reference in VariableReference,\n" 73 " CompiledExpression, etc.\n";
77 " Returns the cosine of a term (radians)\n";
79 calls_[
"#delete_variable"] =
80 "\n#delete_var (var) or #delete_variable (var):\n" 81 " Deletes a variable named var from the knowledge base. \n" 82 " This is an extremely unsafe operation that must only\n" 83 " be used if the variable is never used in compiled\n" 84 " expressions or variable references (including container\n" 85 " classes such as Integer, Double, Vector, etc.)\n";
88 "\n#eval (expression) or #evaluate (expression):\n" 89 " Evaluates the KaRL expression and returns a result. Works similarly\n" 90 " to the KnowledgeBase::evaluate function except this function\n" 91 " inherits the KnowledgeUpdateSettings from the eval call.\n";
94 "\n#eval (expression) or #evaluate (expression):\n" 95 " Evaluates the KaRL expression and returns a result. Works similarly\n" 96 " to the KnowledgeBase::evaluate function except this function\n" 97 " inherits the KnowledgeUpdateSettings from the eval call.\n";
100 "\n#expand (statement) or #expand_statement (statement):\n" 101 " Expands a statement such as 'var{.i}' into 'var0', assuming .i=0\n";
104 "\n#expand_env (statement) or #expand_envs (statement):\n" 105 " Expands a statement such as 'env_var=$(VAR)' into\n" 106 " env_var=VAR CONTENTS, assuming VAR has been set in the OS.\n";
109 "\n#expand_env (statement) or #expand_envs (statement):\n" 110 " Expands a statement such as 'env_var=$(VAR)' into\n" 111 " env_var=VAR CONTENTS, assuming VAR has been set in the OS.\n";
113 calls_[
"#expand_statement"] =
114 "\n#expand (statement) or #expand_statement (statement):\n" 115 " Expands a statement such as 'var{.i}' into 'var0', assuming .i=0\n";
118 "\n#fragment (arg, first, last):\n" 119 " Returns a fragment of the arg, startin at first byte and extending\n" 123 "\n#get_clock () or #get_clock (variable):\n" 124 " Returns either the system clock or the variable clock. Note that\n" 125 " this is a Lamport clock value and not a wall time value.\n";
128 "\n#get_time () or #get_time_ns() or #get_time_nano():\n" 129 " Returns wall clock time on the local machine in nanoseconds.\n";
131 calls_[
"#get_time_seconds"] =
132 "\n#get_time_seconds () or #get_time_s ():\n" 133 " Returns wall clock time on the local machine in seconds.\n";
136 "\n#log_level () or #log_level (value):\n" 137 " Returns the logging level or sets the logging level. The logging\n" 138 " level determines the granularity of MADARA log messages. The value\n" 139 " should be an integer from 0-6.\n" 140 " 0: Emergency or always messages. Default setting.\n" 146 " 6. Detailed logging\n";
149 "\n#pow (base, power):\n" 150 " Returns the base taken to a power (exponent)\n";
153 "\n#print (statement):\n" 154 " Prints a statement that can contain MADARA KaRL variables.\n" 155 " Variables are expanding to include their values where applicable.\n" 156 " For instance, 'var{.id}' would result in printing 'var0' if .id\n" 157 " was set to 0. The same statement would print 'variable' if .id\n" 158 " was set to 'iable'.\n";
160 calls_[
"#print_system_calls"] =
161 "\n#print_system_calls () or #print_system_call (system_call):\n" 162 " Prints help for all system calls or a specific system call.\n";
165 "\n#rand_double (floor = 0.0, ceiling = 1.0, update_srand = true):\n" 166 " Generates a random double from a uniform distribution.\n";
169 "\n#rand_int (floor = 0, ceiling = RAND_MAX, update_srand = true):\n" 170 " Generates a random integer from a uniform distribution.\n";
173 "\n#read_file (filename) or #read_file (filename, type):\n" 174 " Reads a file and returns its contents. Default is to determine\n" 175 " file type by filname extension. Explicit type can be a string\n" 176 " or an integer of the following values:\n" 182 "\n#set_clock (value) or #set_clock (variable, value):\n" 183 " Sets the system clock or a variable clock. The value should be\n" 184 " a non-zero integer (Lamport clock) and is used to determine which\n" 185 " variable values are rejected at the transport layer. Returns the\n" 186 " new clock value.\n";
189 "\n#set_fixed () or #fixed ():\n" 190 " Sets the output format for doubles to fixed format (std::fixed).\n";
192 calls_[
"#set_precision"] =
193 "\n#set_precision (value) or #precision (value):\n" 194 " Sets the precision that is used to convert doubles to strings.\n" 195 " This is a fixed precision (e.g., 5 for pi would be 3.14159).\n" 196 " Negative value resets to default precision.\n";
198 calls_[
"#set_scientific"] =
199 "\n#set_scientific () or #scientific ():\n" 200 " Sets the output format for doubles to scientific format\n" 201 " (std::scientific).\n";
205 " Returns the sine of a term (radians)\n";
209 " Returns the size of the variable or value.\n";
212 "\n#sleep (double time_to_sleep in s):\n" 213 " Sleeps for at least the specified time and returns time\n" 214 " spent sleeping in seconds.\n";
218 " Returns the square root of a value\n";
222 " Returns the tangent of a term (radians)\n";
225 "\n#to_buffer (value) or #buffer (value):\n" 226 " Converts the value to an unsigned char array.\n";
229 "\n#to_double (value) or #double (value):\n" 230 " Converts the value to a double.\n";
233 "\n#to_doubles (value) or #doubles (value):\n" 234 " Converts the value to an array of doubles.\n";
237 "\n#to_host_dirs (directory):\n" 238 " Returns the host appropriate directory structure, e.g.,.\n" 239 " files/file.txt to files\file.txt on Windows.\n";
242 "\n#to_integer (value) or #integer (value):\n" 243 " Converts the value to an integer.\n";
246 "\n#to_integers (value) or #integers (value):\n" 247 " Converts the value to an array of integers.\n";
250 "\n#to_string (value, delimiter) or #string (value, delimiter):\n" 251 " Converts the value to an ASCII string. Delimiter is an optional\n" 252 " string sequence that separates elements of an integer or double" 257 " Returns the integer type of the variable or value.\n" 258 " Supported types are:\n" 259 " UNINITIALIZED = 0\n" 263 " UNKNOWN_FILE_TYPE = 8\n" 266 " INTEGER_ARRAY = 64\n" 267 " DOUBLE_ARRAY = 128\n" 268 " IMAGE_JPEG = 256\n";
271 "\n#write_file (filename, value):\n" 272 " Writes the value to a file. Supports all MADARA types.\n" 291 "System call print_system_calls is printing help\n");
298 else if (
nodes_.size () == 0)
301 "System call print_system_calls is printing help\n");
303 for (SystemCallsHelp::const_iterator i =
calls_.begin ();
306 if (i->first !=
"#delete_var" && i->first !=
"#eval" &&
307 i->first !=
"#expand" && i->first !=
"#expand_env")
314 "KARL RUNTIME ERROR: System call print_system_calls takes either 0" 315 " or 1 arguments\n");
326 visitor.
visit (*
this);
329 #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_
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.