Tesseract 0.28.4
Loading...
Searching...
No Matches
tesseract::common::PropertyTreeBuilder Class Reference

Fluent builder for constructing PropertyTree schemas with minimal boilerplate. More...

#include <property_tree.h>

Public Member Functions

PropertyTreeBuilder & oneOf ()
 Mark the current node as a standalone oneOf schema.
PropertyTreeBuilder & compose (const PropertyTree &source)
 Copy all children from another PropertyTree into the current scope.
PropertyTreeBuilder & done ()
 Pop current node, return to parent scope.
PropertyTree build ()
 Finalize and return the constructed PropertyTree.
Type-creating methods – create a typed child and descend into it.
PropertyTreeBuilder & container (std::string_view name)
PropertyTreeBuilder & string (std::string_view name)
PropertyTreeBuilder & character (std::string_view name)
PropertyTreeBuilder & boolean (std::string_view name)
PropertyTreeBuilder & int32 (std::string_view name)
PropertyTreeBuilder & uint32 (std::string_view name)
PropertyTreeBuilder & int64 (std::string_view name)
PropertyTreeBuilder & uint64 (std::string_view name)
PropertyTreeBuilder & float32 (std::string_view name)
PropertyTreeBuilder & float64 (std::string_view name)
PropertyTreeBuilder & eigenIsometry3d (std::string_view name)
PropertyTreeBuilder & eigenVectorXd (std::string_view name)
PropertyTreeBuilder & eigenVector2d (std::string_view name)
PropertyTreeBuilder & eigenVector3d (std::string_view name)
PropertyTreeBuilder & customType (std::string_view name, std::string_view type_str)
PropertyTreeBuilder & beginOneOf ()
 Begin an inline oneOf group inside a container.
PropertyTreeBuilder & endOneOf ()
 Close an inline oneOf group opened by beginOneOf().
Attribute setters – apply to the current node.
PropertyTreeBuilder & doc (std::string_view text)
PropertyTreeBuilder & required ()
PropertyTreeBuilder & defaultVal (bool val)
PropertyTreeBuilder & defaultVal (int val)
PropertyTreeBuilder & defaultVal (double val)
PropertyTreeBuilder & defaultVal (const char *val)
PropertyTreeBuilder & defaultVal (std::string_view val)
PropertyTreeBuilder & defaultVal (const YAML::Node &val)
PropertyTreeBuilder & enumValues (const std::vector< std::string > &values)
PropertyTreeBuilder & minimum (int val)
PropertyTreeBuilder & minimum (double val)
PropertyTreeBuilder & maximum (int val)
PropertyTreeBuilder & maximum (double val)
PropertyTreeBuilder & minimumLength (std::size_t length)
PropertyTreeBuilder & maximumLength (std::size_t length)
PropertyTreeBuilder & label (std::string_view text)
PropertyTreeBuilder & placeholder (std::string_view text)
PropertyTreeBuilder & group (std::string_view text)
PropertyTreeBuilder & readOnly (bool val=true)
PropertyTreeBuilder & hidden (bool val=true)
PropertyTreeBuilder & validator (PropertyTree::ValidatorFn fn)
PropertyTreeBuilder & attribute (std::string_view name, const YAML::Node &value)
PropertyTreeBuilder & attribute (std::string_view name, std::string_view value)
PropertyTreeBuilder & acceptsDerivedTypes ()
 Mark that this field accepts the base type and any registered derived types. Only applicable when the type attribute is a registered custom type.
Plugin helpers – self-closing convenience methods for PluginInfoContainer schemas.
PropertyTreeBuilder & pluginContainer (std::string_view name, std::string_view factory_base_type, std::string_view plugin_section)
 Create a PluginInfoContainer child with plugin discovery metadata.
PropertyTreeBuilder & pluginContainerMap (std::string_view name, std::string_view factory_base_type, std::string_view plugin_section)
 Create a Map[string, PluginInfoContainer] child with plugin discovery metadata.

Detailed Description

Fluent builder for constructing PropertyTree schemas with minimal boilerplate.

Usage:

auto schema = PropertyTreeBuilder()
.container("config")
.doc("Main config").required()
.boolean("conditional").doc("Enable conditional").defaultVal(true).done()
.string("program").doc("The program").required().done()
.done()
.build();

Schema composition example (reuse base schemas):

auto base = PropertyTreeBuilder()
.attribute(TYPE, CONTAINER)
.string("name").required().done()
.build();
auto extended = PropertyTreeBuilder()
.attribute(TYPE, CONTAINER)
.compose(base) // copies name field
.int32("priority").done()
.build();

Inline oneOf example (shared fields with mutually exclusive parts):

auto schema = PropertyTreeBuilder()
.string(\"name\").required().done()
.beginOneOf()
.container(\"option_a\")
.string(\"field_a\").required().done()
.done()
.container(\"option_b\")
.int32(\"field_b\").required().done()
.done()
.endOneOf()
.build();

Type-creating methods (container, string, boolean, etc.) create a child node, set its type, and push it as the current scope. Attribute setters (doc, required, defaultVal, etc.) apply to the current scope. done() pops back to the parent. Use compose() to copy all children from an existing PropertyTree into the current scope. Use beginOneOf()/endOneOf() to define mutually exclusive branches inline within a container — shared fields are defined outside the oneOf block.

Member Function Documentation

◆ oneOf()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::oneOf ( )

Mark the current node as a standalone oneOf schema.

Define each mutually exclusive branch as a child of the current node. Branches may describe scalar, sequence, or map values. During applyConfig() exactly one branch is selected based on the configuration shape and replaces the current node.

◆ beginOneOf()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::beginOneOf ( )

Begin an inline oneOf group inside a container.

Define mutually exclusive branches as container children within this group. During applyConfig() the parent's full config is used for branch selection, and the chosen branch's children are hoisted into the parent. Close with endOneOf().

◆ acceptsDerivedTypes()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::acceptsDerivedTypes ( )

Mark that this field accepts the base type and any registered derived types. Only applicable when the type attribute is a registered custom type.

Returns
Reference to this builder for method chaining.

◆ pluginContainer()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::pluginContainer ( std::string_view name,
std::string_view factory_base_type,
std::string_view plugin_section )

Create a PluginInfoContainer child with plugin discovery metadata.

Parameters
nameChild property name.
factory_base_typeFully-qualified factory base class.
plugin_sectionboost_plugin_loader export section containing compatible plugins.

◆ pluginContainerMap()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::pluginContainerMap ( std::string_view name,
std::string_view factory_base_type,
std::string_view plugin_section )

Create a Map[string, PluginInfoContainer] child with plugin discovery metadata.

Parameters
nameChild property name.
factory_base_typeFully-qualified factory base class.
plugin_sectionboost_plugin_loader export section containing compatible plugins.

◆ compose()

PropertyTreeBuilder & tesseract::common::PropertyTreeBuilder::compose ( const PropertyTree & source)

Copy all children from another PropertyTree into the current scope.

This allows composing schemas together. The source tree's immediate children (with their full subtrees, attributes, and validators) are appended to the current builder scope. The source tree's own root-level attributes are ignored; only its children are composed.

Parameters
sourceThe PropertyTree whose children should be copied into this scope.
Returns
Reference to this builder for method chaining.