| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- #include <OgreStringConverter.h>
- #include "core/Logger.h"
- #include "core/XmlFile.h"
- XmlFile::XmlFile(const Ogre::String& file):
- m_File(file)
- {
- m_File.SetCondenseWhiteSpace(false);
- m_NormalFile = m_File.LoadFile();
- if(m_NormalFile == false)
- {
- LOG_ERROR("Can't open " + file + ". TinyXml Error: " + m_File.ErrorDesc());
- }
- }
- XmlFile::~XmlFile()
- {
- }
- bool
- XmlFile::GetBool(TiXmlNode* node, const Ogre::String& tag, bool def) const
- {
- bool ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseBool(*string);
- }
- }
- return ret;
- }
- int
- XmlFile::GetInt(TiXmlNode* node, const Ogre::String& tag, int def) const
- {
- int ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseInt(*string);
- }
- }
- return ret;
- }
- float
- XmlFile::GetFloat(TiXmlNode* node, const Ogre::String& tag, float def) const
- {
- float ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseReal(*string);
- }
- }
- return ret;
- }
- const Ogre::String
- XmlFile::GetString(TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def) const
- {
- Ogre::String ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = *string;
- }
- }
- return ret;
- }
- const Ogre::UTFString
- XmlFile::GetUTFString(TiXmlNode* node, const Ogre::String& tag, const Ogre::UTFString& def) const
- {
- Ogre::UTFString ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = (*string).c_str();
- }
- }
- return ret;
- }
- const Ogre::Vector2
- XmlFile::GetVector2(TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector2& def) const
- {
- Ogre::Vector2 ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseVector2(*string);
- }
- }
- return ret;
- }
- const Ogre::Vector3
- XmlFile::GetVector3(TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector3& def) const
- {
- Ogre::Vector3 ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseVector3(*string);
- }
- }
- return ret;
- }
- const Ogre::Vector4
- XmlFile::GetVector4(TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector4& def) const
- {
- Ogre::Vector4 ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseVector4(*string);
- }
- }
- return ret;
- }
- const Ogre::Matrix4
- XmlFile::GetMatrix4(TiXmlNode* node, const Ogre::String& tag, const Ogre::Matrix4& def) const
- {
- Ogre::Matrix4 ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseMatrix4(*string);
- }
- }
- return ret;
- }
- const Ogre::Quaternion
- XmlFile::GetQuaternion(TiXmlNode* node, const Ogre::String& tag, const Ogre::Quaternion& def) const
- {
- Ogre::Quaternion ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseQuaternion(*string);
- }
- }
- return ret;
- }
- const Ogre::ColourValue
- XmlFile::GetColourValue(TiXmlNode* node, const Ogre::String& tag, const Ogre::ColourValue& def) const
- {
- Ogre::ColourValue ret = def;
- if(node->Type() == TiXmlNode::TINYXML_ELEMENT)
- {
- const std::string* string = node->ToElement()->Attribute(tag);
- if(string != nullptr)
- {
- ret = Ogre::StringConverter::parseColourValue(*string);
- }
- }
- return ret;
- }
|