simpleparameter.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWSaveLoad *
  23. * *
  24. * $Archive:: /Commando/Code/wwsaveload/simpleparameter.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 7/16/01 11:12a $*
  29. * *
  30. * $Revision:: 17 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __SIMPLE_PARAMETER_H
  39. #define __SIMPLE_PARAMETER_H
  40. #include "always.h"
  41. #include "parameter.h"
  42. #include "vector2.h"
  43. #include "vector3.h"
  44. #include "matrix3d.h"
  45. #include "rect.h"
  46. #include <float.h>
  47. //////////////////////////////////////////////////////////////////////////////////
  48. //
  49. // SimpleParameterClass
  50. //
  51. //////////////////////////////////////////////////////////////////////////////////
  52. template <class T, ParameterClass::Type type>
  53. class SimpleParameterClass : public ParameterClass
  54. {
  55. public:
  56. ///////////////////////////////////////////////////////////////////////
  57. // Public constructors/destructors
  58. ///////////////////////////////////////////////////////////////////////
  59. SimpleParameterClass (void *data, const char *name);
  60. //////////////////////////////////////////////////////////////////////////////
  61. // Public operators
  62. //////////////////////////////////////////////////////////////////////////////
  63. bool operator== (const ParameterClass &src);
  64. ///////////////////////////////////////////////////////////////////////
  65. // Public methods
  66. ///////////////////////////////////////////////////////////////////////
  67. const T & Get_Value (void) const;
  68. void Set_Value (const T &new_value);
  69. // From Parameter class
  70. ParameterClass::Type Get_Type (void) const;
  71. void Copy_Value (const ParameterClass &src);
  72. private:
  73. ///////////////////////////////////////////////////////////////////////
  74. // Private member data
  75. ///////////////////////////////////////////////////////////////////////
  76. T * m_Data;
  77. T m_Min;
  78. T m_Max;
  79. };
  80. //////////////////////////////////////////////////////////////////////////////////
  81. // SimpleParameterClass
  82. //////////////////////////////////////////////////////////////////////////////////
  83. template <class T, ParameterClass::Type type> inline
  84. SimpleParameterClass<T, type>::SimpleParameterClass (void *data, const char *name)
  85. {
  86. Set_Name (name);
  87. m_Data = (T *)data;
  88. return ;
  89. }
  90. //////////////////////////////////////////////////////////////////////////////////
  91. // Get_Value
  92. //////////////////////////////////////////////////////////////////////////////////
  93. template <class T, ParameterClass::Type type> inline bool
  94. SimpleParameterClass<T, type>::operator== (const ParameterClass &src)
  95. {
  96. bool retval = false;
  97. if (src.Get_Type () == Get_Type ()) {
  98. retval = ((*m_Data) == *(((const SimpleParameterClass &)src).m_Data));
  99. }
  100. return retval;
  101. }
  102. //////////////////////////////////////////////////////////////////////////////////
  103. // Get_Value
  104. //////////////////////////////////////////////////////////////////////////////////
  105. template <class T, ParameterClass::Type type> inline const T &
  106. SimpleParameterClass<T, type>::Get_Value (void) const
  107. {
  108. return (*m_Data);
  109. }
  110. //////////////////////////////////////////////////////////////////////////////////
  111. // Set_Value
  112. //////////////////////////////////////////////////////////////////////////////////
  113. template <class T, ParameterClass::Type type> inline void
  114. SimpleParameterClass<T, type>::Set_Value (const T &new_value)
  115. {
  116. (*m_Data) = new_value;
  117. Set_Modified ();
  118. return ;
  119. }
  120. //////////////////////////////////////////////////////////////////////////////////
  121. // Get_Type
  122. //////////////////////////////////////////////////////////////////////////////////
  123. template <class T, ParameterClass::Type type> inline ParameterClass::Type
  124. SimpleParameterClass<T, type>::Get_Type (void) const
  125. {
  126. return type;
  127. }
  128. //////////////////////////////////////////////////////////////////////////////////
  129. // Copy_Value
  130. //////////////////////////////////////////////////////////////////////////////////
  131. template <class T, ParameterClass::Type type> inline void
  132. SimpleParameterClass<T, type>::Copy_Value (const ParameterClass &src)
  133. {
  134. if (Get_Type () == src.Get_Type ()) {
  135. (*m_Data) = ((SimpleParameterClass<T, type> &)src).Get_Value ();
  136. }
  137. ParameterClass::Copy_Value (src);
  138. return ;
  139. }
  140. //////////////////////////////////////////////////////////////////////////////////
  141. //
  142. // Simple parameter types
  143. //
  144. //////////////////////////////////////////////////////////////////////////////////
  145. typedef SimpleParameterClass<bool, ParameterClass::TYPE_BOOL> BoolParameterClass;
  146. typedef SimpleParameterClass<Vector2, ParameterClass::TYPE_VECTOR2> Vector2ParameterClass;
  147. typedef SimpleParameterClass<Vector3, ParameterClass::TYPE_VECTOR3> Vector3ParameterClass;
  148. typedef SimpleParameterClass<Matrix3D, ParameterClass::TYPE_MATRIX3D> Matrix3DParameterClass;
  149. typedef SimpleParameterClass<RectClass,ParameterClass::TYPE_RECT> RectParameterClass;
  150. typedef SimpleParameterClass<Vector3, ParameterClass::TYPE_COLOR > ColorParameterClass;
  151. typedef SimpleParameterClass<int, ParameterClass::TYPE_STRINGSDB_ID> StringsDBEntryParameterClass;
  152. //////////////////////////////////////////////////////////////////////////////////
  153. //
  154. // RangedParameterClass
  155. //
  156. // Extends simple paramter types so they can have minimum/maximum values.
  157. //
  158. //////////////////////////////////////////////////////////////////////////////////
  159. template <class T, ParameterClass::Type type>
  160. class RangedParameterClass : public SimpleParameterClass<T, type>
  161. {
  162. public:
  163. ///////////////////////////////////////////////////////////////////////
  164. // Public constructors/destructors
  165. ///////////////////////////////////////////////////////////////////////
  166. RangedParameterClass (void *data, const char *name)
  167. : SimpleParameterClass<T, type> (data, name) { }
  168. ///////////////////////////////////////////////////////////////////////
  169. // Public methods
  170. ///////////////////////////////////////////////////////////////////////
  171. void Set_Range (const T &min, const T &max) { m_Min = min; m_Max = max; }
  172. const T & Get_Min (void) const { return m_Min; }
  173. const T & Get_Max (void) const { return m_Max; }
  174. private:
  175. ///////////////////////////////////////////////////////////////////////
  176. // Private member data
  177. ///////////////////////////////////////////////////////////////////////
  178. T m_Min;
  179. T m_Max;
  180. };
  181. //////////////////////////////////////////////////////////////////////////////////
  182. // IntParameterClass
  183. //////////////////////////////////////////////////////////////////////////////////
  184. class IntParameterClass : public RangedParameterClass<int, ParameterClass::TYPE_INT>
  185. {
  186. public:
  187. IntParameterClass (void *data, const char *name)
  188. : RangedParameterClass<int, ParameterClass::TYPE_INT> (data, name)
  189. { Set_Range (-1000000000L, 1000000000L); }
  190. };
  191. //////////////////////////////////////////////////////////////////////////////////
  192. // FloatParameterClass
  193. //////////////////////////////////////////////////////////////////////////////////
  194. class FloatParameterClass : public RangedParameterClass<float, ParameterClass::TYPE_FLOAT>
  195. {
  196. public:
  197. FloatParameterClass (void *data, const char *name)
  198. : RangedParameterClass<float, ParameterClass::TYPE_FLOAT> (data, name)
  199. { Set_Range (-100000.0F, 100000.0F); }
  200. };
  201. //////////////////////////////////////////////////////////////////////////////////
  202. // AngleParameterClass
  203. //////////////////////////////////////////////////////////////////////////////////
  204. class AngleParameterClass : public RangedParameterClass<float, ParameterClass::TYPE_ANGLE>
  205. {
  206. public:
  207. AngleParameterClass (void *data, const char *name)
  208. : RangedParameterClass<float, ParameterClass::TYPE_ANGLE> (data, name)
  209. { Set_Range (0.0F, 6.283185307F); }
  210. };
  211. #endif //__SIMPLE_PARAMETER_H