Factory base class.
More...
#include <FactoryBase.h>
|
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.
|
|
◆ 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
-
DataType | the type of data to be populated (usually inferred from the call) |
ParserFunc | the 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_argument | when child element does not exist. |