LRAUV  revA
LuaNode.h
Go to the documentation of this file.
1 
9 #ifndef LUANODE_H_
10 #define LUANODE_H_
11 
12 #include "LuaAPI.h"
14 #include "utils/FastMap.h"
15 #include "utils/FlexArray.h"
16 
17 class DataReader;
18 class DataValue;
19 class DataWriter;
20 
26 class LuaNode : public ScriptNode
27 {
28 public:
29 
31  virtual ~LuaNode();
32 
34  virtual bool hasChildNodes() const;
35 
37  virtual LuaNode* getNamedNode( const Str& nodeName );
38 
40  virtual LuaNode* newChildNode( const Str& nodeName );
41 
43  virtual LuaNode* newChildFunction( const Str& functionName,
44  const Str& functionBody, Logger& logger );
45 
48  virtual int getNodeCount( const Str& nodeName ) const;
49 
51  virtual LuaNode* getIndexedNode( unsigned int index );
52 
54  virtual LuaNode* getParentNode() const;
55 
57  virtual int getIndex() const
58  {
59  return index_;
60  }
61 
63  virtual const Str& getName() const
64  {
65  return name_;
66  }
67 
70  virtual bool readBool( bool& readTo ) const;
71 
74  virtual bool readDouble( double& readTo ) const;
75 
78  virtual bool readString( Str& readTo ) const;
79 
82  virtual DataValue* asNewDataValue();
83 
85  virtual bool execute( FlexArray<DataReader*>& inputs, FlexArray<SettingReader*>& settings,
86  FlexArray<DataWriter*>& outputs, FlexArray<const Unit*>& outUnits, Logger& logger );
87 
90  virtual bool execute( FlexArray<DataReader*>& inputs, FlexArray<SettingReader*>& settings,
91  bool& boolOutput, Logger& logger );
92 
94  virtual bool execute( Logger& logger );
95 
98  virtual Str toString() const;
99 
100 private:
101  // Note that the copy constructor below is private and not given a body.
102  // Any attempt to call it will return a compiler error.
103  LuaNode( const LuaNode& old ); // disallow copy constructor
104 
105  friend class LuaAPI;
106 
108  LuaNode();
109 
111  LuaNode( LuaNode* parentNode, int index );
112 
114  LuaNode( LuaNode* parentNode, const Str& name );
115 
117  bool open() const;
118 
120  void close() const;
121 
123  inline bool isRoot() const
124  {
125  return parentNode_ == NULL;
126  }
129 
131  int index_;
132 
135 
138 
141 };
142 
143 #endif /* LUANODE_H_ */
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
virtual LuaNode * newChildNode(const Str &nodeName)
Returns a new child node than can contain other nodes.
Definition: LuaNode.cpp:81
virtual Str toString() const
Returns a string representation of this node, with its ancestors, separated by "." characters...
Definition: LuaNode.cpp:322
Contains the LuaAPI class definition.
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: DataReader.h:30
bool isRoot() const
True if this is the root element.
Definition: LuaNode.h:123
virtual bool execute(FlexArray< DataReader * > &inputs, FlexArray< SettingReader * > &settings, FlexArray< DataWriter * > &outputs, FlexArray< const Unit * > &outUnits, Logger &logger)
Attempt to execute the function contained in this node.
Definition: LuaNode.cpp:276
Abstract base class for nodes in tree-like scripts.
Definition: ScriptNode.h:20
virtual LuaNode * getNamedNode(const Str &nodeName)
Returns the child node, by name, or NULL if none.
Definition: LuaNode.cpp:47
LuaNode * parentNode_
Parent node.
Definition: LuaNode.h:128
A wrapper for the lua programming language interface.
Definition: LuaAPI.h:42
void close() const
Close this node.
Definition: LuaNode.cpp:387
FastMap< const Str, LuaNode * > * childMap_
Map of named elements.
Definition: LuaNode.h:137
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
virtual bool hasChildNodes() const
Returns true if the node contains child nodes.
Definition: LuaNode.cpp:35
Contains the FlexArrayBase and FlexArray class declarations.
virtual DataValue * asNewDataValue()
If the node contains a dataValue, materialize such a dataValue Uses the Unit + value paradigm...
Definition: LuaNode.cpp:212
int index_
The index of this node.
Definition: LuaNode.h:131
LuaNode()
Private root node constructor, available to LuaAPI too.
Definition: LuaNode.cpp:336
bool open() const
Open this node.
Definition: LuaNode.cpp:363
Str name_
The name of this node.
Definition: LuaNode.h:134
Replacement for standard template class string.
Definition: Str.h:12
Contains the ScriptNode class definition.
virtual LuaNode * getParentNode() const
Returns the parent node, or NULL if this is the root.
Definition: LuaNode.cpp:161
Contains the FastMap class declaration.
FlexArray< LuaNode * > * childList_
Array of numbered elements.
Definition: LuaNode.h:140
virtual bool readBool(bool &readTo) const
Sets readTo to the value of the node, as a boolean Returns true if read success.
Definition: LuaNode.cpp:172
virtual bool readDouble(double &readTo) const
Sets readTo to the value of the node, as a double Returns true if read success.
Definition: LuaNode.cpp:186
virtual const Str & getName() const
Returns the name of the node, undefined if indexed.
Definition: LuaNode.h:63
virtual int getIndex() const
Returns the index of the node, -1 if named.
Definition: LuaNode.h:57
virtual bool readString(Str &readTo) const
Sets readTo to the value of the node, unsigned char string Returns true if read success.
Definition: LuaNode.cpp:199
virtual LuaNode * newChildFunction(const Str &functionName, const Str &functionBody, Logger &logger)
Returns a new child node that is a function.
Definition: LuaNode.cpp:96
virtual ~LuaNode()
Destructor.
Definition: LuaNode.cpp:15
Implements ScriptNode for the LuaAPI.
Definition: LuaNode.h:26
virtual LuaNode * getIndexedNode(unsigned int index)
Returns the indexed (array, or list-like) node at the zero-based index, or NULL if none...
Definition: LuaNode.cpp:132
virtual int getNodeCount(const Str &nodeName) const
Returns the number of indexed (array, or list-like) nodes Returns 0 is this is not a table...
Definition: LuaNode.cpp:118