MarlinMT
0.1.0
|
XMLConfigReader plugin Read an XML file and populate the configuration with sections and parameters. More...
Inherits marlinmt::ConfigReader.
Public Member Functions | |
void | init (const std::string &desc) override |
Initialize the parser. More... | |
void | read (Configuration &cfg) override |
Read the configuration and populate the configuration object. More... | |
Public Member Functions inherited from marlinmt::ConfigReader | |
virtual | ~ConfigReader ()=default |
Default destructor. More... | |
Private Member Functions | |
void | parseSection (TiXmlElement *parentElement, const std::string &name, Configuration &cfg, bool addAttributes, bool throwIfNotFound) const |
Parse a configuration section from the parent XML element. More... | |
void | parseExecuteSection (TiXmlElement *parentElement, Configuration &cfg) const |
Parse the <execute> section and populate the configuration object accordingly. More... | |
void | resolveGroupSections (TiXmlElement *rootElement) const |
Resolve the <group> sections. More... | |
void | parseProcessorParameters (TiXmlElement *parent, Configuration &cfg) const |
Parse all the processor parameter sections in the parent XML element. More... | |
std::string | getAttribute (const TiXmlElement *element, const std::string &name) const |
Helper method to get a XML element attribute as string. More... | |
void | parseConstants (TiXmlDocument *idoc, Configuration &cfg) const |
Parse the <constants> section. More... | |
void | parseConstant (TiXmlElement *element, Configuration &cfg) const |
Parse a single <constant> element. More... | |
void | processIncludeElements (TiXmlElement *element, const Configuration &cfg) const |
Process all XML elements recursively. More... | |
void | processIncludeElement (TiXmlElement *element, const Configuration &cfg, TiXmlDocument &document) const |
Process a single XML element. More... | |
void | checkForNestedIncludes (const TiXmlNode *node) const |
Check recursively for XML element in the node. More... | |
void | parametersFromXMLElement (const TiXmlElement *element, const Configuration &cfg, ConfigSection §ion, bool addAttributes, const std::string &replacePrefix="") const |
Read the <parameter> XML elements form the parent XML element. More... | |
void | processConditions (TiXmlNode *current, const std::string &aCondition) const |
Treat the conditions for a XML node. More... | |
void | replaceGroups (TiXmlNode *processorsParent, TiXmlNode *section) const |
Replace the <group> tags in the execute section by the corresponding processors. More... | |
TiXmlNode * | findElement (TiXmlNode *node, const std::string &tag, const std::string &attribute, const std::string &value) const |
Find a particular XML node by matching tag, and a specific attribute value. More... | |
std::optional< std::string > | getReplacementParameter (const std::string &arg, const Configuration &config) const |
Private Attributes | |
std::string | _fname {} |
The input/output file name. More... | |
XMLConfigReader plugin Read an XML file and populate the configuration with sections and parameters.
Definition at line 26 of file XMLConfigReader.cc.
|
private |
Check recursively for XML element in the node.
Throw if an include element is found.
node | the parent element to check |
Definition at line 508 of file XMLConfigReader.cc.
References MARLINMT_THROW_T.
Referenced by processIncludeElement().
|
private |
Find a particular XML node by matching tag, and a specific attribute value.
For example:
corresponds to:
node | the parent node |
tag | the child XML element tag |
attribute | the attribute key to match |
value | the attribute value to match |
Definition at line 648 of file XMLConfigReader.cc.
Referenced by replaceGroups().
|
private |
Helper method to get a XML element attribute as string.
Throw an exception if not found
element | the XML element |
name | the attribute name |
Definition at line 358 of file XMLConfigReader.cc.
References _fname, and MARLINMT_THROW_T.
Referenced by parametersFromXMLElement(), parseConstant(), parseExecuteSection(), parseProcessorParameters(), processConditions(), processIncludeElement(), and replaceGroups().
|
private |
Definition at line 660 of file XMLConfigReader.cc.
References marlinmt::Configuration::hasSection(), MARLINMT_DECLARE_CONFIG_READER, marlinmt::ConfigSection::parameter(), marlinmt::ConfigSection::section(), and marlinmt::Configuration::section().
Referenced by parametersFromXMLElement(), parseConstant(), and parseExecuteSection().
|
overridevirtual |
Initialize the parser.
The descriptor string can be e.g:
desc | a descriptor string |
Implements marlinmt::ConfigReader.
Definition at line 188 of file XMLConfigReader.cc.
References _fname.
|
private |
Read the <parameter> XML elements form the parent XML element.
Add a new or overwrite an existing parameter in the input config section. The flag addAttributes specifies whether the XML element attributes should be imported as parameters. For example:
will add a parameter 'SuperHeroName' with the value 'Batman' to the list of parameters
element | the parent XML element containing parameter tags |
cfg | the configuration object for constants resolution |
section | the section to populate with parameters |
addAttributes | whether to add the XML element attributes in the list of parameters |
replacePrefix | the section prefix for replacement parameters |
Definition at line 521 of file XMLConfigReader.cc.
References getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, marlinmt::Configuration::replaceConstants(), and marlinmt::ConfigSection::setParameter().
Referenced by parseProcessorParameters(), and parseSection().
|
private |
Parse a single <constant> element.
Add a constant to the configuration object
element | the constant XML element |
cfg | the configuration object to populate |
Definition at line 411 of file XMLConfigReader.cc.
References marlinmt::Configuration::addConstant(), getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, marlinmt::Configuration::replaceConstants(), and marlinmt::book::Flags::value().
Referenced by parseConstants().
|
private |
Parse the <constants> section.
Populate the configuration object with constants. Also parse elements contained in the <constants> element (only).
idoc | the input XML document |
cfg | the configuration object to populate |
Definition at line 368 of file XMLConfigReader.cc.
References parseConstant(), and processIncludeElement().
Referenced by read().
|
private |
Parse the <execute> section and populate the configuration object accordingly.
parentElement | the parent element of the <execute> section |
cfg | the configuration object to populate |
Definition at line 259 of file XMLConfigReader.cc.
References _fname, marlinmt::Configuration::createSection(), getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, MARLINMT_THROW_T, processConditions(), marlinmt::Configuration::replaceConstants(), and replaceGroups().
Referenced by read().
|
private |
Parse all the processor parameter sections in the parent XML element.
Create a global config section 'processors' and add every processor parameters in a separate sub section.
parent | the parent XML element of the <processor> tags |
cfg | the configuration object to populate |
Definition at line 333 of file XMLConfigReader.cc.
References marlinmt::Configuration::createSection(), getAttribute(), MARLINMT_RETHROW_T, MARLINMT_THROW_T, and parametersFromXMLElement().
Referenced by read().
|
private |
Parse a configuration section from the parent XML element.
parentElement | the parent XML element of the config |
name | the XML element tag to read |
cfg | the configuration object to populate |
addAttributes | whether to add the XML element attributes in the parameters |
throwIfNotFound | whether to throw if the section if not found |
Definition at line 244 of file XMLConfigReader.cc.
References _fname, marlinmt::Configuration::createSection(), MARLINMT_THROW_T, and parametersFromXMLElement().
Referenced by read().
|
private |
Treat the conditions for a XML node.
current | the input XML node |
aCondition | the condition string to parse |
Definition at line 567 of file XMLConfigReader.cc.
References getAttribute(), and MARLINMT_RETHROW.
Referenced by parseExecuteSection().
|
private |
Process a single XML element.
Resolve the 'ref' location and load the XML document. Check for nested include XML element which not allowed for the current implementation.
element | the XML element to process |
cfg | the configuration for constant resolution |
document | the include document object to receive |
Definition at line 476 of file XMLConfigReader.cc.
References _fname, checkForNestedIncludes(), getAttribute(), MARLINMT_RETHROW, MARLINMT_THROW_T, and marlinmt::Configuration::replaceConstants().
Referenced by parseConstants(), and processIncludeElements().
|
private |
Process all XML elements recursively.
Import the XML tree of the include reference in-place in the current XML tree.
element | the current XML element to parse |
cfg | the configuration object for constants replacement |
Definition at line 441 of file XMLConfigReader.cc.
References processIncludeElement().
Referenced by read().
|
overridevirtual |
Read the configuration and populate the configuration object.
cfg | the configuration object to populate |
Implements marlinmt::ConfigReader.
Definition at line 194 of file XMLConfigReader.cc.
References _fname, MARLINMT_THROW_T, parseConstants(), parseExecuteSection(), parseProcessorParameters(), parseSection(), processIncludeElements(), and resolveGroupSections().
|
private |
Replace the <group> tags in the execute section by the corresponding processors.
processorsParent | the XML element containing the list of groups |
section | the execute XML element section |
Definition at line 614 of file XMLConfigReader.cc.
References findElement(), getAttribute(), MARLINMT_RETHROW, and MARLINMT_THROW_T.
Referenced by parseExecuteSection().
|
private |
Resolve the <group> sections.
Add common group parameter to every processor in the group
rootElement | the XML parent element (the <marlinmt> root element) |
Definition at line 306 of file XMLConfigReader.cc.
Referenced by read().
|
private |
The input/output file name.
Definition at line 182 of file XMLConfigReader.cc.
Referenced by getAttribute(), init(), parseExecuteSection(), parseSection(), processIncludeElement(), and read().