The Sparta Modeling Framework
|
Node containing a Parameter and value to apply. Can be used to describes a value extracted from the tree when using get or tryGet. This is a copy of the value and is not in any way synchronized with the tree. More...
#include <ParameterTree.hpp>
Classes | |
class | MatchIterator |
Public Types | |
typedef std::vector< std::unique_ptr< Node > > | ChildVector |
Vector of children owned by this node. | |
Public Member Functions | |
Node ()=delete | |
Not default-constructable. | |
Node (Node *parent, const std::string &name, const std::string &value, const std::string &origin) | |
Node (Node *parent, const std::string &name) | |
Value-less constructor. | |
Node (Node *parent, ParameterTree *tree) | |
Root node constructor. Constructs node pointing to a new tree having no name. Normal nodes to not have tree pointers (getOwner) | |
Node (Node *parent, const Node &n) | |
Deep-Copy constructor. | |
Node & | operator= (const Node &n) |
Parent-preserving deep-copy assignment operator. | |
void | dump (std::ostream &o) const |
Dumps the content of this node to an ostream on a single line. Does not recurs into children. | |
const std::string & | getName () const |
Gets the name of this node. | |
Node * | getParent () |
Gets the parent of this node. | |
Node const * | getParent () const |
Gets the parent of this node. | |
Node * | getRoot () |
Gets the parent of this node. | |
Node const * | getRoot () const |
Gets the parent of this node. | |
ParameterTree * | getOwner () |
Gets the ParameterTree object that owns this node. | |
const ParameterTree * | getOwner () const |
Gets the ParameterTree object that owns this node. | |
std::string | getPath () const |
Gets the path to this node including the root node. | |
bool | isRoot () const |
Is this a root node. | |
void | incrementReadCount () const |
Increment the read count of this node. | |
uint32_t | getReadCount () const |
Gets the number of times this node has been accessed to be read (i.e. with get/tryGet) | |
const std::string & | getValue () const |
Gets the value of this object as a string. | |
const std::string & | peekValue () const |
Gets the value of this object as a string. | |
const std::string & | getOrigin () const |
Gets the origin associated with the value at this node. | |
template<typename T , typename = typename std::enable_if<!std::is_convertible<T, std::string>::value>::type> | |
T | getAs () const |
Gets the value in this object. | |
template<typename T , typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type> | |
const std::string & | getAs () const |
getAs template instance for string types (e.g. char[], const char*, std::string) | |
operator std::string () const | |
Get value as a string. | |
template<typename T > | |
operator T () const | |
Get value as a specific type through getAs. | |
template<typename T > | |
bool | operator== (const T &rhp) const |
Equality test. Attempts to lexically cast underlying string to requested data-type. | |
Node * | getChild (const std::string &name) const |
Gets the most recently created child of this node by a concrete child name. | |
Node * | create (const std::string &path, bool required) |
Get a child for setting a parameter, creating it if needed. | |
Node * | getPriorityChildMatch (const std::string &name) const |
Attempts to get an immediate child with an exact match for a given name or pattern string. There is no pattern matching in this method. Patterns are treated as raw strings. | |
Node * | addChild (const std::string &name, bool required) |
Node & | operator[] (const std::string &name) const |
Gets a child of this node by its name. | |
Node & | operator[] (const char *name) const |
bool | hasValue () const |
Does this node have a value written to it which can be accessed through: | |
void | setValue (const std::string &val, bool required=true, const std::string &origin="") |
Set a value on this node directly. | |
void | incRequired () |
Increment the required count. | |
void | unrequire () |
Clear the required count. This is necessary if a parameter is flagged as deprecated or removed in a configuration file. This affects this node only. | |
std::unique_ptr< Node > | release () |
Release this node and its children from the tree. | |
bool | set (const std::string &path, const std::string &val, bool required, const std::string &origin="") |
Set the string value of a child of this node. Note that this may not affect this node directly because of the way pattern nodes work. | |
const std::string & | operator= (const std::string &val) |
String value assignment operator. | |
bool | isRequired () const |
Return true if this parameter node is required to exist by the client by 1 or more "set"-ers using this object. | |
uint32_t | getRequiredCount () const |
Returns the number of times this node has been flagged as required. | |
std::vector< Node * > | getChildren () |
Gets vector of pointers to children of this node. | |
std::vector< const Node * > | getChildren () const |
Gets vector of pointers to children of this node. | |
void | recursePrint (std::ostream &o, uint32_t indent=0) const |
Recursively print. | |
void | appendTree (const Node *ot) |
Appends a tree as a child of this node. | |
MatchIterator | getMatcherBegin () const |
Get most recent child added. | |
MatchIterator | getMatcherEnd () const |
Get end of child match iterator (past oldest child added) | |
Static Public Member Functions | |
static bool | matches (const std::string &pattern, const std::string &other) |
Does a string, name, interpreted as a sparta TreeNode pattern, match another string interpreted as a concrete (no-wildcards) node name. | |
Friends | |
class | MatchIterator |
Node containing a Parameter and value to apply. Can be used to describes a value extracted from the tree when using get or tryGet. This is a copy of the value and is not in any way synchronized with the tree.
It is illegal to try and read the value if there is no value set (see hasValue) - An exception will be thrown.
Can be written as well
Contains a string that can be lexically cast using the getAs<T> method. Supports all types supported by sparta::lexicalCast
Definition at line 56 of file ParameterTree.hpp.
typedef std::vector<std::unique_ptr<Node> > sparta::ParameterTree::Node::ChildVector |
Vector of children owned by this node.
Definition at line 63 of file ParameterTree.hpp.
|
inline |
Definition at line 90 of file ParameterTree.hpp.
|
inline |
Value-less constructor.
Definition at line 103 of file ParameterTree.hpp.
|
inline |
Root node constructor. Constructs node pointing to a new tree having no name. Normal nodes to not have tree pointers (getOwner)
Definition at line 116 of file ParameterTree.hpp.
Deep-Copy constructor.
Definition at line 129 of file ParameterTree.hpp.
|
inline |
\Create a child of this node at the end of the list (meaning it is the most recent)
Definition at line 502 of file ParameterTree.hpp.
|
inline |
Appends a tree as a child of this node.
ot | Other tree to append. If ot is a root node (isRoot), it is merged over the current node, adding or replacing all its children. Otherwise, ot is added as a child of this node. To add all children of a particular node without adding the parent, those children must currently be iterated and separately appended to node through appendTree calls. However, since only leaf nodes are expected to have actual parameter values, it is typically safe to simply call appendTree with a node that is not a leaf when its children (subtrees) are the only nodes of interest |
Definition at line 703 of file ParameterTree.hpp.
|
inline |
Get a child for setting a parameter, creating it if needed.
path | Path of immediate child to get/create. If there is a child by this path which was not created before any wildcard nodes matching name, then the existing node will be returned. Otherwise, a new child will be created. |
required | Is this node required to exist in the tree. This is a deferred value |
Definition at line 400 of file ParameterTree.hpp.
|
inline |
Dumps the content of this node to an ostream on a single line. Does not recurs into children.
o | Ostream to write content to |
Definition at line 168 of file ParameterTree.hpp.
|
inline |
Gets the value in this object.
Template | parameter |
Example
* val.getAs<std::string>() * val.getAs<uint32_t>() *
Definition at line 314 of file ParameterTree.hpp.
|
inline |
getAs template instance for string types (e.g. char[], const char*, std::string)
Definition at line 322 of file ParameterTree.hpp.
|
inline |
Gets the most recently created child of this node by a concrete child name.
name | Name to get a child with. Must not be a pattern. Pattern-based nodes must be added and cannot be searched for. Searching based on a pattern would be too complicated |
Definition at line 373 of file ParameterTree.hpp.
|
inline |
Gets vector of pointers to children of this node.
Definition at line 654 of file ParameterTree.hpp.
|
inline |
Gets vector of pointers to children of this node.
Definition at line 665 of file ParameterTree.hpp.
|
inline |
Get most recent child added.
Definition at line 765 of file ParameterTree.hpp.
|
inline |
Get end of child match iterator (past oldest child added)
Definition at line 770 of file ParameterTree.hpp.
|
inline |
Gets the name of this node.
Definition at line 176 of file ParameterTree.hpp.
|
inline |
Gets the origin associated with the value at this node.
Definition at line 296 of file ParameterTree.hpp.
|
inline |
Gets the ParameterTree object that owns this node.
Definition at line 215 of file ParameterTree.hpp.
|
inline |
Gets the ParameterTree object that owns this node.
Definition at line 222 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 181 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 186 of file ParameterTree.hpp.
|
inline |
Gets the path to this node including the root node.
Definition at line 229 of file ParameterTree.hpp.
|
inline |
Attempts to get an immediate child with an exact match for a given name or pattern string. There is no pattern matching in this method. Patterns are treated as raw strings.
This searches children in reverse order (priority order) for a match. This will find the most recently created child which matches the pattern
Definition at line 441 of file ParameterTree.hpp.
|
inline |
Gets the number of times this node has been accessed to be read (i.e. with get/tryGet)
Definition at line 267 of file ParameterTree.hpp.
|
inline |
Returns the number of times this node has been flagged as required.
Definition at line 647 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 191 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 203 of file ParameterTree.hpp.
|
inline |
Gets the value of this object as a string.
Definition at line 276 of file ParameterTree.hpp.
|
inline |
Does this node have a value written to it which can be accessed through:
Definition at line 538 of file ParameterTree.hpp.
|
inline |
Increment the read count of this node.
Definition at line 259 of file ParameterTree.hpp.
|
inline |
Increment the required count.
Definition at line 566 of file ParameterTree.hpp.
|
inline |
Return true if this parameter node is required to exist by the client by 1 or more "set"-ers using this object.
Definition at line 633 of file ParameterTree.hpp.
|
inline |
Is this a root node.
Definition at line 252 of file ParameterTree.hpp.
|
inlinestatic |
Does a string, name, interpreted as a sparta TreeNode pattern, match another string interpreted as a concrete (no-wildcards) node name.
pattern | String pattern to attempt to match with. This is a sparta::TreeNode single location pattern (no '.' characters) |
other | String to attempt to match. Interpreted as a plain string, regardless of content. \erturn true if pattern matches other, false if not/ |
Definition at line 360 of file ParameterTree.hpp.
|
inline |
Get value as a string.
Definition at line 329 of file ParameterTree.hpp.
|
inline |
Get value as a specific type through getAs.
T | Type to retrieve content as |
Definition at line 338 of file ParameterTree.hpp.
Parent-preserving deep-copy assignment operator.
Definition at line 149 of file ParameterTree.hpp.
|
inline |
String value assignment operator.
Definition at line 623 of file ParameterTree.hpp.
|
inline |
Equality test. Attempts to lexically cast underlying string to requested data-type.
Definition at line 347 of file ParameterTree.hpp.
|
inline |
Definition at line 527 of file ParameterTree.hpp.
|
inline |
Gets a child of this node by its name.
Definition at line 520 of file ParameterTree.hpp.
|
inline |
Gets the value of this object as a string.
Definition at line 287 of file ParameterTree.hpp.
|
inline |
Recursively print.
Definition at line 676 of file ParameterTree.hpp.
|
inline |
Release this node and its children from the tree.
Definition at line 586 of file ParameterTree.hpp.
|
inline |
Set the string value of a child of this node. Note that this may not affect this node directly because of the way pattern nodes work.
path | Path to child. To set this node, use path="" |
val | Value to assign |
required | Is this parameter location required? |
origin | Origin of the value (e.g. "foo.yaml line:50 col:23") |
Definition at line 603 of file ParameterTree.hpp.
|
inline |
Set a value on this node directly.
val | Value to assign. |
required | Must the parameter identified by this node be consumed (may be overwritten later)? |
origin | Origin of the value (e.g. "foo.yaml line:2 col:35") |
Definition at line 549 of file ParameterTree.hpp.
|
inline |
Clear the required count. This is necessary if a parameter is flagged as deprecated or removed in a configuration file. This affects this node only.
Definition at line 574 of file ParameterTree.hpp.
|
friend |
Definition at line 760 of file ParameterTree.hpp.