|
Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
|
#include <DBNode.h>
Public Types | |
| using | Value = std::variant< BlockName, int, double, bool, std::shared_ptr< DBNode >, std::vector< std::shared_ptr< DBNode > > > |
| Variant type used to store values in the tree. | |
Public Member Functions | |
| DBNode () | |
| Default constructor. | |
| template<typename... Keys> | |
| Value | get (Keys &&... keys) const |
| Retrieves a value from the node using a sequence of keys. | |
| std::vector< BlockName > | get_keys () |
| Returns all the keys stored at the current node level. | |
| template<typename T , typename Key , typename... Rest> | |
| void | set (T value, Key &&key, Rest &&... rest) |
| Sets a value in the node using a sequence of keys. | |
| std::map< BlockName, Value > | getGroup (const std::vector< BlockName > &keys) const |
| Retrieves a whole sub-tree as a map from a path of keys. | |
| void | setGroup (const std::vector< BlockName > &keys, const std::map< BlockName, Value > &groupData) |
| Sets the content of a whole sub-tree from a map of values. | |
| void | printJSON (int level=0) const |
| Prints the node in JSON format to std::cout. | |
| void | printJSONToStream (std::ostream &os, int level=0) const |
| Prints the node in JSON format to a given output stream. | |
| void | printYAMLToStream (std::ostream &os, int level=0) const |
| Prints the node in YAML format to a given output stream. | |
| void | printYAML (int level=0) const |
| Prints the node in YAML format to std::cout. | |
| bool | contains (const BlockName &key) const |
| Checks whether the node contains a direct child with the given key. | |
| int | countChildren () const |
| Returns the number of direct children of this node. | |
| bool | isList () const |
| Returns true if this node represents a "list" node. | |
| using DBNode::Value = std::variant<BlockName, int, double, bool, std::shared_ptr<DBNode>, std::vector<std::shared_ptr<DBNode> >> |
|
default |
Default constructor.
Constructs an empty node with no children.
| bool DBNode::contains | ( | const BlockName & | key | ) | const |
Checks whether the node contains a direct child with the given key.
This does not inspect nested children; it only checks the current level of the map.
| key | Key to look up. |
key exists in this node, false otherwise. Definition at line 263 of file DBNode.cpp.
| int DBNode::countChildren | ( | ) | const |
Returns the number of direct children of this node.
Equivalent to data_.size().
Definition at line 270 of file DBNode.cpp.
| Value DBNode::get | ( | Keys &&... | keys | ) | const |
Retrieves a value from the node using a sequence of keys.
This is a generic hierarchical accessor:
The provided keys are interpreted as a path: at each step, the corresponding child must be a nested DBNode (stored in a std::shared_ptr<DBNode>) until the final element is reached.
| Keys | Types of the keys (typically BlockName, std::string, const char*). |
| keys | Path of keys leading to the desired value. |
| std::runtime_error | If the path does not exist or the structure along the way is not compatible (e.g. non-DBNode where a DBNode is expected). |
| std::vector< BlockName > DBNode::get_keys | ( | ) |
Returns all the keys stored at the current node level.
This does not recurse into children; it only returns the immediate keys present in the underlying map.
Definition at line 5 of file DBNode.cpp.
| std::map< BlockName, DBNode::Value > DBNode::getGroup | ( | const std::vector< BlockName > & | keys | ) | const |
Retrieves a whole sub-tree as a map from a path of keys.
The keys vector is interpreted as a path of nested nodes. At the end of the path, the underlying map<BlockName,Value> is returned.
| keys | Sequence of keys describing the path to the group node. |
| std::runtime_error | If the path does not exist or does not terminate on a DBNode. |
Definition at line 13 of file DBNode.cpp.
| bool DBNode::isList | ( | ) | const |
Returns true if this node represents a "list" node.
A node is considered a list node if its first stored value is a std::vector<std::shared_ptr<DBNode>>. This is a heuristic used internally to differentiate arrays from objects during printing.
| void DBNode::printJSON | ( | int | level = 0 | ) | const |
Prints the node in JSON format to std::cout.
This produces a pretty-printed JSON-like representation of the current node and all its descendants.
| level | Indentation level (used internally for recursion). |
Definition at line 55 of file DBNode.cpp.
| void DBNode::printJSONToStream | ( | std::ostream & | os, |
| int | level = 0 |
||
| ) | const |
Prints the node in JSON format to a given output stream.
| os | Output stream. |
| level | Indentation level (used internally for recursion). |
Definition at line 105 of file DBNode.cpp.
| void DBNode::printYAML | ( | int | level = 0 | ) | const |
Prints the node in YAML format to std::cout.
| level | Indentation level (used internally for recursion). |
Definition at line 148 of file DBNode.cpp.
| void DBNode::printYAMLToStream | ( | std::ostream & | os, |
| int | level = 0 |
||
| ) | const |
Prints the node in YAML format to a given output stream.
Lists and nested objects are rendered using standard YAML indentation and list syntax.
| os | Output stream. |
| level | Indentation level (used internally for recursion). |
Definition at line 286 of file DBNode.cpp.
| void DBNode::set | ( | T | value, |
| Key && | key, | ||
| Rest &&... | rest | ||
| ) |
Sets a value in the node using a sequence of keys.
Intermediate nodes on the path are created as needed and stored as std::shared_ptr<DBNode>. The last key in the sequence is associated with the provided value.
| T | Type of the value to store (compatible with Value). |
| Key | Type of the first key. |
| Rest | Types of additional keys. |
| value | Value to store. |
| key | First key in the path. |
| rest | Remaining keys specifying the path. |
| void DBNode::setGroup | ( | const std::vector< BlockName > & | keys, |
| const std::map< BlockName, Value > & | groupData | ||
| ) |
Sets the content of a whole sub-tree from a map of values.
The keys vector is interpreted as a path. Intermediate nodes are created as needed. At the end of the path, the node's internal map is replaced with groupData.
| keys | Path to the group node to fill. |
| groupData | Map of key–value pairs to store at that node. |
Definition at line 30 of file DBNode.cpp.