36#ifndef NEKTAR_LIB_UTILITIES_BASICUTILS_SESSIONNODE_H
37#define NEKTAR_LIB_UTILITIES_BASICUTILS_SESSIONNODE_H
49namespace SessionNodeConvert
73 unsigned long &value);
75 unsigned long long &value);
133 std::string text =
"");
174 const std::string &name)
const;
179 const std::string &def)
const;
201 template <
typename T>
208 return GetAttributeAs<T>(name);
218 const std::string &name)
const;
223 const std::string &name)
const;
230 const std::string &name)
const;
243 const std::string &name)
const;
248 const std::string &def)
const;
253 template <
typename T> T
GetValueAs(
const std::string &name)
const
256 const std::string &str =
GetValue(name);
267 template <
typename T>
274 return GetValueAs<T>(name);
300 const size_t timeLevel,
const bool enableCheck =
true)
const;
333 void UpdatePath(
const std::string &parentPath);
337 const std::string &kind,
const std::string &name,
338 const std::string &str)
const;
#define LIB_UTILITIES_EXPORT
A single node of a format-neutral session configuration tree.
ChildList m_children
Children of this node, in the order supplied.
bool DefinesText() const
Returns true if this node carries a non-empty block of text.
void AddChild(SessionNode child)
Appends child to this node's list of children.
const SessionNode * GetChildPtr(const std::string &name) const
Returns the first child called name, or nullptr if there is none.
const std::string & GetPath() const
Returns the path of this node from the root of the tree it belongs to, e.g. "FORCING/FORCE/COEFF".
const std::string & GetValue(const std::string &name) const
Returns the text of the first child called name.
std::vector< std::pair< std::string, std::string > > AttributeMap
Ordered list of (name, value) attribute pairs.
const std::string & GetName() const
Returns the name of this node, e.g. "FORCE".
void SetAttribute(std::string name, std::string value)
Sets attribute name to value, replacing any existing value.
bool DefinesChild(const std::string &name) const
Returns true if this node has at least one child called name.
SessionNode()=default
Construct an empty, unnamed node.
T GetValueAs(const std::string &name, const T &def) const
Returns the text of the first child called name converted to a T, or def if there is no such child; a...
void UpdatePath(const std::string &parentPath)
Recomputes m_path from parentPath, recursing into m_children.
std::string m_text
Text carried by this node, if any.
std::string m_path
Path of this node from the root of its tree; see GetPath().
T GetAttributeAs(const std::string &name) const
Returns attribute name converted to a T; a fatal error is raised if the attribute is not defined or d...
std::vector< SessionNode > ChildList
Ordered list of child nodes.
void SetText(std::string text)
Sets the text carried by this node.
const std::string & GetAttribute(const std::string &name) const
Returns the value of attribute name; a fatal error is raised if the attribute is not defined.
T GetAttributeAs(const std::string &name, const T &def) const
Returns attribute name converted to a T, or def if the attribute is not defined; a fatal error is rai...
const AttributeMap & GetAttributes() const
Returns all of this node's attributes, in the order they were supplied.
std::string m_name
Name of this node.
const std::string & GetText() const
Returns the text carried by this node, or an empty string if it carries none.
void ThrowConversionError(const std::string &kind, const std::string &name, const std::string &str) const
Raises a fatal error describing a failed string conversion.
const SessionNode & GetChild(const std::string &name) const
Returns the first child called name; a fatal error is raised if there is none.
bool DefinesAttribute(const std::string &name) const
Returns true if this node has an attribute called name.
std::string Describe() const
Returns a short human-readable rendering of this node, naming its path and its attributes,...
const ChildList & GetChildren() const
Returns every child of this node, in document order.
AttributeMap m_attributes
Attributes of this node, in the order supplied.
const SessionNode * GetTimeLevel(const size_t timeLevel, const bool enableCheck=true) const
Resolves the TIMELEVEL indirection used by parallel-in-time runs.
T GetValueAs(const std::string &name) const
Returns the text of the first child called name converted to a T; a fatal error is raised if there is...
bool FromString(const std::string &str, std::string &value)
Convert the string str into value.