MADARA  3.2.3
SystemCallToHostDirs.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
10 
11 
14  const ComponentNodes & nodes)
15  : SystemCallNode (context, nodes)
16 {
17 
18 }
19 
20 // Dtor
22 {
23 }
24 
27 {
29 }
30 
36 {
37  // user can always change a function, and we have no control over
38  // what it does. Consequently, a function node cannot be pruned out
39  // under any situation
40  can_change = true;
41 
43 
44  if (nodes_.size () == 1)
45  {
46  bool arg_can_change = false;
47  result = nodes_[0]->prune (arg_can_change);
48 
49  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
50  {
51  delete nodes_[0];
52  nodes_[0] = new LeafNode (*(this->logger_), result);
53  }
54  }
55  else
56  {
58  "madara::expression::SystemCallToHostDirs: "
59  "KARL COMPILE ERROR:"
60  "System call to_host_dirs requires 1 argument,"
61  "e.g., #to_host_dirs ('files/file.txt') will convert to files\file.txt"
62  " on Windows\n");
63 
64  throw KarlException ("madara::expression::SystemCallToHostDirs: "
65  "KARL COMPILE ERROR: "
66  "System call to_host_dirs requires 1 argument,"
67  "e.g., #to_host_dirs ('files/file.txt') will convert to files\file.txt"
68  " on Windows\n");
69  }
70 
71 
72  return result;
73 }
74 
80 {
81  knowledge::KnowledgeRecord return_value;
82 
83  if (nodes_.size () == 1)
84  {
85  std::string statement (nodes_[0]->evaluate (settings).to_string ());
86 
88  "madara::expression::SystemCallToHostDirs: "
89  "System call to_host_dirs is returning the proper directory structure "
90  "of %s.\n", statement.c_str ());
91 
94  }
95  else
96  {
98  "madara::expression::SystemCallToHostDirs: "
99  "KARL RUNTIME ERROR:"
100  "System call to_host_dirs requires 1 argument,"
101  "e.g., #to_host_dirs ('files/file.txt') will convert to files\file.txt"
102  " on Windows\n");
103 
104  throw KarlException ("madara::expression::SystemCallToHostDirs: "
105  "KARL RUNTIME ERROR: "
106  "System call to_host_dirs requires 1 argument,"
107  "e.g., #to_host_dirs ('files/file.txt') will convert to files\file.txt"
108  " on Windows\n");
109  }
110 
111  return return_value;
112 }
113 
114 // accept a visitor
115 void
117  madara::expression::Visitor &visitor) const
118 {
119  visitor.visit (*this);
120 }
121 
122 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:97
This class stores variables and their values for use by any entity needing state information in a thr...
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
SystemCallToHostDirs(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
static struct madara::knowledge::tags::string_t string
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
std::string clean_dir_name(const std::string &source)
Substitutes the appropriate directory delimiter, which may help with portability between operating sy...
Definition: Utility.cpp:457
Interface for a MADARA system call.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.