Add project files.
This commit is contained in:
parent
18b81590d3
commit
045f3a8439
15 changed files with 1303019 additions and 0 deletions
59
lib/osmparser/src/util.cpp
Normal file
59
lib/osmparser/src/util.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <util.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <tinyxml2.h>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
#define FAILED(err) (err != xml::XML_SUCCESS)
|
||||
|
||||
std::string GetSafeAttributeString(const tinyxml2::XMLElement* elem, const std::string& name)
|
||||
{
|
||||
const char* buffer;
|
||||
|
||||
xml::XMLError result = elem->QueryStringAttribute(name.c_str(), &buffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
std::cerr << "Failed to fetch string attribute \"" << name << "\"" << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string returnStr(buffer);
|
||||
return returnStr;
|
||||
}
|
||||
|
||||
float GetSafeAttributeFloat(const tinyxml2::XMLElement* elem, const std::string& name)
|
||||
{
|
||||
float returnVal = 0.0f;
|
||||
|
||||
xml::XMLError result = elem->QueryFloatAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch float attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
unsigned int GetSafeAttributeUint(const tinyxml2::XMLElement* elem, const std::string& name)
|
||||
{
|
||||
unsigned int returnVal = 0;
|
||||
|
||||
xml::XMLError result = elem->QueryUnsignedAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch uint attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool GetSafeAttributeBool(const tinyxml2::XMLElement* elem, const std::string& name)
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
xml::XMLError result = elem->QueryBoolAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch bool attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue