39 #ifndef _uhal_XmlParser_hpp_ 40 #define _uhal_XmlParser_hpp_ 46 #include "pugixml.hpp" 47 #include "uhal/log/log.hpp" 56 UHAL_DEFINE_EXCEPTION_CLASS ( ContradictoryParserRule ,
"Exception class to handle the case where an attribute is both required and forbidden." )
58 UHAL_DEFINE_EXCEPTION_CLASS ( NoActionSpecified , "Exception class to handle the case where a callback is requested without it being specified." )
60 UHAL_DEFINE_EXCEPTION_CLASS ( TooManyAttributes , "Exception class to handle the case where the parser is asked to handle more than 64 attributes." )
64 UHAL_DEFINE_EXCEPTION_CLASS ( AmbiguousParserRules , "Exception class to handle the case where two or more equally strict rules are passed." )
70 template < typename R >
74 template < typename R >
81 virtual ~BaseFunctionObject();
87 virtual R operator() (
const pugi::xml_node& aNode ) = 0;
91 template <
typename R ,
typename T >
106 R operator() (
const pugi::xml_node& aNode );
116 template <
typename R ,
typename T >
131 R operator() (
const pugi::xml_node& aNode );
145 template <
typename R >
166 Rule<R>& require (
const std::string& aStr );
173 Rule<R>& forbid (
const std::string& aStr );
180 Rule<R>& optional (
const std::string& aStr );
196 R operator() (
const pugi::xml_node& aNode );
220 template <
typename R >
235 template <
typename T >
236 void addRule (
const Rule<R> & aRule , T aCallbackHandler );
243 R operator() (
const pugi::xml_node& aNode );
249 boost::unordered_map< std::string , uint64_t >
mHashes;
std::set< std::string > mOptional
The optional attributes for this rule.
Abstract base class for wrapping function pointers, function objects and bound functions as objects...
uint64_t mRequiredHash
The hash for required attributes.
boost::unordered_map< std::string, uint64_t > mHashes
Map of the tags to the one-hot encoded hash.
Class for wrapping bound functions and function objects as an object.
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
BaseFunctionObject< R > * mFuncPtr
An object wrapping the function pointer for the function to be called when the rule conditions are me...
T mT
The function object or bound function which will be called when the object is evaluated (bracket oper...
uint32_t mRuleCounter
Member to track rule numbers for giving each rule a unique ID.
uint32_t mRuleId
The ID of the rule.
uint64_t mForbiddenHash
The hash for forbidden attributes.
std::deque< Rule< R > > mRules
Container for storing rule objects.
Rule for matching XML attributes.
std::set< std::string > mRequired
The required attributes for this rule.
T * mT
Store the function pointer which will be called when the object is evaluated (bracket operator) ...
uint64_t mNextHash
One-hot encoded hash for rules.
std::set< std::string > mForbidden
The forbidden attributes for this rule.
Forward declaration of the Parser so we can declare it friend.