XmlFile.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreColourValue.h>
  17. #include <OgreMatrix4.h>
  18. #include <OgreString.h>
  19. #include <Ogre.h>
  20. #include <Overlay/OgreUTFString.h>
  21. #include <tinyxml.h>
  22. /**
  23. * Handles XML files.
  24. */
  25. class XmlFile{
  26. public:
  27. /**
  28. * Constructor.
  29. *
  30. * @param file[in] Path to the XML file.
  31. */
  32. XmlFile(const Ogre::String& file);
  33. /**
  34. * Destructor.
  35. */
  36. virtual ~XmlFile();
  37. /**
  38. * Retrieves a boolean from an XMl tag.
  39. *
  40. * @param node[in] The XML node.
  41. * @param tag[in] The name of the tag.
  42. * @param def[in] Default value, in case the tag is not found or it's
  43. * not a boolean value.
  44. * @return Boolean value of the tag. If it's not found or it's not a
  45. * boolean, def is returned.
  46. */
  47. bool GetBool(
  48. TiXmlNode* node, const Ogre::String& tag, bool def = false
  49. ) const;
  50. /**
  51. * Retrieves an integer from an XMl tag.
  52. *
  53. * @param node[in] The XML node.
  54. * @param tag[in] The name of the tag.
  55. * @param def[in] Default value, in case the tag is not found or it's
  56. * not a numeric value.
  57. * @return Integer value of the tag. If it's not found or it's not a
  58. * number, def is returned.
  59. */
  60. int GetInt(TiXmlNode* node, const Ogre::String& tag, int def = 0) const;
  61. /**
  62. * Retrieves a defcimal from an XMl tag.
  63. *
  64. * @param node[in] The XML node.
  65. * @param tag[in] The name of the tag.
  66. * @param def[in] Default value, in case the tag is not found or it's
  67. * not a numeric value.
  68. * @return Decimal value of the tag. If it's not found or it's not a
  69. * number, def is returned.
  70. */
  71. float GetFloat(
  72. TiXmlNode* node, const Ogre::String& tag, float def = 0.0f
  73. ) const;
  74. /**
  75. * Retrieves a string from an XMl tag.
  76. *
  77. * @param node[in] The XML node.
  78. * @param tag[in] The name of the tag.
  79. * @param def[in] Default value, in case the tag is not found.
  80. * @return String value of the tag. If it's not found, def is returned.
  81. */
  82. const Ogre::String GetString(
  83. TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def = ""
  84. ) const;
  85. /**
  86. * Retrieves a string from an XMl tag.
  87. *
  88. * @param node[in] The XML node.
  89. * @param tag[in] The name of the tag.
  90. * @param def[in] Default value, in case the tag is not found.
  91. * @return String value of the tag, in UFT8. If not found, def is
  92. * returned.
  93. */
  94. const Ogre::UTFString GetUTFString(
  95. TiXmlNode* node, const Ogre::String& tag,
  96. const Ogre::UTFString& def = ""
  97. ) const;
  98. /**
  99. * Retrieves a 2-dimensional vector from an XMl tag.
  100. *
  101. * @param node[in] The XML node.
  102. * @param tag[in] The name of the tag.
  103. * @param def[in] Default value, in case the tag is not found.
  104. * @return Vector in the tag. If it's not found, def is returned.
  105. */
  106. const Ogre::Vector2 GetVector2(
  107. TiXmlNode* node, const Ogre::String& tag,
  108. const Ogre::Vector2& def = Ogre::Vector2::ZERO
  109. ) const;
  110. /**
  111. * Retrieves a 3-dimensional vector from an XMl tag.
  112. *
  113. * @param node[in] The XML node.
  114. * @param tag[in] The name of the tag.
  115. * @param def[in] Default value, in case the tag is not found.
  116. * @return Vector in the tag. If it's not found, def is returned.
  117. */
  118. const Ogre::Vector3 GetVector3(
  119. TiXmlNode* node, const Ogre::String& tag,
  120. const Ogre::Vector3& def = Ogre::Vector3::ZERO
  121. ) const;
  122. /**
  123. * Retrieves a 4-dimensional vector from an XMl tag.
  124. *
  125. * @param node[in] The XML node.
  126. * @param tag[in] The name of the tag.
  127. * @param def[in] Default value, in case the tag is not found.
  128. * @return Vector in the tag. If it's not found, def is returned.
  129. */
  130. const Ogre::Vector4 GetVector4(
  131. TiXmlNode* node, const Ogre::String& tag,
  132. const Ogre::Vector4& def = Ogre::Vector4::ZERO
  133. ) const;
  134. /**
  135. * Retrieves a 4-dimensional matrix from an XMl tag.
  136. *
  137. * @param node[in] The XML node.
  138. * @param tag[in] The name of the tag.
  139. * @param def[in] Default value, in case the tag is not found.
  140. * @return The matrix in the tag. If it's not found, def is returned.
  141. */
  142. const Ogre::Matrix4 GetMatrix4(
  143. TiXmlNode* node, const Ogre::String& tag,
  144. const Ogre::Matrix4& def = Ogre::Matrix4::IDENTITY
  145. ) const;
  146. /**
  147. * Retrieves a quaternion from an XMl tag.
  148. *
  149. * @param node[in] The XML node.
  150. * @param tag[in] The name of the tag.
  151. * @param def[in] Default value, in case the tag is not found.
  152. * @return Quaternion in the tag. If it's not found, def is returned.
  153. */
  154. const Ogre::Quaternion GetQuaternion(
  155. TiXmlNode* node, const Ogre::String& tag,
  156. const Ogre::Quaternion& def = Ogre::Quaternion::IDENTITY
  157. ) const;
  158. /**
  159. * Retrieves a colour from an XMl tag.
  160. *
  161. * @param node[in] The XML node.
  162. * @param tag[in] The name of the tag.
  163. * @param def[in] Default value, in case the tag is not found.
  164. * @return Colour in the tag. If it's not found, def is returned.
  165. */
  166. const Ogre::ColourValue GetColourValue(
  167. TiXmlNode* node, const Ogre::String& tag,
  168. const Ogre::ColourValue& def = Ogre::ColourValue::ZERO
  169. ) const;
  170. protected:
  171. /**
  172. * Indicates if the file is a normal file.
  173. *
  174. * @todo As opposed to what?
  175. */
  176. bool normal_file_;
  177. /**
  178. * The XML file.
  179. */
  180. TiXmlDocument file_;
  181. };