GEOSX
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
geosx::xmlWrapper Class Reference

#include <xmlWrapper.hpp>

Public Types

using xmlDocument = pugi::xml_document
 Alias for the type of xml document.
 
using xmlResult = pugi::xml_parse_result
 Alias for the type of the result from an xml parse attempt.
 
using xmlNode = pugi::xml_node
 Alias for the type of an xml node.
 
using xmlAttribute = pugi::xml_attribute
 Alias for the type of an xml attribute.
 
using xmlTypes = pugi::xml_node_type
 Alias for the type variant of an xml node.
 

Public Member Functions

 IS_VALID_EXPRESSION (canParseVariable, T, stringToInputVariable(std::declval< T & >(), string()))
 
Constructors/destructor/assignment.
 xmlWrapper ()=delete
 Deleted default constructor.
 
 ~xmlWrapper ()=delete
 Deleted default default destructor.
 
 xmlWrapper (xmlWrapper const &)=delete
 Deleted copy constructor.
 
 xmlWrapper (xmlWrapper &&)=delete
 Deleted move constructor.
 

Static Public Member Functions

static void addIncludedXML (xmlNode &targetNode)
 Function to add xml nodes from included files. More...
 
static void buildMultipleInputXML (string_array const &inputFileList, string &inputFileName)
 Function to handle multiple input xml files. More...
 
String to variable parsing.

These functions take in value and parse that string based on the type of target. The function implementation should provide sufficient error checking in the case that value is formatted incorrectly for the type specified in target.

template<typename T >
static std::enable_if_t< traits::CanStreamInto< std::istringstream, T > > stringToInputVariable (T &target, string const &value)
 Parse a string and fill a variable with the value(s) in the string. More...
 
template<typename T , int SIZE>
static void stringToInputVariable (Tensor< T, SIZE > &target, string const &value)
 Parse a string and fill a R1Tensor with the value(s) in the string. More...
 
template<typename T , int NDIM, typename PERMUTATION >
static std::enable_if_t< traits::CanStreamInto< std::istringstream, T > > stringToInputVariable (Array< T, NDIM, PERMUTATION > &array, string const &value)
 Parse a string and fill an Array with the value(s) in the string. More...
 
Attribute extraction from XML nodes.
template<typename T , typename T_DEF = T>
static std::enable_if_t< canParseVariable< T >, bool > readAttributeAsType (T &rval, string const &name, xmlNode const &targetNode, T_DEF const &defVal)
 Extract attribute in an xml tree, and translate its value into a typed variable. More...
 
template<typename T >
static std::enable_if_t< canParseVariable< T >, bool > readAttributeAsType (T &rval, string const &name, xmlNode const &targetNode, bool const required)
 Extract attribute in an xml tree, and translate its value into a typed variable. More...
 
template<typename T >
static std::enable_if_t< !dataRepository::DefaultValue< T >::has_default_value, bool > readAttributeAsType (T &rval, string const &name, xmlNode const &targetNode, dataRepository::DefaultValue< T > const &)
 Extract attribute in an xml tree, and translate its value into a typed variable. More...
 
template<typename T >
static std::enable_if_t< dataRepository::DefaultValue< T >::has_default_value, bool > readAttributeAsType (T &rval, string const &name, xmlNode const &targetNode, dataRepository::DefaultValue< T > const &defVal)
 Extract attribute in an xml tree, and translate its value into a typed variable. More...
 
template<typename T , typename U >
static std::enable_if_t< !canParseVariable< T >, bool > readAttributeAsType (T &, string const &, xmlNode const &, U const &)
 Stub that for unreadable types that errors out. More...
 

Static Public Attributes

static constexpr auto filePathString = "filePath"
 constexpr variable to hold name for inserting the file path into the xml file. More...
 

Detailed Description

This class wraps/provides facilities to process entries from an xml file into the appropriate data types. xmlWrapper provides some aliases that will wrap the underlying xml package being used to extract data from the xml file, and a set of static member functions that facilitate the parsing of string data from the xml into the variables that will hold those values in the code.

Definition at line 49 of file xmlWrapper.hpp.

Member Function Documentation

◆ addIncludedXML()

static void geosx::xmlWrapper::addIncludedXML ( xmlNode targetNode)
static

Function to add xml nodes from included files.

Parameters
targetNodethe node for which to look for included children specifications

This function looks for a "Included" node under the targetNode, loops over all subnodes under the "Included" node, and then parses the file specified in those subnodes taking all the nodes in the file and adding them to the targetNode.

◆ buildMultipleInputXML()

static void geosx::xmlWrapper::buildMultipleInputXML ( string_array const &  inputFileList,
string inputFileName 
)
static

Function to handle multiple input xml files.

Parameters
inputFileListthe list of input xml files
inputFileNamethe input xml file name

This function checks for multiple xml files, and will build a new input xml file with an included block if neccesary

◆ IS_VALID_EXPRESSION()

geosx::xmlWrapper::IS_VALID_EXPRESSION ( canParseVariable  ,
,
stringToInputVariable(std::declval< T &>(), string())   
)

Defines a static constexpr bool canParseVariable that is true iff the template parameter T is a valid argument to StringToInputVariable.

◆ readAttributeAsType() [1/5]

