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

A global registry of named schemas for PropertyTree. More...

#include <schema_registry.h>

Public Member Functions

 SchemaRegistry (const SchemaRegistry &)=delete
SchemaRegistry & operator= (const SchemaRegistry &)=delete
 SchemaRegistry (const SchemaRegistry &&)=delete
SchemaRegistry & operator= (const SchemaRegistry &&)=delete
void registerSchema (const std::string &key, const PropertyTree &schema)
 Register an already-parsed schema under a logical key.
void registerSchemaFromFile (const std::string &key, const std::string &path)
 Register a schema from a YAML file path.
bool contains (const std::string &key) const
 Check whether a schema is registered under this key.
PropertyTree get (const std::string &key) const
 Retrieve a registered schema by key.
void loadAndRetainPluginLibraries (const boost_plugin_loader::PluginLoader &loader)
 Load plugin libraries and retain ownership for the lifetime of their registered schemas.
void registerDerivedType (const std::string &base_type_name, const std::string &derived_type_name)
 Register that a derived type can be used where a base type is expected.
bool isDerivedFrom (const std::string &base_type_name, const std::string &candidate_type) const
 Check if a given type is derived from (or equal to) a base type.
std::vector< std::string > getDerivedTypes (const std::string &base_type_name) const
 Get all registered derived types for a base type.

Static Public Member Functions

static std::shared_ptr< SchemaRegistry > instance ()
 Access the singleton instance.
static PropertyTree loadFile (const std::string &path)
 Load and parse an arbitrary YAML file into a PropertyTree.

Detailed Description

A global registry of named schemas for PropertyTree.

Use SchemaRegistry::instance() to access the singleton.

Member Function Documentation

◆ registerSchema()

void tesseract::common::SchemaRegistry::registerSchema ( const std::string & key,
const PropertyTree & schema )

Register an already-parsed schema under a logical key.

Parameters
keyUnique identifier for this schema.
schemaParsed PropertyTree schema.

◆ registerSchemaFromFile()

void tesseract::common::SchemaRegistry::registerSchemaFromFile ( const std::string & key,
const std::string & path )

Register a schema from a YAML file path.

Parameters
keyUnique identifier for this schema.
pathPath to a .yaml schema file.

◆ contains()

bool tesseract::common::SchemaRegistry::contains ( const std::string & key) const

Check whether a schema is registered under this key.

Parameters
keyLogical identifier.
Returns
True if present.

◆ get()

PropertyTree tesseract::common::SchemaRegistry::get ( const std::string & key) const

Retrieve a registered schema by key.

Parameters
keyLogical identifier.
Returns
Copy of the schema PropertyTree.
Exceptions
std::out_of_rangeif the key is not found.

◆ loadFile()

PropertyTree tesseract::common::SchemaRegistry::loadFile ( const std::string & path)
static

Load and parse an arbitrary YAML file into a PropertyTree.

Parameters
pathPath to a .yaml file.
Returns
Parsed PropertyTree.
Exceptions
YAML::Exceptionon parse errors.

◆ loadAndRetainPluginLibraries()

void tesseract::common::SchemaRegistry::loadAndRetainPluginLibraries ( const boost_plugin_loader::PluginLoader & loader)

Load plugin libraries and retain ownership for the lifetime of their registered schemas.

Libraries are loaded before the registry mutex is acquired so their static schema registration may safely call back into this registry. Loaded libraries are deduplicated by their resolved path.

Parameters
loaderConfigured plugin loader defining the libraries and search paths to use.
Exceptions
boost_plugin_loader::PluginLoaderExceptionif no plugin libraries were provided.

◆ registerDerivedType()

void tesseract::common::SchemaRegistry::registerDerivedType ( const std::string & base_type_name,
const std::string & derived_type_name )

Register that a derived type can be used where a base type is expected.

Parameters
base_type_nameThe base type name (e.g., "MyBaseClass")
derived_type_nameThe derived type name (e.g., "MyDerivedClass")

◆ isDerivedFrom()

bool tesseract::common::SchemaRegistry::isDerivedFrom ( const std::string & base_type_name,
const std::string & candidate_type ) const

Check if a given type is derived from (or equal to) a base type.

Parameters
base_type_nameThe base type to check against
candidate_typeThe type to check
Returns
True if candidate is the base or derives from it

◆ getDerivedTypes()

std::vector< std::string > tesseract::common::SchemaRegistry::getDerivedTypes ( const std::string & base_type_name) const

Get all registered derived types for a base type.

Parameters
base_type_nameThe base type
Returns
Vector of all type names that derive from (or equal) the base