20 #ifndef GEOS_DATAREPOSITORY_XMLWRAPPER_HPP_
21 #define GEOS_DATAREPOSITORY_XMLWRAPPER_HPP_
26 #include "common/GEOS_RAJA_Interface.hpp"
27 #include "LvArray/src/output.hpp"
28 #include "LvArray/src/input.hpp"
30 #include "codingUtilities/RTTypes.hpp"
33 #include <pugixml.hpp>
150 static constexpr
size_t npos = string::npos;
262 pugi::xml_document pugiDocument;
267 string m_rootFilePath;
302 string const & outputDir = {} );
349 template<
typename T >
350 std::enable_if_t< traits::CanStreamInto< std::istringstream, T > >
355 std::istringstream ss( value );
358 "Error detected while parsing string \"" << value <<
359 "\" to type " << LvArray::system::demangleType< T >(),
371 template<
typename T,
int SIZE >
387 template<
typename T,
int NDIM,
typename PERMUTATION >
388 std::enable_if_t< traits::CanStreamInto< std::istringstream, T > >
393 LvArray::input::stringToArray( array,
string( stringutilities::trimSpaces( value ) ) );
403 IS_VALID_EXPRESSION( canParseVariable, T,
stringToInputVariable( std::declval< T & >(),
string(), Regex() ) );
411 template<
typename T >
412 static void equate( T & lhs, T
const & rhs )
423 template<
typename T,
int NDIM,
typename PERM >
424 static void equate( Array< T, NDIM, PERM >
const & lhs, T
const & rhs )
425 { lhs.template setValues< serialPolicy >( rhs ); }
444 template<
typename T,
typename U >
445 std::enable_if_t< !internal::canParseVariable< T >,
bool >
448 GEOS_THROW(
"Cannot parse key with name ("<<name<<
") with the given type " << LvArray::system::demangleType< T >(),
InputError );
464 template<
typename T,
typename T_DEF = T >
465 std::enable_if_t< internal::canParseVariable< T >,
bool >
470 T_DEF
const & defVal )
472 xmlAttribute const xmlatt = targetNode.attribute( name.c_str() );
473 if( !xmlatt.empty() )
482 internal::equate( rval, defVal );
499 template<
typename T >
500 std::enable_if_t< internal::canParseVariable< T >,
bool >
505 bool const required )
507 xmlAttribute const xmlatt = targetNode.attribute( name.c_str() );
509 bool const success = !(xmlatt.empty() && required);
530 template<
typename T >
531 std::enable_if_t< !dataRepository::DefaultValue< T >::has_default_value,
bool >
553 template<
typename T >
554 typename std::enable_if_t< dataRepository::DefaultValue< T >::has_default_value,
bool >
#define GEOS_THROW(msg, TYPE)
Throw an exception.
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
Lightweight wrapper around a c-array.
Base template for ordered and unordered maps.
xmlNode appendChild(string const &name)
Add a root element to the document.
xmlDocument(xmlDocument &&)=default
move constructor
void addIncludedXML(xmlNode &targetNode, int level=0)
Function to add xml nodes from included files.
bool hasNodeFileInfo() const
string const & getFilePath() const
map< string, string > const & getOriginalBuffers() const
bool saveFile(string const &path) const
Save the XML to a file.
xmlNode appendChild(xmlNodeType type=xmlNodeType::node_element)
Add a root element to the document.
string const & getOriginalBuffer() const
xmlDocument()
Construct an empty xmlDocument that waits to load something.
xmlNode getChild(string const &name) const
xmlNodePos getNodePosition(xmlWrapper::xmlNode const &node) const
If the node file information are loaded, compute the position of a node.
xmlDocument(const xmlDocument &)=delete
non-copyable
xmlNode getFirstChild() const
xmlResult loadString(string_view content, bool loadNodeFileInfo=false)
Load document from zero-terminated string. No encoding conversions are applied. Free any previously l...
static constexpr size_t npos
Error value for when an offset / line position is undefined.
xmlResult loadFile(string const &path, bool loadNodeFileInfo=false)
Load document from file. Free any previously loaded xml tree. Wrapper of pugi::xml_document::loadBuff...
string const * getOriginalBuffer(string const &filePath) const
internal::Helper< T > DefaultValue
A templated alias to hold default values.
pugi::xml_node_type xmlNodeType
Alias for the type variant of an xml node.
constexpr char const includedFileTag[]
XML tag name for included files.
std::enable_if_t< traits::CanStreamInto< std::istringstream, T > > stringToInputVariable(T &target, string const &value, Regex const ®ex)
Parse a string and fill a variable with the value(s) in the string.
void validateString(string const &value, Regex const ®ex)
pugi::xml_attribute xmlAttribute
std::enable_if_t< !internal::canParseVariable< T >, bool > readAttributeAsType(T &, string const &name, Regex const &, xmlNode const &, U const &)
Extract attribute in an xml tree, and translate its value into a typed variable. This SFINAE implemen...
pugi::xml_parse_result xmlResult
Alias for the type of the result from an xml parse attempt.
constexpr char const charOffsetString[]
constexpr variable to hold node character offset from the start of the xml file.
bool isFileMetadataAttribute(string const &name)
constexpr char const includedListTag[]
XML tag name for included sections.
constexpr char const filePathString[]
constexpr variable to hold name for inserting the file path into the xml file.
void processInputException(std::exception const &ex, string const &targetAttributeName, xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Helper method to process an exception that has been thrown during xml parsing.
string buildMultipleInputXML(string_array const &inputFileList, string const &outputDir={})
Function to handle multiple input xml files.
LvArray::Array< T, NDIM, PERMUTATION, localIndex, LvArray::ChaiBuffer > Array
Multidimensional array type. See LvArray:Array for details.
array1d< string > string_array
A 1-dimensional array of geos::string types.
std::string_view string_view
String type.
string filePath
Path of the file containing this element.
size_t const offsetInLine
xmlAttributePos(string const &filePath, size_t line, size_t offsetInLine, size_t offset)
Constructor of this struct.
xmlAttributePos getAttributeLine(string const &attName) const
Compute the xmlAttributePos of an xml attribute.
xmlNodePos(xmlDocument const &document, string const &filePath, size_t line, size_t offsetInLine, size_t offset)
Constructor of this struct.
xmlDocument const & document
Reference of the main xmlDocument that contains all original file buffers.