00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "Globals.h"
00025 #include "external/tinyxml/tinyxml.h"
00026
00027 namespace verve
00028 {
00029 namespace globals
00030 {
00031 real VERVE_CALL getAttributeReal(const TiXmlNode* nodePtr,
00032 const std::string& name)
00033 {
00034 TiXmlElement* elementPtr =
00035 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00036 double temp = 0;
00037
00038 if (NULL == elementPtr->Attribute(name.c_str(), &temp))
00039 {
00040 VERVE_LOGGER("warning") <<
00041 "verve::globals::getAttributeReal: Element "
00042 << nodePtr->Value() << " is missing attribute '"
00043 << name << "'. Parameter will be set to '0.0'."
00044 << std::endl;
00045 return 0;
00046 }
00047 else
00048 {
00049 return (real)temp;
00050 }
00051 }
00052
00053 int VERVE_CALL getAttributeInt(const TiXmlNode* nodePtr,
00054 const std::string& name)
00055 {
00056 TiXmlElement* elementPtr =
00057 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00058 int temp = 0;
00059
00060 if (NULL == elementPtr->Attribute(name.c_str(), &temp))
00061 {
00062 VERVE_LOGGER("warning") <<
00063 "verve::globals::getAttributeInt: Element "
00064 << nodePtr->Value() << " is missing attribute '"
00065 << name << "'. Parameter will be set to '0'."
00066 << std::endl;
00067 return 0;
00068 }
00069 else
00070 {
00071 return temp;
00072 }
00073 }
00074
00075 bool VERVE_CALL getAttributeBool(const TiXmlNode* nodePtr,
00076 const std::string& name)
00077 {
00078 TiXmlElement* elementPtr =
00079 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00080 const char* temp = elementPtr->Attribute(name.c_str());
00081
00082 if (NULL == temp)
00083 {
00084 VERVE_LOGGER("warning") <<
00085 "verve::globals::getAttributeBool: Element "
00086 << nodePtr->Value() << " is missing attribute '"
00087 << name << "'. Parameter will be set to 'false'."
00088 << std::endl;
00089 return false;
00090 }
00091 else
00092 {
00093 std::string value = temp;
00094 if ("true" == value || "1" == value)
00095 {
00096 return true;
00097 }
00098 else if ("false" == value || "0" == value)
00099 {
00100 return false;
00101 }
00102 else
00103 {
00104 VERVE_LOGGER("warning") <<
00105 "verve::globals::getAttributeBool: Element "
00106 << nodePtr->Value() << " attribute '" << name
00107 << "' has an invalid value. Possible "
00108 << "values are 'true', 'false', '1', and '0'. "
00109 << "Parameter will be set to 'false'." << std::endl;
00110 return false;
00111 }
00112 }
00113 }
00114
00115 std::string VERVE_CALL getAttributeString(const TiXmlNode* nodePtr,
00116 const std::string& name)
00117 {
00118 TiXmlElement* elementPtr =
00119 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00120 const char* temp = elementPtr->Attribute(name.c_str());
00121
00122 if (NULL == temp)
00123 {
00124 VERVE_LOGGER("warning") <<
00125 "verve::globals::getAttributeString: Element "
00126 << nodePtr->Value() << " is missing attribute '"
00127 << name << "'. Parameter will be set to \"\"."
00128 << std::endl;
00129 return "";
00130 }
00131 else
00132 {
00133 return temp;
00134 }
00135 }
00136 }
00137 }