Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
simpleparameter.h
Go to the documentation of this file.
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/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWSaveLoad *
24 * *
25 * $Archive:: /Commando/Code/wwsaveload/simpleparameter.h $*
26 * *
27 * Author:: Patrick Smith *
28 * *
29 * $Modtime:: 7/16/01 11:12a $*
30 * *
31 * $Revision:: 17 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42
43
44
45#ifndef __SIMPLE_PARAMETER_H
46#define __SIMPLE_PARAMETER_H
47
48#include "always.h"
49#include "parameter.h"
50#include "vector2.h"
51#include "vector3.h"
52#include "matrix3d.h"
53#include "rect.h"
54#include <float.h>
55
56
58//
59// SimpleParameterClass
60//
62template <class T, ParameterClass::Type type>
64{
65public:
66
68 // Public constructors/destructors
70 SimpleParameterClass (void *data, const char *name);
71
73 // Public operators
75 bool operator== (const ParameterClass &src);
76
78 // Public methods
80 const T & Get_Value (void) const;
81 void Set_Value (const T &new_value);
82
83 // From Parameter class
85 void Copy_Value (const ParameterClass &src);
86
87private:
88
90 // Private member data
92 T * m_Data;
93 T m_Min;
94 T m_Max;
95};
96
98// SimpleParameterClass
100template <class T, ParameterClass::Type type> inline
102{
103 Set_Name (name);
104 m_Data = (T *)data;
105 return ;
106}
107
109// Get_Value
111template <class T, ParameterClass::Type type> inline bool
113{
114 bool retval = false;
115 if (src.Get_Type () == Get_Type ()) {
116 retval = ((*m_Data) == *(((const SimpleParameterClass &)src).m_Data));
117 }
118
119 return retval;
120}
121
123// Get_Value
125template <class T, ParameterClass::Type type> inline const T &
127{
128 return (*m_Data);
129}
130
132// Set_Value
134template <class T, ParameterClass::Type type> inline void
136{
137 (*m_Data) = new_value;
138 Set_Modified ();
139 return ;
140}
141
143// Get_Type
145template <class T, ParameterClass::Type type> inline ParameterClass::Type
147{
148 return type;
149}
150
152// Copy_Value
154template <class T, ParameterClass::Type type> inline void
156{
157 if (Get_Type () == src.Get_Type ()) {
158 (*m_Data) = ((SimpleParameterClass<T, type> &)src).Get_Value ();
159 }
160
162 return ;
163}
164
166//
167// Simple parameter types
168//
177
178
180//
181// RangedParameterClass
182//
183// Extends simple paramter types so they can have minimum/maximum values.
184//
186template <class T, ParameterClass::Type type>
188{
189public:
191 // Public constructors/destructors
193 RangedParameterClass (void *data, const char *name)
194 : SimpleParameterClass<T, type> (data, name) { }
195
197 // Public methods
199 void Set_Range (const T &min, const T &max) { m_Min = min; m_Max = max; }
200 const T & Get_Min (void) const { return m_Min; }
201 const T & Get_Max (void) const { return m_Max; }
202
203private:
204
206 // Private member data
208 T m_Min;
209 T m_Max;
210};
211
212
214// IntParameterClass
216class IntParameterClass : public RangedParameterClass<int, ParameterClass::TYPE_INT>
217{
218public:
219 IntParameterClass (void *data, const char *name)
220 : RangedParameterClass<int, ParameterClass::TYPE_INT> (data, name)
221 { Set_Range (-1000000000L, 1000000000L); }
222};
223
225// FloatParameterClass
227class FloatParameterClass : public RangedParameterClass<float, ParameterClass::TYPE_FLOAT>
228{
229public:
230 FloatParameterClass (void *data, const char *name)
231 : RangedParameterClass<float, ParameterClass::TYPE_FLOAT> (data, name)
232 { Set_Range (-100000.0F, 100000.0F); }
233};
234
236// AngleParameterClass
238class AngleParameterClass : public RangedParameterClass<float, ParameterClass::TYPE_ANGLE>
239{
240public:
241 AngleParameterClass (void *data, const char *name)
242 : RangedParameterClass<float, ParameterClass::TYPE_ANGLE> (data, name)
243 { Set_Range (0.0F, 6.283185307F); }
244};
245
246#endif //__SIMPLE_PARAMETER_H
247
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
AngleParameterClass(void *data, const char *name)
FloatParameterClass(void *data, const char *name)
IntParameterClass(void *data, const char *name)
virtual void Set_Modified(bool onoff=true)
Definition parameter.h:133
virtual void Copy_Value(const ParameterClass &src)
Definition parameter.h:144
ParameterClass(void)
Definition parameter.h:168
virtual void Set_Name(const char *new_name)
Definition parameter.h:221
virtual Type Get_Type(void) const =0
const T & Get_Max(void) const
const T & Get_Min(void) const
RangedParameterClass(void *data, const char *name)
void Set_Range(const T &min, const T &max)
const T & Get_Value(void) const
void Copy_Value(const ParameterClass &src)
void Set_Value(const T &new_value)
bool operator==(const ParameterClass &src)
ParameterClass::Type Get_Type(void) const
SimpleParameterClass(void *data, const char *name)
else return(RetVal)
SimpleParameterClass< Vector2, ParameterClass::TYPE_VECTOR2 > Vector2ParameterClass
SimpleParameterClass< Vector3, ParameterClass::TYPE_VECTOR3 > Vector3ParameterClass
SimpleParameterClass< RectClass, ParameterClass::TYPE_RECT > RectParameterClass
SimpleParameterClass< Vector3, ParameterClass::TYPE_COLOR > ColorParameterClass
SimpleParameterClass< int, ParameterClass::TYPE_STRINGSDB_ID > StringsDBEntryParameterClass
SimpleParameterClass< bool, ParameterClass::TYPE_BOOL > BoolParameterClass
SimpleParameterClass< Matrix3D, ParameterClass::TYPE_MATRIX3D > Matrix3DParameterClass