MADARA  3.2.3
SystemCallExpandEnv.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::SystemCallExpandEnv: "
59  "KARL COMPILE ERROR:"
60  "System call expand_env requires 1 argument,"
61  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
62 
63  throw KarlException ("madara::expression::SystemCallExpandEnv: "
64  "KARL COMPILE ERROR: "
65  "System call expand_env requires 1 argument,"
66  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
67  }
68 
69 
70  return result;
71 }
72 
78 {
79  knowledge::KnowledgeRecord return_value;
80 
81  if (nodes_.size () == 1)
82  {
83  std::string statement (nodes_[0]->evaluate (settings).to_string ());
84 
86  "madara::expression::SystemCallExpandEnv: "
87  "System call expand_var is returning the expansion "
88  "of %s.\n", statement.c_str ());
89 
91  }
92  else
93  {
95  "madara::expression::SystemCallExpandEnv: "
96  "KARL RUNTIME ERROR:"
97  "System call expand_env requires 1 argument,"
98  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
99 
100  throw KarlException ("madara::expression::SystemCallExpandEnv: "
101  "KARL RUNTIME ERROR: "
102  "System call expand_env requires 1 argument,"
103  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
104  }
105 
106  return return_value;
107 }
108 
109 // accept a visitor
110 void
112  madara::expression::Visitor &visitor) const
113 {
114  visitor.visit (*this);
115 }
116 
117 #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.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
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...
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
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
SystemCallExpandEnv(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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
Interface for a MADARA system call.
std::string expand_envs(const std::string &source)
Expand any environment variables in a string.
Definition: Utility.cpp:421
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual ~SystemCallExpandEnv(void)
Destructor.