OSFI-C++  3.10.0
OpenSF Integration Library
ParamReader Class Reference

#include <ParamReader.h>

Public Member Functions

 ParamReader (const string &xmlFile, const string &xsdFile)
 
 ParamReader (const std::string &xmlFile)
 
 ParamReader (const ParamReader &other)
 
 ParamReader (ParamReader &&other)=default
 
bool validateAgainst (const std::string &xsdFile) const
 
bool validateAgainstInternalSchema () const
 
virtual ~ParamReader ()
 
Parameter getParameter (const string &paramName) const
 
vector< ParametergetParameters (const string &groupName) const
 
t_params_map getParameters () const
 
bool existParameter (const string &paramName) const
 
void setParameter (const string &paramName, string value)
 
void print () const
 
ParametergetParameterRef (const string &path)
 
const ParametergetParameterRef (const string &path) const
 

Detailed Description

This class parses the XML configuration files provided by the openSF HMI formatted with the following elements:

  • Element <group_name>. This element can create nested groups to enclose parameters and provide scope information. Optional element.
  • Element parameter. This element can define the following attributes:
    • name. This is the parameter identifier. Names cannot contain spaces.
    • description. Short definition or meaning for the parameter, optional.
    • type. Possible values for this attribute are in osfi::confm::ElementType. Alternatively, if values "ARRAY" or "MATRIX" appear, the data type is in the elementType atttribute.
    • Text content. This is the numerical, string or file location value.
    • units, min, max. Optional metadata for the parameter.
    • dims. Size of the dimensions, used to represent vectors and matrices. The first number refers to columns and the second one to rows when describing a matrix. This attribute is also optional: for scalar variables, dims can be avoided.

See the E2E-ICD reference for more details.

Constructor & Destructor Documentation

◆ ParamReader() [1/3]

ParamReader::ParamReader ( const string &  xmlFile,
const string &  xsdFile 
)

Default class constructor. Creates an instance of the ParamReader class, parses a given configuration XML file and stores every valid parameter.

Validating agains an XSD schema is optional.

Parameters
xmlFile- Configuration XML file
xsdFile- Configuration XSD schema
Exceptions
exceptionif error while parsing
Deprecated:
Broken overload. Instead of calling it, use the single argument version and then call the validateAgainst functions.

◆ ParamReader() [2/3]

ParamReader::ParamReader ( const std::string &  xmlFile)

Reads OSFI-formatted parameters from the given file.

Parameters
xmlFileConfiguration XML file
Exceptions
std::exceptionIf an error arises during parsing.

◆ ParamReader() [3/3]

ParamReader::ParamReader ( const ParamReader other)

Copy constructor, duplicates the map and document objects

◆ ~ParamReader()

virtual ParamReader::~ParamReader ( )
virtual

Class destructor.

Member Function Documentation

◆ existParameter()

bool ParamReader::existParameter ( const string &  paramName) const

Checks the existence of a parameter within a configuration file.

Parameters
paramNameParameter name (full path and name)
Returns
True if the parameter exists, false otherwise.

◆ getParameter()

Parameter ParamReader::getParameter ( const string &  paramName) const

Retrieves the parameter object corresponding with the given full path in the configuration file. If no such parameter exists, returns a "dummy" parameter. See also getParameterRef().

Parameters
paramNameParameter full path
Returns
A copy of the parameter instance with the given name

◆ getParameterRef() [1/2]

Parameter& ParamReader::getParameterRef ( const string &  path)

Returns a reference to a parameter in the set of read data. This method differs from getParameter() in that it does not copy the data, so the lifetime of the referee is limited to that of this instance. The returned reference is never otherwise invalidated.

Exceptions
std::invalid_argumentIf the path does not correspond to a parameter.

◆ getParameterRef() [2/2]

const Parameter& ParamReader::getParameterRef ( const string &  path) const

Returns a reference to a parameter in the set of read data. This method differs from getParameter() in that it does not copy the data, so the lifetime of the referee is limited to that of this instance. The returned reference is never otherwise invalidated.

Exceptions
std::invalid_argumentIf the path does not correspond to a parameter.

◆ getParameters() [1/2]

t_params_map ParamReader::getParameters ( ) const
Returns
A copy of all parameters read from the configuration file, keyed by full path.

◆ getParameters() [2/2]

vector<Parameter> ParamReader::getParameters ( const string &  groupName) const

Retrieves a copy of all parameters under a certain group, directly or indirectly. If there are no parameters that have the argument as a parent group, returns an empty vector.

Returns
all parameters under a certain group, or an empty vector if there are none.
Parameters
groupNamefull path of the parent group

◆ print()

void ParamReader::print ( ) const

Prints a textual representation of the list of Parameters to the OSFI log.

◆ setParameter()

void ParamReader::setParameter ( const string &  paramName,
string  value 
)

Changes the stored value of a certain parameter. Shows an error if cannot find parameter.

Parameters
paramName- full name of the parameter
value- new value
Exceptions
exceptionif value is invalid

◆ validateAgainst()

bool ParamReader::validateAgainst ( const std::string &  xsdFile) const

Validate the XML document read against the given schema.

Exceptions
invalid_argumentIf the schema cannot be read.
Returns
true if the document passes validation, false otherwise.

◆ validateAgainstInternalSchema()

bool ParamReader::validateAgainstInternalSchema ( ) const

Validate the XML document read against the schema referenced in the document itself.

Returns
true if the document passes validation, false otherwise.

The documentation for this class was generated from the following file: