MUSX Document Model
Loading...
Searching...
No Matches
musx::factory::PoolFactory< DerivedType, ObjectBase, PoolType > Class Template Reference

Factory class for creating a dom::ObjectPool from XML. More...

#include <PoolFactory.h>

+ Inheritance diagram for musx::factory::PoolFactory< DerivedType, ObjectBase, PoolType >:

Static Public Member Functions

static std::shared_ptr< PoolType > create (const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
 Creates a OthersPool object from an XML element.
 

Additional Inherited Members

- Static Protected Member Functions inherited from musx::factory::FactoryBase
template<typename DataType , typename ParserFunc >
static void getFieldFromXml (const XmlElementPtr &element, const std::string &nodeName, DataType &dataField, ParserFunc parserFunc, bool expected=false)
 Helper function to check if a child exists and populate it if so.
 
static XmlElementPtr getFirstChildElement (const XmlElementPtr &element, const std::string &childElementName)
 Helper function to throw when child element does not exist.
 
static std::optional< std::string > getOptionalChildText (const XmlElementPtr &element, const std::string &childElementName)
 Helper function to return std::nullopt when child element does not exist.
 
template<typename T >
static std::optional< T > getOptionalChildTextAs (const XmlElementPtr &element, const std::string &childElementName, T defaultValue={})
 Helper function to return std::nullopt when child element does not exist.
 

Detailed Description

template<typename DerivedType, typename ObjectBase, typename PoolType>
class musx::factory::PoolFactory< DerivedType, ObjectBase, PoolType >

Factory class for creating a dom::ObjectPool from XML.

This factory class uses CRTP (Curiously Recurring Template Pattern) to implement a polymorphic factory for creating ObjectPool objects from an XML representation. The derived classes are responsible for specifying their own creation mechanisms by providing appropriate specializations.

Template Parameters
DerivedTypeThe derived type for CRTP, which will implement specific extraction behavior from XML.
ObjectBaseThe base type of the objects that are stored in the pool, providing a common interface.
PoolTypeThe type of the pool that stores the objects, such as a collection of ObjectBase derived objects.

Member Function Documentation

◆ create()

template<typename DerivedType , typename ObjectBase , typename PoolType >
static std::shared_ptr< PoolType > musx::factory::PoolFactory< DerivedType, ObjectBase, PoolType >::create ( const XmlElementPtr element,
const dom::DocumentPtr document,
ElementLinker elementLinker 
)
inlinestatic

Creates a OthersPool object from an XML element.

This function creates an object pool by parsing the XML element representing the <others> node. It iterates over each child element of the XML element, extracts relevant information using DerivedType::extractFromXml, and adds the created objects to the pool.

Parameters
elementThe XML element representing the <others> node.
documentThe document object providing context for the XML parsing.
elementLinkerA class for storing deferred linkage commands.
Returns
A fully populated ObjectPoolType object.