ConfigVar.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <OgreString.h>
  17. class ConfigVarManager;
  18. /**
  19. * A configuration variable
  20. */
  21. class ConfigVar{
  22. friend class ConfigVarManager;
  23. public:
  24. /**
  25. * Constructor.
  26. *
  27. * @param name[in] The variable name.
  28. * @param description[in] A human-friendly description for the
  29. * variable.
  30. * @param default_value[in] The default value for the variable.
  31. */
  32. ConfigVar(
  33. const Ogre::String& name, const Ogre::String& description,
  34. const Ogre::String& default_value
  35. );
  36. /**
  37. * Retrieves the value of the variable in integer form.
  38. *
  39. * @return The variable value.
  40. */
  41. int GetI() const;
  42. /**
  43. * Retrieves the value of the variable in float form.
  44. *
  45. * @return The variable value.
  46. */
  47. float GetF() const;
  48. /**
  49. * Retrieves the value of the variable in boolean form.
  50. *
  51. * @return The variable value.
  52. */
  53. bool GetB() const;
  54. /**
  55. * Retrieves the value of the variable in string form.
  56. *
  57. * @return The variable value.
  58. */
  59. Ogre::String GetS() const;
  60. /**
  61. * Sets the integer value of the variable.
  62. *
  63. * @param value[in] The variable value.
  64. */
  65. void SetI(int value);
  66. /**
  67. * Sets the float value of the variable.
  68. *
  69. * @param value[in] The variable value.
  70. */
  71. void SetF(float value);
  72. /**
  73. * Sets the boolean value of the variable.
  74. *
  75. * @param value[in] The variable value.
  76. */
  77. void SetB(bool value);
  78. /**
  79. * Sets the string value of the variable.
  80. *
  81. * @param value[in] The variable value.
  82. */
  83. void SetS(const Ogre::String& value);
  84. /**
  85. * Retrieves the variable name.
  86. *
  87. * @return The variable name.
  88. */
  89. const Ogre::String& GetName() const;
  90. /**
  91. * Retrieves the variable description.
  92. *
  93. * @return The variable description.
  94. */
  95. const Ogre::String& GetDescription() const;
  96. /**
  97. * Retrieves the variable default value.
  98. *
  99. * @return The variable default value.
  100. */
  101. const Ogre::String& GetDefaultValue() const;
  102. /**
  103. * Updates the integer and float values from the string value.
  104. */
  105. void UpdateVariables();
  106. private:
  107. /**
  108. * Forbidden copy constructor.
  109. */
  110. ConfigVar(const ConfigVar&) = delete;
  111. /**
  112. * Forbidden copy constructor.
  113. */
  114. ConfigVar&operator=(const ConfigVar&) = delete;
  115. /**
  116. * The variable name.
  117. */
  118. Ogre::String name_;
  119. /**
  120. * The variable description.
  121. */
  122. Ogre::String description_;
  123. /**
  124. * The variable default value.
  125. */
  126. Ogre::String default_value_;
  127. /**
  128. * Variable value, integer format.
  129. */
  130. int value_i_;
  131. /**
  132. * Variable value, float format.
  133. */
  134. float value_f_;
  135. /**
  136. * Variable value, integer format.
  137. */
  138. bool value_b_;
  139. /**
  140. * Variable value, string format.
  141. */
  142. Ogre::String value_s_;
  143. /**
  144. * @todo Understand and document.
  145. */
  146. ConfigVar* previous_;
  147. /**
  148. * @todo Understand and document.
  149. */
  150. static ConfigVar* static_config_var_list_;
  151. };