|
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. | |
| void | resetReadCount () const |
| Reset the read count back to zero. | |
| 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 | recursFindPTreeNodesNamed (const std::string &name, std::vector< Node * > &matching_nodes) |
| Recursively find all nodes that have a given name. | |
| void | recursFindPTreeNodesNamed (const std::string &name, std::vector< const Node * > &matching_nodes) const |
| Recursively find all nodes that have a given name. | |
| void | recurseVisitLeaves (std::function< void(const Node *)> callback) const |
| Apply the given callback to all leaf nodes. | |
| void | recursePrint (std::ostream &o, uint32_t indent=0, bool print_user_data=true) const |
| Recursively print. | |
| void | printUserData (std::ostream &o, uint32_t indent=0) const |
| Pretty-print all user data for this node, if any. | |
| void | appendTree (const Node *ot) |
| Appends a tree as a child of this node. | |
| template<typename T > | |
| void | setUserData (const std::string &name, const T &user_data) |
| Set any named user data (std::any) | |
| template<typename T > | |
| void | setUserData (const std::string &name, T &&user_data) |
| Set any named user data (std::any) | |
| template<typename T > | |
| const T & | getUserData (const std::string &name) const |
| Get any named user data (std::any_cast) | |
| template<typename T > | |
| T & | getUserData (const std::string &name) |
| Get any named user data (std::any_cast) | |
| template<typename T > | |
| const T * | tryGetUserData (const std::string &name, bool must_exist=false) const |
| Try to get any named user data (std::any_cast) | |
| template<typename T > | |
| T * | tryGetUserData (const std::string &name, bool must_exist=false) |
| Try to get any named user data (std::any_cast) | |
| void | recurseGetAllNodeExtensions (std::map< const Node *, std::map< std::string, const TreeNode::ExtensionsBase * > > &map) const |
| Get a mapping from Nodes to their extensions recursively. | |
| std::set< std::string > | getUserDataKeys () const |
| Get all user data keys (names). | |
| bool | clearUserData (const std::string &name) |
| Clear named user data. Returns true if removed, false if not found. | |
| size_t | clearUserData () |
| Clear all user data. Returns the number of elements removed. | |
| 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 61 of file ParameterTree.hpp.
| std::vector<std::unique_ptr<Node> > sparta::ParameterTree::Node::ChildVector |
Vector of children owned by this node.
Definition at line 68 of file ParameterTree.hpp.
|
inline |
Definition at line 159 of file ParameterTree.hpp.
|
inline |
Value-less constructor.
Definition at line 172 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 185 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 578 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 849 of file ParameterTree.hpp.

|
inline |
Clear all user data. Returns the number of elements removed.
Definition at line 977 of file ParameterTree.hpp.
|
inline |
Clear named user data. Returns true if removed, false if not found.
Definition at line 965 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 476 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 237 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 390 of file ParameterTree.hpp.

|
inline |
getAs template instance for string types (e.g. char[], const char*, std::string)
Definition at line 398 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 449 of file ParameterTree.hpp.

|
inline |
Gets vector of pointers to children of this node.
Definition at line 730 of file ParameterTree.hpp.
|
inline |
Gets vector of pointers to children of this node.
Definition at line 741 of file ParameterTree.hpp.
|
inline |
Get most recent child added.
Definition at line 1033 of file ParameterTree.hpp.
|
inline |
Get end of child match iterator (past oldest child added)
Definition at line 1038 of file ParameterTree.hpp.
|
inline |
Gets the name of this node.
Definition at line 245 of file ParameterTree.hpp.
|
inline |
Gets the origin associated with the value at this node.
Definition at line 372 of file ParameterTree.hpp.

|
inline |
Gets the ParameterTree object that owns this node.
Definition at line 284 of file ParameterTree.hpp.

|
inline |
Gets the ParameterTree object that owns this node.
Definition at line 291 of file ParameterTree.hpp.

|
inline |
Gets the parent of this node.
Definition at line 250 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 255 of file ParameterTree.hpp.
|
inline |
Gets the path to this node including the root node.
Definition at line 298 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 517 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 343 of file ParameterTree.hpp.
|
inline |
Returns the number of times this node has been flagged as required.
Definition at line 723 of file ParameterTree.hpp.
|
inline |
Gets the parent of this node.
Definition at line 260 of file ParameterTree.hpp.

|
inline |
Gets the parent of this node.
Definition at line 272 of file ParameterTree.hpp.

|
inline |
Get any named user data (std::any_cast)
Definition at line 897 of file ParameterTree.hpp.

|
inline |
Get any named user data (std::any_cast)
Definition at line 888 of file ParameterTree.hpp.

|
inline |
Get all user data keys (names).
Definition at line 954 of file ParameterTree.hpp.
|
inline |
Gets the value of this object as a string.
Definition at line 352 of file ParameterTree.hpp.

|
inline |
Does this node have a value written to it which can be accessed through:
Definition at line 614 of file ParameterTree.hpp.
|
inline |
Increment the read count of this node.
Definition at line 328 of file ParameterTree.hpp.
|
inline |
Increment the required count.
Definition at line 642 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 709 of file ParameterTree.hpp.

|
inline |
Is this a root node.
Definition at line 321 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 436 of file ParameterTree.hpp.

|
inline |
Get value as a string.
Definition at line 405 of file ParameterTree.hpp.
|
inline |
Get value as a specific type through getAs.
| T | Type to retrieve content as |
Definition at line 414 of file ParameterTree.hpp.

Parent-preserving deep-copy assignment operator.
Definition at line 218 of file ParameterTree.hpp.
|
inline |
String value assignment operator.
Definition at line 699 of file ParameterTree.hpp.

|
inline |
Equality test. Attempts to lexically cast underlying string to requested data-type.
Definition at line 423 of file ParameterTree.hpp.

|
inline |
Definition at line 603 of file ParameterTree.hpp.
|
inline |
Gets a child of this node by its name.
Definition at line 596 of file ParameterTree.hpp.

|
inline |
Gets the value of this object as a string.
Definition at line 363 of file ParameterTree.hpp.

|
inline |
Pretty-print all user data for this node, if any.
Definition at line 821 of file ParameterTree.hpp.

|
inline |
Get a mapping from Nodes to their extensions recursively.
Definition at line 937 of file ParameterTree.hpp.

|
inline |
Recursively print.
Definition at line 800 of file ParameterTree.hpp.

|
inline |
Apply the given callback to all leaf nodes.
Definition at line 788 of file ParameterTree.hpp.
|
inline |
Recursively find all nodes that have a given name.
Definition at line 770 of file ParameterTree.hpp.

|
inline |
Recursively find all nodes that have a given name.
Definition at line 752 of file ParameterTree.hpp.

|
inline |
Release this node and its children from the tree.
Definition at line 662 of file ParameterTree.hpp.
|
inline |
Reset the read count back to zero.
Definition at line 335 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 679 of file ParameterTree.hpp.

|
inline |
Set any named user data (std::any)
Definition at line 867 of file ParameterTree.hpp.
|
inline |
Set any named user data (std::any)
Definition at line 878 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 625 of file ParameterTree.hpp.
|
inline |
Try to get any named user data (std::any_cast)
Definition at line 922 of file ParameterTree.hpp.

|
inline |
Try to get any named user data (std::any_cast)
Definition at line 906 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 650 of file ParameterTree.hpp.
|
friend |
Definition at line 1028 of file ParameterTree.hpp.