2 #ifndef _MADARA_NO_KARL_
44 if (nodes_.size() == 1)
46 bool arg_can_change =
false;
47 result = nodes_[0]->prune(arg_can_change);
49 if (!arg_can_change &&
dynamic_cast<LeafNode*
>(nodes_[0]) == 0)
52 nodes_[0] =
new LeafNode(*(this->logger_), result);
55 else if (nodes_.size() != 0)
58 "madara::expression::SystemCallPrintSystemCalls: "
60 "System call print_system_calls takes either 0"
64 "madara::expression::SystemCallPrintSystemCalls: "
65 "KARL COMPILE ERROR: "
66 "System call print_system_calls takes either 0"
71 if (calls_.size() == 0)
73 calls_[
"#clear_variable"] =
74 "\n#clear_var (var) or #clear_variable (var):\n"
75 " Clears the variable var in the knowledge base. This is\n"
76 " the preferred way to delete variables. It masks the variable\n"
77 " from printouts and save_modifieds but leaves a phantom record\n"
78 " in the knowledge base to safely reference in VariableReference,\n"
79 " CompiledExpression, etc.\n";
81 calls_[
"#cos"] =
"\n#cos (var):\n"
82 " Returns the cosine of a term (radians)\n";
84 calls_[
"#delete_variable"] =
85 "\n#delete_var (var) or #delete_variable (var):\n"
86 " Deletes a variable named var from the knowledge base. \n"
87 " This is an extremely unsafe operation that must only\n"
88 " be used if the variable is never used in compiled\n"
89 " expressions or variable references (including container\n"
90 " classes such as Integer, Double, Vector, etc.)\n";
93 "\n#eval (expression) or #evaluate (expression):\n"
94 " Evaluates the KaRL expression and returns a result. Works "
96 " to the KnowledgeBase::evaluate function except this function\n"
97 " inherits the KnowledgeUpdateSettings from the eval call.\n";
100 "\n#eval (expression) or #evaluate (expression):\n"
101 " Evaluates the KaRL expression and returns a result. Works "
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";
110 calls_[
"#expand_env"] =
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";
115 calls_[
"#expand_envs"] =
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";
124 calls_[
"#fragment"] =
125 "\n#fragment (arg, first, last):\n"
126 " Returns a fragment of the arg, startin at first byte and extending\n"
129 calls_[
"#get_clock"] =
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";
134 calls_[
"#get_time"] =
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";
146 calls_[
"#log_level"] =
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";
159 calls_[
"#pow"] =
"\n#pow (base, power):\n"
160 " Returns the base taken to a power (exponent)\n";
163 "\n#print (statement):\n"
164 " Prints a statement that can contain MADARA KaRL variables.\n"
165 " Variables are expanding to include their values where applicable.\n"
166 " For instance, 'var{.id}' would result in printing 'var0' if .id\n"
167 " was set to 0. The same statement would print 'variable' if .id\n"
168 " was set to 'iable'.\n";
170 calls_[
"#print_system_calls"] =
171 "\n#print_system_calls () or #print_system_call (system_call):\n"
172 " Prints help for all system calls or a specific system call.\n";
174 calls_[
"#rand_double"] =
175 "\n#rand_double (floor = 0.0, ceiling = 1.0, update_srand = true):\n"
176 " Generates a random double from a uniform distribution.\n";
178 calls_[
"#rand_int"] =
179 "\n#rand_int (floor = 0, ceiling = RAND_MAX, update_srand = true):\n"
180 " Generates a random integer from a uniform distribution.\n";
182 calls_[
"#read_file"] =
183 "\n#read_file (filename) or #read_file (filename, type):\n"
184 " Reads a file and returns its contents. Default is to determine\n"
185 " file type by filname extension. Explicit type can be a string\n"
186 " or an integer of the following values:\n"
191 calls_[
"#set_clock"] =
192 "\n#set_clock (value) or #set_clock (variable, value):\n"
193 " Sets the system clock or a variable clock. The value should be\n"
194 " a non-zero integer (Lamport clock) and is used to determine which\n"
195 " variable values are rejected at the transport layer. Returns the\n"
196 " new clock value.\n";
198 calls_[
"#set_fixed"] =
199 "\n#set_fixed () or #fixed ():\n"
200 " Sets the output format for doubles to fixed format (std::fixed).\n";
202 calls_[
"#set_precision"] =
203 "\n#set_precision (value) or #precision (value):\n"
204 " Sets the precision that is used to convert doubles to strings.\n"
205 " This is a fixed precision (e.g., 5 for pi would be 3.14159).\n"
206 " Negative value resets to default precision.\n";
208 calls_[
"#set_scientific"] =
209 "\n#set_scientific () or #scientific ():\n"
210 " Sets the output format for doubles to scientific format\n"
211 " (std::scientific).\n";
213 calls_[
"#sin"] =
"\n#sin (var):\n"
214 " Returns the sine of a term (radians)\n";
216 calls_[
"#size"] =
"\n#size (value):\n"
217 " Returns the size of the variable or value.\n";
220 "\n#sleep (double time_to_sleep in s):\n"
221 " Sleeps for at least the specified time and returns time\n"
222 " spent sleeping in seconds.\n";
224 calls_[
"#sqrt"] =
"\n#sqrt (value):\n"
225 " Returns the square root of a value\n";
227 calls_[
"#tan"] =
"\n#tan (value):\n"
228 " Returns the tangent of a term (radians)\n";
230 calls_[
"#to_buffer"] =
"\n#to_buffer (value) or #buffer (value):\n"
231 " Converts the value to an unsigned char array.\n";
233 calls_[
"#to_double"] =
"\n#to_double (value) or #double (value):\n"
234 " Converts the value to a double.\n";
236 calls_[
"#to_doubles"] =
"\n#to_doubles (value) or #doubles (value):\n"
237 " Converts the value to an array of doubles.\n";
239 calls_[
"#to_host_dirs"] =
240 "\n#to_host_dirs (directory):\n"
241 " Returns the host appropriate directory structure, e.g.,.\n"
242 " files/file.txt to files\file.txt on Windows.\n";
244 calls_[
"#to_integer"] =
"\n#to_integer (value) or #integer (value):\n"
245 " Converts the value to an integer.\n";
247 calls_[
"#to_integers"] =
"\n#to_integers (value) or #integers (value):\n"
248 " Converts the value to an array of integers.\n";
250 calls_[
"#to_string"] =
251 "\n#to_string (value, delimiter) or #string (value, delimiter):\n"
252 " Converts the value to an ASCII string. Delimiter is an optional\n"
253 " string sequence that separates elements of an integer or double"
256 calls_[
"#type"] =
"\n#type (value):\n"
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";
270 calls_[
"#write_file"] =
271 "\n#write_file (filename, value):\n"
272 " Writes the value to a file. Supports all MADARA types.\n"
287 if (nodes_.size() == 1)
290 "madara::expression::SystemCallPrintSystemCalls: "
291 "System call print_system_calls is printing help\n");
293 context_.print(calls_[nodes_[0]->evaluate(settings).to_string()], 0);
297 else if (nodes_.size() == 0)
300 "madara::expression::SystemCallPrintSystemCalls: "
301 "System call print_system_calls is printing help\n");
303 for (SystemCallsHelp::const_iterator i = calls_.begin(); i != calls_.end();
306 if (i->first !=
"#delete_var" && i->first !=
"#eval" &&
307 i->first !=
"#expand" && i->first !=
"#expand_env")
314 "madara::expression::SystemCallPrintSystemCalls: "
315 "KARL RUNTIME ERROR:"
316 "System call print_system_calls takes either 0"
317 " or 1 arguments\n");
320 "madara::expression::SystemCallPrintSystemCalls: "
321 "KARL RUNTIME ERROR: "
322 "System call print_system_calls takes either 0"
323 " or 1 arguments\n");
333 visitor.
visit(*
this);
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Interface for a MADARA system call.
virtual ~SystemCallPrintSystemCalls(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
SystemCallPrintSystemCalls(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
static SystemCallsHelp calls_
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
Abstract base class for all visitors to all classes that derive from ComponentNode.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
std::map< std::string, std::string > SystemCallsHelp