![]() |
Tesseract 0.28.4
|
Represents a node in a hierarchical property tree. More...
#include <property_tree.h>
Public Types | |
| using | ValidatorFn |
| Signature for custom validator callbacks. | |
Public Member Functions | |
| PropertyTree ()=default | |
| Default constructor. Creates an empty tree node. | |
| PropertyTree (const PropertyTree &other) | |
| Deep-copy constructor – clones all YAML::Nodes and subtrees. | |
| PropertyTree & | operator= (const PropertyTree &other) |
| Deep-copy assignment operator. | |
| PropertyTree (PropertyTree &&) noexcept=default | |
| Default move constructor/assignment are fine. | |
| PropertyTree & | operator= (PropertyTree &&) noexcept=default |
| std::vector< std::string > | applyConfig (const YAML::Node &config, bool allow_extra_properties=false) |
| Apply a YAML configuration to this schema, populate defaults, and validate the result. | |
| std::vector< std::string > | validate (bool allow_extra_properties=false) const |
| Validate the tree, collecting all errors. | |
| void | addValidator (ValidatorFn fn) |
| Register a custom validator for this node. | |
| PropertyTree & | operator[] (std::string_view key) |
| Access or create a child node by key. | |
| PropertyTree & | at (std::string_view key) |
| Access a child node by key. | |
| const PropertyTree & | at (std::string_view key) const |
| Access a child node by key (const). | |
| const PropertyTree * | find (std::string_view key) const |
| Find a child node without creating it. | |
| PropertyTree * | find (std::string_view key) |
| Find a child node without creating it (mutable). | |
| void | setValue (const YAML::Node &v) |
| Set the YAML value of this node. | |
| const YAML::Node & | getValue () const |
| Retrieve the YAML value stored at this node. | |
| template<typename T> | |
| T | as () const |
| Retrieve the YAML value casted to the provided type. | |
| bool | isNull () const |
| Check if property value is null. | |
| bool | isContainer () const |
| Check if property is a container of child properties. | |
| std::vector< std::string > | keys () const |
| List all immediate child keys. | |
| void | setAttribute (std::string_view name, const YAML::Node &attr) |
| Set a metadata attribute (YAML node form). | |
| void | setAttribute (std::string_view name, std::string_view attr) |
| Convenience overload to set a string attribute. | |
| void | setAttribute (std::string_view name, const char *attr) |
| void | setAttribute (std::string_view name, bool attr) |
| Set a boolean attribute. | |
| void | setAttribute (std::string_view name, int attr) |
| Set an integer attribute. | |
| void | setAttribute (std::string_view name, double attr) |
| Set a double attribute. | |
| void | setAttribute (std::string_view name, const std::vector< std::string > &attr) |
| Set a vector of strings attribute. | |
| bool | hasAttribute (std::string_view name) const |
| Check if an attribute exists and is not null. | |
| std::optional< YAML::Node > | getAttribute (std::string_view name) const |
| Retrieve an attribute value by name. | |
| std::vector< std::string > | getAttributeKeys () const |
| List all metadata attribute keys. | |
| bool | isRequired () const |
| Check if property is requried by checking for attribute and its value. | |
| YAML::Node | toYAML (bool exclude_attributes=true) const |
| Serialize this tree back into a YAML::Node. | |
| operator bool () const noexcept | |
| Indicate if defined, meaning it has children or a value. | |
| std::size_t | size () const |
| Return number of immediate children. | |
| bool | empty () const |
| Check if this node has no children. | |
Static Public Member Functions | |
| static PropertyTree | fromYAML (const YAML::Node &node) |
| Create a PropertyTree from a YAML::Node. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const PropertyTree &tree) |
| Stream output – serializes toYAML() to the stream. | |
| void | validateCustomType (const PropertyTree &node, const std::string &path, std::vector< std::string > &errors) |
| Validator: Retrieve schema for the custom type and run its validators. | |
Represents a node in a hierarchical property tree.
Each PropertyTree node may contain:
Signature for custom validator callbacks.
| node | The PropertyTree node being validated. |
| path | Dot-separated path to this node (for error messages). |
| errors | Output vector to append error messages to. |
|
nodiscard |
Apply a YAML configuration to this schema, populate defaults, and validate the result.
| config | The user-supplied YAML::Node (possibly null). |
| allow_extra_properties | If false, undeclared keys are reported. |
|
nodiscard |
Validate the tree, collecting all errors.
Recursively invokes all validators on this node and its children, collecting every error rather than stopping at the first one.
| allow_extra_properties | Indicate if extra properties are allowed. |
| void tesseract::common::PropertyTree::addValidator | ( | ValidatorFn | fn | ) |
Register a custom validator for this node.
| fn | Callback to invoke during validation. |
| PropertyTree & tesseract::common::PropertyTree::operator[] | ( | std::string_view | key | ) |
Access or create a child node by key.
| key | Child identifier (string key). |
| PropertyTree & tesseract::common::PropertyTree::at | ( | std::string_view | key | ) |
Access a child node by key.
| key | Child identifier. |
| std::out_of_range | if key not found. |
| const PropertyTree & tesseract::common::PropertyTree::at | ( | std::string_view | key | ) | const |
Access a child node by key (const).
| key | Child identifier. |
| std::out_of_range | if key not found. |
| const PropertyTree * tesseract::common::PropertyTree::find | ( | std::string_view | key | ) | const |
Find a child node without creating it.
| key | Child identifier. |
| PropertyTree * tesseract::common::PropertyTree::find | ( | std::string_view | key | ) |
Find a child node without creating it (mutable).
| key | Child identifier. |
| void tesseract::common::PropertyTree::setValue | ( | const YAML::Node & | v | ) |
Set the YAML value of this node.
| v | YAML::Node representing the new value. |
| const YAML::Node & tesseract::common::PropertyTree::getValue | ( | ) | const |
Retrieve the YAML value stored at this node.
|
inline |
Retrieve the YAML value casted to the provided type.
| bool tesseract::common::PropertyTree::isNull | ( | ) | const |
Check if property value is null.
| bool tesseract::common::PropertyTree::isContainer | ( | ) | const |
Check if property is a container of child properties.
| std::vector< std::string > tesseract::common::PropertyTree::keys | ( | ) | const |
List all immediate child keys.
| void tesseract::common::PropertyTree::setAttribute | ( | std::string_view | name, |
| const YAML::Node & | attr ) |
Set a metadata attribute (YAML node form).
| name | Attribute name. |
| attr | YAML::Node value. |
| bool tesseract::common::PropertyTree::hasAttribute | ( | std::string_view | name | ) | const |
Check if an attribute exists and is not null.
| name | Attribute name. |
| std::optional< YAML::Node > tesseract::common::PropertyTree::getAttribute | ( | std::string_view | name | ) | const |
Retrieve an attribute value by name.
| name | Attribute name. |
| std::vector< std::string > tesseract::common::PropertyTree::getAttributeKeys | ( | ) | const |
List all metadata attribute keys.
| bool tesseract::common::PropertyTree::isRequired | ( | ) | const |
Check if property is requried by checking for attribute and its value.
|
static |
Create a PropertyTree from a YAML::Node.
| node | Root YAML::Node to convert. |
| YAML::Node tesseract::common::PropertyTree::toYAML | ( | bool | exclude_attributes = true | ) | const |
Serialize this tree back into a YAML::Node.
| exclude_attributes | If true, omit the attributes map. |
| std::size_t tesseract::common::PropertyTree::size | ( | ) | const |
Return number of immediate children.
| bool tesseract::common::PropertyTree::empty | ( | ) | const |
Check if this node has no children.
|
friend |
Validator: Retrieve schema for the custom type and run its validators.
| node | Node to validate. |
| path | Dot-separated path for error messages. |
| errors | Output vector to append errors to. |