MUSX Document Model
Loading...
Searching...
No Matches
musx::factory::FactoryBase Class Reference

Factory base class. More...

#include <FactoryBase.h>

+ Inheritance diagram for musx::factory::FactoryBase:

Static Protected Member Functions

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

Factory base class.

Member Function Documentation

◆ getFieldFromXml()

template<typename DataType , typename ParserFunc >
static void musx::factory::FactoryBase::getFieldFromXml ( const XmlElementPtr element,
const std::string &  nodeName,
DataType &  dataField,
ParserFunc  parserFunc,
bool  expected = false 
)
inlinestaticprotected

Helper function to check if a child exists and populate it if so.

EnigmaXml generally omits fields when they have the default value (usually 0). This helper function handles that without causing an exception. However, fields retrieved with this function are expected to exist unless the expected parameter is false. If they are missing but expected, this fact may be logged.

Template Parameters
DataTypethe type of data to be populated (usually inferred from the call)
ParserFuncthe parser function (usually inferred from the call)

◆ getFirstChildElement()

static XmlElementPtr musx::factory::FactoryBase::getFirstChildElement ( const XmlElementPtr element,
const std::string &  childElementName 
)
inlinestaticprotected

Helper function to throw when child element does not exist.

Exceptions
std::invalid_argumentwhen child element does not exist.