Skip to content
Snippets Groups Projects
Commit 0f90d9c4 authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

Merge branch 'MinorXMLHandlerClean' into 'main'

Minor cleaning of the XMLHandler

See merge request !295
parents 5fc6ac02 fa288ef0
No related branches found
No related tags found
1 merge request!295Minor cleaning of the XMLHandler
Pipeline #7014713 failed
......@@ -17,59 +17,68 @@ class XMLHandlerStore;
class XMLHandler {
public:
XMLHandler(std::string n);
virtual ~XMLHandler() {}
std::string GetName() {return m_name;}
virtual void ElementHandle()=0;
virtual void Handle(xercesc::DOMNode *t)
{
SetCurrentElement(t);
ElementHandle();
}
void StopLoop(bool);
bool IsLoopToBeStopped();
virtual void postLoopHandling() {;}
XMLHandler(const std::string& n);
virtual ~XMLHandler() {}
const std::string& GetName() const {return m_name;}
virtual void ElementHandle()=0;
virtual void Handle(xercesc::DOMNode *t)
{
SetCurrentElement(t);
ElementHandle();
}
void StopLoop(bool);
bool IsLoopToBeStopped() const;
virtual void postLoopHandling() {;}
protected:
std::string m_name;
bool m_stopLoop;
std::string m_name;
bool m_stopLoop{false};
static xercesc::DOMNode *s_currentElement;
static void SetCurrentElement(xercesc::DOMNode *t) {s_currentElement=t;}
static xercesc::DOMNode *GetCurrentElement() {return s_currentElement;}
static xercesc::DOMNode *s_currentElement;
static void SetCurrentElement(xercesc::DOMNode *t) {s_currentElement=t;}
static xercesc::DOMNode *GetCurrentElement() {return s_currentElement;}
bool isAttribute(const std::string) const;
bool isAttribute(const std::string& attributeName) const;
std::string getAttribute(const std::string, bool&) const;
std::string getAttributeAsString(const std::string) const;
double getAttributeAsDouble(const std::string) const;
float getAttributeAsFloat(const std::string) const;
int getAttributeAsInt(const std::string) const;
long getAttributeAsLong(const std::string) const;
std::vector<double> getAttributeAsVector(const std::string) const;
std::vector<int> getAttributeAsIntVector(const std::string) const;
std::string getAttributeAsString(const std::string, bool&) const;
double getAttributeAsDouble(const std::string, bool&) const;
float getAttributeAsFloat(const std::string, bool&) const;
int getAttributeAsInt(const std::string, bool&) const;
long getAttributeAsLong(const std::string, bool&) const;
std::vector<double> getAttributeAsVector(const std::string, bool&) const;
std::vector<int> getAttributeAsIntVector(const std::string, bool&) const;
std::string getAttributeAsString(const std::string, const std::string) const;
double getAttributeAsDouble(const std::string, const double) const;
float getAttributeAsFloat(const std::string, const float) const;
int getAttributeAsInt(const std::string, const int) const;
long getAttributeAsLong(const std::string, const long) const;
std::vector<double> getAttributeAsVector(const std::string, const std::vector<double>) const;
std::vector<int> getAttributeAsIntVector(const std::string, const std::vector<int>) const;
static bool s_printFlag;
std::string getAttribute(const std::string& attributeName, bool& attrIsPresent) const;
std::string getAttributeAsString(const std::string& attributeName) const;
double getAttributeAsDouble(const std::string& attributeName) const;
float getAttributeAsFloat(const std::string& attributeName) const;
int getAttributeAsInt(const std::string& attributeName) const;
long getAttributeAsLong(const std::string& attributeName) const;
std::vector<double> getAttributeAsVector(const std::string& attributeName) const;
std::vector<int> getAttributeAsIntVector(const std::string& attributeName) const;
std::string getAttributeAsString(const std::string& attributeName, bool& attrIsPresent) const;
double getAttributeAsDouble(const std::string& attributeName, bool& attrIsPresent) const;
float getAttributeAsFloat(const std::string& attributeName, bool& attrIsPresent) const;
int getAttributeAsInt(const std::string& attributeName, bool& attrIsPresent) const;
long getAttributeAsLong(const std::string& attributeName, bool& attrIsPresent) const;
std::vector<double> getAttributeAsVector(const std::string& attributeName, bool& attrIsPresent) const;
std::vector<int> getAttributeAsIntVector(const std::string& attributeName, bool& attrIsPresent) const;
std::string getAttributeAsString(const std::string& attributeName, const std::string& fallBackVal) const;
double getAttributeAsDouble(const std::string& attributeName, const double fallBackVal) const;
float getAttributeAsFloat(const std::string& attributeName, const float fallBackVal) const;
int getAttributeAsInt(const std::string& attributeName, const int fallBackVal) const;
long getAttributeAsLong(const std::string& attributeName, const long fallBackVal) const;
std::vector<double> getAttributeAsVector(const std::string& attributeName,
const std::vector<double>& fallBackVal) const;
std::vector<int> getAttributeAsIntVector(const std::string& attributeName,
const std::vector<int>& fallBackVal) const;
static bool s_printFlag;
ExpressionEvaluator* Evaluator() const {
static ExpressionEvaluator* eval=ExpressionEvaluator::GetEvaluator();
return eval;
}
ExpressionEvaluator* Evaluator() const
{
static ExpressionEvaluator* eval=ExpressionEvaluator::GetEvaluator();
return eval;
}
private:
void RegisterToStore();
};
} // end namespace
......
......@@ -16,33 +16,24 @@ using namespace GeoModelTools;
DOMNode* XMLHandler::s_currentElement=0;
bool XMLHandler::s_printFlag=false;
XMLHandler::XMLHandler(std::string n):m_name(n) {
XMLHandler::XMLHandler(const std::string& n):m_name(n) {
// std::cout<< " creating new handler "<<n<<std::endl;
m_stopLoop=false;
RegisterToStore();
XMLHandlerStore::GetHandlerStore()->RegisterHandler(this);
}
void XMLHandler::RegisterToStore()
{
XMLHandlerStore::GetHandlerStore()->RegisterHandler(this);
}
void XMLHandler::StopLoop(bool v)
{
void XMLHandler::StopLoop(bool v) {
m_stopLoop=v;
}
bool XMLHandler::IsLoopToBeStopped()
{
bool XMLHandler::IsLoopToBeStopped() const {
return m_stopLoop;
}
bool XMLHandler::isAttribute(const std::string name) const
{
bool XMLHandler::isAttribute(const std::string&name) const {
bool res;
std::string temp=getAttribute(name,res);
return res;
}
std::string XMLHandler::getAttribute(const std::string name, bool& isPresent) const
{
std::string XMLHandler::getAttribute(const std::string&name, bool& isPresent) const {
std::string retValue="";
isPresent=false;
if (s_currentElement->hasAttributes()) {
......@@ -64,8 +55,7 @@ std::string XMLHandler::getAttribute(const std::string name, bool& isPresent) co
}
return retValue;
}
std::string XMLHandler::getAttributeAsString(const std::string name) const
{
std::string XMLHandler::getAttributeAsString(const std::string&name) const {
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
......@@ -73,84 +63,79 @@ std::string XMLHandler::getAttributeAsString(const std::string name) const
}
return temp;
}
double XMLHandler::getAttributeAsDouble(const std::string name) const
{
double res=0.;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
double XMLHandler::getAttributeAsDouble(const std::string&name) const {
double res=0.;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
}
float XMLHandler::getAttributeAsFloat(const std::string name) const
{
float res=0.;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
float XMLHandler::getAttributeAsFloat(const std::string&name) const {
float res=0.;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
}
int XMLHandler::getAttributeAsInt(const std::string name) const
{
int res=0;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
int XMLHandler::getAttributeAsInt(const std::string&name) const {
int res=0;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
}
long XMLHandler::getAttributeAsLong(const std::string name) const
{
long res=0;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
long XMLHandler::getAttributeAsLong(const std::string&name) const {
long res=0;
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
return res;
}
std::vector<double> XMLHandler::getAttributeAsVector(const std::string name) const
{
bool isPresent{false};
std::vector<double> vect;
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
std::vector<double> XMLHandler::getAttributeAsVector(const std::string&name) const {
bool isPresent{false};
std::vector<double> vect;
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
}
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string name) const {
bool isPresent{false};
std::vector<int> vect;
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string&name) const {
bool isPresent{false};
std::vector<int> vect;
std::string temp=getAttribute(name,isPresent);
if (!isPresent) {
THROW_EXCEPTION("--> Attribute '" << name << "' is not present! Check your data!");
}
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
}
std::string XMLHandler::getAttributeAsString(const std::string name, bool& isPresent) const {
std::string XMLHandler::getAttributeAsString(const std::string&name, bool& isPresent) const {
std::string temp=getAttribute(name,isPresent);
return temp;
}
double XMLHandler::getAttributeAsDouble(const std::string name, bool& isPresent) const {
double XMLHandler::getAttributeAsDouble(const std::string&name, bool& isPresent) const {
double res=0.;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
......@@ -158,15 +143,15 @@ double XMLHandler::getAttributeAsDouble(const std::string name, bool& isPresent)
}
return res;
}
float XMLHandler::getAttributeAsFloat(const std::string name, bool& isPresent) const {
float XMLHandler::getAttributeAsFloat(const std::string&name, bool& isPresent) const {
float res=0.;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
res=ExpressionEvaluator::GetEvaluator()->Eval(temp.c_str());
}
return res;
}
int XMLHandler::getAttributeAsInt(const std::string name, bool& isPresent) const {
int XMLHandler::getAttributeAsInt(const std::string&name, bool& isPresent) const {
int res=0;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
......@@ -174,7 +159,7 @@ int XMLHandler::getAttributeAsInt(const std::string name, bool& isPresent) const
}
return res;
}
long XMLHandler::getAttributeAsLong(const std::string name, bool& isPresent) const {
long XMLHandler::getAttributeAsLong(const std::string&name, bool& isPresent) const {
long res=0;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
......@@ -182,11 +167,10 @@ long XMLHandler::getAttributeAsLong(const std::string name, bool& isPresent) con
}
return res;
}
std::vector<double> XMLHandler::getAttributeAsVector(const std::string name, bool& isPresent) const {
std::vector<double> XMLHandler::getAttributeAsVector(const std::string&name, bool& isPresent) const {
std::vector<double> vect;
std::string temp=getAttribute(name,isPresent);
if (isPresent)
{
if (isPresent) {
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
......@@ -195,25 +179,25 @@ std::vector<double> XMLHandler::getAttributeAsVector(const std::string name, boo
return vect;
}
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string name, bool& isPresent) const {
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string&name, bool& isPresent) const {
std::vector<int> vect;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
}
return vect;
}
std::string XMLHandler::getAttributeAsString(const std::string name, const std::string def) const {
std::string XMLHandler::getAttributeAsString(const std::string&name, const std::string&def) const {
bool isPresent{false};
std::string temp=getAttribute(name,isPresent);
if (isPresent) return temp;
else return def;
}
double XMLHandler::getAttributeAsDouble(const std::string name, const double def) const {
double XMLHandler::getAttributeAsDouble(const std::string&name, const double def) const {
bool isPresent{false};
double res=0.;
std::string temp=getAttribute(name,isPresent);
......@@ -223,7 +207,7 @@ double XMLHandler::getAttributeAsDouble(const std::string name, const double def
}
return def;
}
float XMLHandler::getAttributeAsFloat(const std::string name, const float def) const {
float XMLHandler::getAttributeAsFloat(const std::string&name, const float def) const {
bool isPresent{false};
float res=0.;
std::string temp=getAttribute(name,isPresent);
......@@ -233,7 +217,7 @@ float XMLHandler::getAttributeAsFloat(const std::string name, const float def) c
}
return def;
}
int XMLHandler::getAttributeAsInt(const std::string name, const int def) const {
int XMLHandler::getAttributeAsInt(const std::string&name, const int def) const {
bool isPresent{false};
int res=0;
std::string temp=getAttribute(name,isPresent);
......@@ -243,7 +227,7 @@ int XMLHandler::getAttributeAsInt(const std::string name, const int def) const {
}
return def;
}
long XMLHandler::getAttributeAsLong(const std::string name, const long def) const {
long XMLHandler::getAttributeAsLong(const std::string&name, const long def) const {
bool isPresent{false};
long res=0;
std::string temp=getAttribute(name,isPresent);
......@@ -253,7 +237,7 @@ long XMLHandler::getAttributeAsLong(const std::string name, const long def) cons
}
return def;
}
std::vector<double> XMLHandler::getAttributeAsVector(const std::string name, const std::vector<double> def) const {
std::vector<double> XMLHandler::getAttributeAsVector(const std::string&name, const std::vector<double>& def) const {
bool isPresent{false};
std::vector<double> vect{};
std::string temp=getAttribute(name,isPresent);
......@@ -267,16 +251,16 @@ std::vector<double> XMLHandler::getAttributeAsVector(const std::string name, con
return def;
}
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string name, const std::vector<int> def) const {
bool isPresent{false};
std::vector<int> vect;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
}
return def;
std::vector<int> XMLHandler::getAttributeAsIntVector(const std::string&name, const std::vector<int>& def) const {
bool isPresent{false};
std::vector<int> vect;
std::string temp=getAttribute(name,isPresent);
if (isPresent) {
std::vector<std::string> v= GeoStrUtils::tokenize(temp, ";");
for (unsigned int i=0;i<v.size();i++) {
vect.push_back(ExpressionEvaluator::GetEvaluator()->Eval(v[i].c_str()));
}
return vect;
}
return def;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment