Base: [skip ci] in XMLReader class replace assert(0) calls with throwing an XMLAttributeError exception

This commit is contained in:
wmayer
2020-06-07 14:23:53 +02:00
parent ae641dc527
commit b0e92abcb5

View File

@@ -130,39 +130,45 @@ long Base::XMLReader::getAttributeAsInteger(const char* AttrName) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end())
if (pos != AttrMap.end()) {
return atol(pos->second.c_str());
else
}
else {
// wrong name, use hasAttribute if not sure!
assert(0);
return 0;
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
}
unsigned long Base::XMLReader::getAttributeAsUnsigned(const char* AttrName) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end())
if (pos != AttrMap.end()) {
return strtoul(pos->second.c_str(),0,10);
else
}
else {
// wrong name, use hasAttribute if not sure!
assert(0);
return 0;
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
}
double Base::XMLReader::getAttributeAsFloat (const char* AttrName) const
{
AttrMapType::const_iterator pos = AttrMap.find(AttrName);
if (pos != AttrMap.end())
if (pos != AttrMap.end()) {
return atof(pos->second.c_str());
else
}
else {
// wrong name, use hasAttribute if not sure!
assert(0);
return 0.0;
std::ostringstream msg;
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
}
const char* Base::XMLReader::getAttribute (const char* AttrName) const