59 log (
Error() ,
"Failed to parse file " , aPath.c_str() ,
". PugiXML returned the following description " ,
Quote ( aLoadResult.
description() ) ,
"." );
60 std::size_t lLineCounter ( 1 );
61 std::vector<uint8_t>::const_iterator lIt0 ( aFile.begin() );
62 std::vector<uint8_t>::const_iterator lIt1 ( aFile.begin() + aLoadResult.
offset );
63 std::vector<uint8_t>::const_iterator lIt2 ( lIt1 );
65 for ( ; lIt0!=lIt1 ; ++lIt0 )
73 for ( ; lIt1 != aFile.begin() ; --lIt1 )
82 for ( ; lIt2 != aFile.end() ; ++lIt2 )
91 std::size_t lDist0 ( lIt0 - lIt1 );
92 std::size_t lDist1 ( lIt2 - lIt0 );
94 lLine.reserve ( lIt2 - lIt1 );
96 for ( ; lIt1 != lIt2 ; ++lIt1 )
98 if ( isprint ( *lIt1 ) || *lIt1==10 )
108 log (
Error() ,
"Error occured at line number " ,
Integer ( lLineCounter ) ,
109 ", character " ,
Integer ( lDist0+1 ) ,
"\n"
110 "LINE : " , lLine ,
"\n"
111 "ERROR LOCATION : " , std::string ( lDist0 ,
'_' ) ,
"^" , std::string ( lDist1 ,
'_' ) );
115 template <
bool DebugInfo >
120 if ( ! lAttr.
empty() )
122 aTarget = lAttr.
value();
129 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
140 template <
bool DebugInfo >
145 if ( ! lAttr.
empty() )
147 std::string lAttrStr ( lAttr.
value() );
148 std::stringstream ss;
151 if ( lAttrStr.size() > 2 )
153 if ( ( lAttrStr[1] ==
'x' ) || ( lAttrStr[1] ==
'X' ) )
155 ss << std::hex << lAttrStr.substr ( 2 );
162 else if ( lAttrStr.size() > 1 )
164 if ( ( lAttrStr[0] ==
'x' ) || ( lAttrStr[0] ==
'X' ) )
166 ss << std::hex << lAttrStr.substr ( 1 );
181 if ( ss.str().size() > 10 )
183 exception::StringNumberWillNotFitInto32BitNumber lExc;
184 log ( lExc ,
"XML attribute " ,
Quote ( aAttrName ) ,
" has value " ,
Quote ( ss.str() ) ,
" which is too big to fit into 32-bit number" );
193 exception::StringNumberWillNotFitInto32BitNumber lExc;
194 log ( lExc ,
"XML attribute " ,
Quote ( aAttrName ) ,
" has value " ,
Quote ( ss.str() ) ,
" which is too big to fit into 32-bit number" );
198 aTarget = ( int32_t ) ( lTarget );
205 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
216 template <
bool DebugInfo >
221 if ( ! lAttr.
empty() )
223 std::string lAttrStr ( lAttr.
value() );
224 std::stringstream ss;
226 size_t lBasePrefixLength = 0;
228 if ( lAttrStr.empty() )
229 throw exception::NodeAttributeIncorrectValue(
"XML attribute '" + aAttrName +
"' is empty, so cannot be converted to uint32_t");
232 if ( lAttrStr.size() > 2 )
234 if ( ( lAttrStr[0] ==
'0' ) and ( ( lAttrStr[1] ==
'x' ) or ( lAttrStr[1] ==
'X' ) ) )
236 lBasePrefixLength = 2;
241 if ( lAttrStr.size() > 1 )
243 if ( ( lAttrStr[0] ==
'x' ) || ( lAttrStr[0] ==
'X' ) )
245 lBasePrefixLength = 1;
250 if ( lAttrStr.find_first_not_of(lBasePrefixLength ?
"0123456789abcdefABCDEF" :
"0123456789", lBasePrefixLength) != std::string::npos )
251 throw exception::NodeAttributeIncorrectValue(
"XML attribute '" + aAttrName +
"' has value '" + lAttrStr +
"' that cannot be converted to uint32_t");
253 ss << lAttrStr.substr(lBasePrefixLength);
256 if ( ss.str().size() > 10 )
258 exception::StringNumberWillNotFitInto32BitNumber lExc;
259 log ( lExc ,
"XML attribute " ,
Quote ( aAttrName ) ,
" has value " ,
Quote ( ss.str() ) ,
" which is too big to fit into 32-bit number" );
268 exception::StringNumberWillNotFitInto32BitNumber lExc;
269 log ( lExc ,
"XML attribute " ,
Quote ( aAttrName ) ,
" has value " ,
Quote ( ss.str() ) ,
" which is too big to fit into 32-bit number" );
273 aTarget = ( uint32_t ) ( lTarget );
280 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
291 template <
bool DebugInfo >
296 if ( ! lAttr.
empty() )
305 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
316 template <
bool DebugInfo >
321 if ( ! lAttr.
empty() )
330 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
341 template <
bool DebugInfo >
346 if ( ! lAttr.
empty() )
355 log (
Error() ,
"Failed to get attribute " ,
Quote ( aAttrName ) ,
" from XML node." );
bool as_bool(bool def=false) const
float as_float(float def=0) const
double as_double(double def=0) const
const char_t * value() const
xml_attribute attribute(const char_t *name) const
template bool GetXMLattribute< false >(const pugi::xml_node &aNode, const std::string &aAttrName, std::string &aTarget)
template bool GetXMLattribute< true >(const pugi::xml_node &aNode, const std::string &aAttrName, std::string &aTarget)
bool GetXMLattribute(const pugi::xml_node &aNode, const std::string &aAttrName, std::string &aTarget)
Helper function to retrieve a named attribute from a PugiXML node and cast it to the correct type.
void PugiXMLParseResultPrettifier(const pugi::xml_parse_result &aLoadResult, const boost::filesystem::path &aPath, const std::vector< uint8_t > &aFile)
Helper function to make debugging failures when parsing XML files easier.
_Quote< T > Quote(const T &aT)
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
const char * description() const