MADARA  3.4.1
SystemCallExpandEnv.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
9 
12  : SystemCallNode(context, nodes)
13 {
14 }
15 
16 // Dtor
18 
21 {
22  return madara::knowledge::KnowledgeRecord(nodes_.size());
23 }
24 
30 {
31  // user can always change a function, and we have no control over
32  // what it does. Consequently, a function node cannot be pruned out
33  // under any situation
34  can_change = true;
35 
37 
38  if (nodes_.size() == 1)
39  {
40  bool arg_can_change = false;
41  result = nodes_[0]->prune(arg_can_change);
42 
43  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
44  {
45  delete nodes_[0];
46  nodes_[0] = new LeafNode(*(this->logger_), result);
47  }
48  }
49  else
50  {
52  "madara::expression::SystemCallExpandEnv: "
53  "KARL COMPILE ERROR:"
54  "System call expand_env requires 1 argument,"
55  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
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 
64  return result;
65 }
66 
72 {
73  knowledge::KnowledgeRecord return_value;
74 
75  if (nodes_.size() == 1)
76  {
77  std::string statement(nodes_[0]->evaluate(settings).to_string());
78 
80  "madara::expression::SystemCallExpandEnv: "
81  "System call expand_var is returning the expansion "
82  "of %s.\n",
83  statement.c_str());
84 
86  }
87  else
88  {
90  "madara::expression::SystemCallExpandEnv: "
91  "KARL RUNTIME ERROR:"
92  "System call expand_env requires 1 argument,"
93  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
94 
96  "madara::expression::SystemCallExpandEnv: "
97  "KARL RUNTIME ERROR: "
98  "System call expand_env requires 1 argument,"
99  "e.g., #expand_env ('path=$(MADARA_ROOT')\n");
100  }
101 
102  return return_value;
103 }
104 
105 // accept a visitor
107  madara::expression::Visitor& visitor) const
108 {
109  visitor.visit(*this);
110 }
111 
112 #endif // _MADARA_NO_KARL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
SystemCallExpandEnv(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
Interface for a MADARA system call.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
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
constexpr string_t string
std::string expand_envs(const std::string &source)
Expand any environment variables in a string.
Definition: Utility.cpp:357