template<typename T , typename T_DEF = T>
static std::enable_if_t< canParseVariable< T >, bool > geosx::xmlWrapper::readAttributeAsType ( T &  rval,
string const &  name,
xmlNode const &  targetNode,
T_DEF const &  defVal 
)
inlinestatic

Extract attribute in an xml tree, and translate its value into a typed variable.

Template Parameters
Tthe type of variable fill with xml attribute.
T_DEFtype of the default value for rval
Parameters
[out]rvalthe variable to fill with value
[in]namethe name of the xml attribute to process
[in]targetNodethe xml node that should contain the attribute
[in]defValdefault value of rval (or entries of rval, if it is an array)
Returns
boolean value indicating whether the value was successfully read from XML.

Definition at line 183 of file xmlWrapper.hpp.

◆ readAttributeAsType() [2/5]

template<typename T >
static std::enable_if_t< canParseVariable< T >, bool > geosx::xmlWrapper::readAttributeAsType ( T &  rval,
string const &  name,
xmlNode const &  targetNode,
bool const  required 
)
inlinestatic

Extract attribute in an xml tree, and translate its value into a typed variable.

Template Parameters
Tthe type of variable fill with xml attribute.
Parameters
[out]rvalthe variable to fill with value
[in]namethe name of the xml attribute to process
[in]targetNodethe xml node that should contain the attribute
[in]requiredwhether or not the value is required
Returns
boolean value indicating whether the value was successfully read from XML.

Definition at line 214 of file xmlWrapper.hpp.

◆ readAttributeAsType() [3/5]

template<typename T >
static std::enable_if_t< !dataRepository::DefaultValue< T >::has_default_value, bool > geosx::xmlWrapper::readAttributeAsType ( T &  rval,
string const &  name,
xmlNode const &  targetNode,
dataRepository::DefaultValue< T > const &   
)
inlinestatic

Extract attribute in an xml tree, and translate its value into a typed variable.

Template Parameters
Tthe type of variable fill with xml attribute.
Parameters
[out]rvalthe variable to fill with value
[in]namethe name of the xml attribute to process
[in]targetNodethe xml node that should contain the attribute
Returns
boolean value indicating whether the value was successfully read from XML.

Definition at line 241 of file xmlWrapper.hpp.

◆ readAttributeAsType() [4/5]

template<typename T >
static std::enable_if_t< dataRepository::DefaultValue< T >::has_default_value, bool > geosx::xmlWrapper::readAttributeAsType ( T &  rval,
string const &  name,
xmlNode const &  targetNode,
dataRepository::DefaultValue< T > const &  defVal 
)
inlinestatic

Extract attribute in an xml tree, and translate its value into a typed variable.

Template Parameters
Tthe type of variable fill with xml attribute.
Parameters
[out]rvalthe variable to fill with value
[in]namethe name of the xml attribute to process
[in]targetNodethe xml node that should contain the attribute
[in]defValdefault value of rval (or entries of rval, if it is an array)
Returns
boolean value indicating whether the value was successfully read from XML.

Definition at line 258 of file xmlWrapper.hpp.

◆ readAttributeAsType() [5/5]

template<typename T , typename U >
static std::enable_if_t< !canParseVariable< T >, bool > geosx::xmlWrapper::readAttributeAsType ( T &  ,
string const &  ,
xmlNode const &  ,
U const &   
)
inlinestatic

Stub that for unreadable types that errors out.

Returns
false.

Definition at line 270 of file xmlWrapper.hpp.

◆ stringToInputVariable() [1/3]

template<typename T >
static std::enable_if_t< traits::CanStreamInto< std::istringstream, T > > geosx::xmlWrapper::stringToInputVariable ( T &  target,
string const &  value 
)
inlinestatic

Parse a string and fill a variable with the value(s) in the string.

Template Parameters
Tthe type of variable fill with string value
Parameters
[out]targetthe object to read values into
[in]valuethe string that contains the data to be parsed into target
Returns
void.

Definition at line 132 of file xmlWrapper.hpp.

◆ stringToInputVariable() [2/3]

template<typename T , int SIZE>
static void geosx::xmlWrapper::stringToInputVariable ( Tensor< T, SIZE > &  target,
string const &  value 
)
static

Parse a string and fill a R1Tensor with the value(s) in the string.

Parameters
[out]targetthe object to read values into
[in]valuethe string that contains the data to be parsed into target

◆ stringToInputVariable() [3/3]

template<typename T , int NDIM, typename PERMUTATION >
static std::enable_if_t< traits::CanStreamInto< std::istringstream, T > > geosx::xmlWrapper::stringToInputVariable ( Array< T, NDIM, PERMUTATION > &  array,
string const &  value 
)
inlinestatic

Parse a string and fill an Array with the value(s) in the string.

Template Parameters
Tdata type of the array
NDIMnumber of dimensions of the array
PERMUTATIONthe permutation of the array
Parameters
[out]arraythe array to read values into
[in]valuethe string that contains the data to be parsed into target
Returns
void.

Definition at line 157 of file xmlWrapper.hpp.

Member Data Documentation

◆ filePathString

constexpr auto geosx::xmlWrapper::filePathString = "filePath"
static

constexpr variable to hold name for inserting the file path into the xml file.

This is used because we would like the option to hold the file path in the xml structure.

Definition at line 73 of file xmlWrapper.hpp.


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