My Project
Type.h
1 #pragma once
2 #include <string>
3 #include <map>
4 #include <float.h>
5 using namespace std;
6 
7 namespace ParaEngine
8 {
9  enum TYPE_ENUMERATION
10  {
11  Type_void,
12  Type_Int,
13  Type_Bool,
14  Type_Float,
15  Type_Enum,
16  Type_Double,
17  Type_Vector2,
18  Type_Vector3,
19  Type_Vector4,
20  Type_String,
21  Type_GUIRoot,
22  Type_GUIText,
23  Type_GUIVideo,
24  Type_GUIButton,
25  Type_GUIEditBox,
26  Type_GUIIMEEditBox,
27  Type_GUIScrollBar,
28  Type_GUIListBox,
29  Type_GUIToolTip,
30  Type_GUIPainter,
31  Type_GUISlider,
32  Type_GUIGrid,
33  Type_GUICanvas,
34  Type_GUIContainer,
35  Type_GUIWebBrowser,
36  };
37 
38  enum ITYPE_VERIFY_RESULT
39  {
40  Verify_Success=0,
41  Verify_Overflow=1,
42  Verify_Underflow=2,
43  Verify_OutOfRange=3,
44  Verify_Unknown=4,
45  Verify_Failed=0xffffffff
46  };
47  class IType;
48  //This is a singleton
50  {
51  public:
52  //initialize the types, adding void, int, bool, float, double, string etc. to the manager
53  CTypeManager();
54  //delete all instance
55  ~CTypeManager();
56  //return a type pointer to the required type, null if not exists. Do NOT delete the return pointer.
57  IType* GetType(const char* szTypeName)const;
62  bool SetType(IType* pType);
63  static void ReleaseType(IType* pType);
64  protected:
65  map<string,IType*> m_types;
66  };
67 
75  class IType
76  {
77  public:
78  virtual const char* GetTypeName()const=0;
79  virtual int Verify(const char* input)const=0;
80  static IType* GetType(const char* szTypeName);
81  IType* GetType()const;
82  int GetTypeValue()const{return m_etype;}
83  friend class CTypeManager;
84  virtual bool operator ==(int value)const
85  {
86  return m_etype==value;
87  }
88  virtual bool operator ==(const char *szTypeName)const;
89  virtual bool operator ==(const IType& value)const
90  {
91  return m_etype==value.m_etype;
92  }
93  protected:
94  int m_etype;//TYPE_ENUMERATION
95  virtual ~IType(){}
96  };
97  class CDataInt32;
98  class CDataFloat;
99  class CDataBool;
100 
101  class CVoid:public IType
102  {
103  public:
104  static const char TypeName[];
105  CVoid(){m_etype=Type_void;}
106  virtual const char* GetTypeName()const
107  {
108  return TypeName;
109  }
110  virtual int Verify(const char* input)const
111  {
112  return input==NULL?Verify_Unknown:Verify_Success;
113  }
114  protected:
115  virtual ~CVoid(){}
116  };
117 
118  class CBool:public IType
119  {
120  public:
121  static const char TypeName[];
122  CBool(){m_etype=Type_Bool;}
123  virtual const char* GetTypeName()const
124  {
125  return TypeName;
126  }
127  static bool Parse(const char* input);
128  virtual int Verify(const char* input)const;
129  protected:
130  virtual ~CBool(){}
131  };
132 
133  class CInt32:public IType
134  {
135  public:
136  static const char TypeName[];
137  CInt32(){m_etype=Type_Int;}
138  static const int MaxValue;
139  static const int MinValue;
140  static int Parse(const char* input);
141  virtual const char* GetTypeName()const
142  {
143  return TypeName;
144  }
145  virtual int Verify(const char* input)const;
146  protected:
147  virtual ~CInt32(){}
148  };
149 
150  class CFloat:public IType
151  {
152  public:
153  static const char TypeName[];
154  /*static const float MaxValue;
155  static const float MinValue;*/
156  CFloat(){m_etype=Type_Float;}
157  virtual const char* GetTypeName()const
158  {
159  return TypeName;
160  }
161  static float Parse(const char* input);
162  virtual int Verify(const char* input)const;
163  protected:
164  virtual ~CFloat(){}
165  };
166 
167  class CDouble:public IType
168  {
169  public:
170  static const char TypeName[];
171  static const double MaxValue;
172  static const double MinValue;
173  CDouble(){m_etype=Type_Double;}
174  virtual const char* GetTypeName()const
175  {
176  return TypeName;
177  }
178  static double Parse(const char* input);
179  virtual int Verify(const char* input)const;
180  protected:
181  virtual ~CDouble(){}
182  };
183 
184  class CStr:public IType
185  {
186  public:
187  static const char TypeName[];
188  CStr(){m_etype=Type_String;}
189  virtual const char* GetTypeName()const
190  {
191  return TypeName;
192  }
193  virtual int Verify(const char* input)const;
194  protected:
195  virtual ~CStr(){}
196  };
197 
198  class CDataInt32 : public IObject
199  {
200  public:
201  CDataInt32():m_data(0)
202  {
203  if (!m_type){
204  m_type=IType::GetType("int");
205  }
206  };
207  CDataInt32(int data):m_data(data)
208  {
209  if (!m_type){
210  m_type=IType::GetType("int");
211  }
212  }
213  virtual ~CDataInt32(){};
214  IObject* Clone()const{return new CDataInt32(m_data);}
215  void Clone(IObject* obj)const{((CDataInt32*)obj)->m_data=m_data;}
216  operator int(){return m_data;}
217  CDataInt32& operator =(int data){m_data=data;return *this;}
218  virtual bool operator ==(int value){return m_data==value;}
219  virtual string ToString()const;
220  virtual const IType* GetType()const{return m_type;}
221  protected:
222  static const IType* m_type;
223  int m_data;
224  };
225 
226  class CDataBool:public IObject
227  {
228  public:
229  CDataBool():m_data(0)
230  {
231  if (!m_type){
232  m_type=IType::GetType("bool");
233  }
234  };
235  CDataBool(bool data):m_data(data)
236  {
237  if (!m_type){
238  m_type=IType::GetType("bool");
239  }
240  };
241  virtual ~CDataBool(){};
242  IObject* Clone()const{return new CDataBool(m_data);}
243  void Clone(IObject* obj)const{((CDataBool*)obj)->m_data=m_data;}
244  operator bool(){return m_data;}
245  CDataBool& operator =(bool data){m_data=data;return *this;}
246  virtual bool operator ==(bool value)const{return m_data==value;}
247  virtual string ToString()const;
248  virtual const IType* GetType()const{return m_type;}
249  protected:
250  static const IType* m_type;
251  bool m_data;
252  };
253 
254  class CDataFloat:public IObject
255  {
256  public:
257  CDataFloat():m_data(0)
258  {
259  if (!m_type){
260  m_type=IType::GetType("float");
261  }
262  };
263  CDataFloat(float data):m_data(data)
264  {
265  if (!m_type){
266  m_type=IType::GetType("float");
267  }
268  };
269  virtual ~CDataFloat(){};
270  IObject* Clone()const{return new CDataFloat(m_data);}
271  void Clone(IObject* obj)const{((CDataFloat*)obj)->m_data=m_data;}
272  operator float(){return m_data;}
273  CDataFloat& operator =(float data){m_data=data;return *this;}
274  virtual bool operator ==(float value)const{return m_data==value;}
275  virtual string ToString()const;
276  virtual const IType* GetType()const{return m_type;}
277  protected:
278  static const IType* m_type;
279  float m_data;
280  };
281 
282  class CDataDouble:public IObject
283  {
284  public:
285  CDataDouble():m_data(0)
286  {
287  if (!m_type){
288  m_type=IType::GetType("double");
289  }
290  };
291  CDataDouble(double data):m_data(data)
292  {
293  if (!m_type){
294  m_type=IType::GetType("double");
295  }
296  };
297  virtual ~CDataDouble(){};
298  IObject* Clone()const{return new CDataDouble(m_data);}
299  void Clone(IObject* obj)const{((CDataDouble*)obj)->m_data=m_data;}
300  operator double(){return m_data;}
301  CDataDouble& operator =(double data){m_data=data;return *this;}
302  virtual bool operator ==(double value)const{return m_data==value;}
303  virtual string ToString()const;
304  virtual const IType* GetType()const{return m_type;}
305  protected:
306  static const IType* m_type;
307  double m_data;
308  };
309 
310  class CDataString:public IObject
311  {
312  public:
313  CDataString():m_data(0)
314  {
315  if (!m_type){
316  m_type=IType::GetType("string");
317  }
318  };
319  CDataString(const string& data):m_data(data)
320  {
321  if (!m_type){
322  m_type=IType::GetType("string");
323  }
324  };
325  virtual ~CDataString(){};
326  IObject* Clone()const{return new CDataString(m_data);}
327  void Clone(IObject* obj)const{((CDataString*)obj)->m_data=m_data;}
328  operator const string()const{return m_data;}
329  operator const char*()const {return m_data.c_str();}
330  operator const wstring()const;
331  CDataString& operator =(const string& data){m_data=data;return *this;}
332  CDataString& operator =(const char* data);
333  bool operator ==(const string& value)const{return m_data==value;}
334  bool operator ==(const char* value)const{return m_data==value;}
335  CDataString& operator =(const wstring& data);
336  CDataString& operator =(const wchar_t* data);
337  bool operator ==(const wstring& value)const;
338  virtual string ToString()const;
339  virtual const IType* GetType()const{return m_type;}
340  protected:
341  static const IType* m_type;
342  string m_data;
343 
344  };
346  // GUI types
348  class CGUIType:public IType
349  {
350  public :
351  virtual bool IsContainer()const=0;
352  virtual int Verify(const char* input)const{return Verify_Success;}
353  };
354 
355  class CGUIRootType:public CGUIType
356  {
357  public:
358  CGUIRootType(){m_etype=Type_GUIRoot;}
359  virtual bool IsContainer()const{return true;}
360  static const char TypeName[];
361  virtual const char* GetTypeName()const
362  {
363  return TypeName;
364  }
365  protected:
366  virtual ~CGUIRootType(){}
367  };
368 
370  {
371  public:
372  CGUIButtonType(){m_etype=Type_GUIButton;}
373  virtual bool IsContainer()const{return false;}
374  static const char TypeName[];
375  virtual const char* GetTypeName()const
376  {
377  return TypeName;
378  }
379  protected:
380  virtual ~CGUIButtonType(){}
381  };
382 
384  {
385  public:
386  CGUIWebBrowserType(){m_etype=Type_GUIWebBrowser;}
387  virtual bool IsContainer()const{return false;}
388  static const char TypeName[];
389  virtual const char* GetTypeName()const
390  {
391  return TypeName;
392  }
393  protected:
394  virtual ~CGUIWebBrowserType(){}
395  };
396 
397  class CGUITextType:public CGUIType
398  {
399  public:
400  CGUITextType(){m_etype=Type_GUIText;}
401  virtual bool IsContainer()const{return false;}
402  static const char TypeName[];
403  virtual const char* GetTypeName()const
404  {
405  return TypeName;
406  }
407  protected:
408  virtual ~CGUITextType(){}
409  };
410 
411  class CGUIVideoType:public CGUIType
412  {
413  public:
414  CGUIVideoType(){m_etype=Type_GUIVideo;}
415  virtual bool IsContainer()const{return false;}
416  static const char TypeName[];
417  virtual const char* GetTypeName()const
418  {
419  return TypeName;
420  }
421  protected:
422  virtual ~CGUIVideoType(){}
423  };
424 
426  {
427  public:
428  CGUIEditBoxType(){m_etype=Type_GUIEditBox;}
429  virtual bool IsContainer()const{return false;}
430  static const char TypeName[];
431  virtual const char* GetTypeName()const
432  {
433  return TypeName;
434  }
435  protected:
436  virtual ~CGUIEditBoxType(){}
437  };
438 
440  {
441  public:
442  CGUIIMEEditBoxType(){m_etype=Type_GUIIMEEditBox;}
443  virtual bool IsContainer()const{return false;}
444  static const char TypeName[];
445  virtual const char* GetTypeName()const
446  {
447  return TypeName;
448  }
449  protected:
450  virtual ~CGUIIMEEditBoxType(){}
451  };
452 
454  {
455  public:
456  CGUIScrollBarType(){m_etype=Type_GUIScrollBar;}
457  virtual bool IsContainer()const{return false;}
458  static const char TypeName[];
459  virtual const char* GetTypeName()const
460  {
461  return TypeName;
462  }
463  protected:
464  virtual ~CGUIScrollBarType(){}
465  };
466 
468  {
469  public:
470  CGUIListBoxType(){m_etype=Type_GUIListBox;}
471  virtual bool IsContainer()const{return true;}
472  static const char TypeName[];
473  virtual const char* GetTypeName()const
474  {
475  return TypeName;
476  }
477  protected:
478  virtual ~CGUIListBoxType(){}
479  };
480 
482  {
483  public:
484  CGUIToolTipType(){m_etype=Type_GUIToolTip;}
485  virtual bool IsContainer()const{return false;}
486  static const char TypeName[];
487  virtual const char* GetTypeName()const
488  {
489  return TypeName;
490  }
491  protected:
492  virtual ~CGUIToolTipType(){}
493  };
494 
496  {
497  public:
498  CGUIPainterType(){m_etype=Type_GUIPainter;}
499  virtual bool IsContainer()const{return false;}
500  static const char TypeName[];
501  virtual const char* GetTypeName()const
502  {
503  return TypeName;
504  }
505  protected:
506  virtual ~CGUIPainterType(){}
507  };
508 
510  {
511  public:
512  CGUISliderType(){m_etype=Type_GUISlider;}
513  virtual bool IsContainer()const{return false;}
514  static const char TypeName[];
515  virtual const char* GetTypeName()const
516  {
517  return TypeName;
518  }
519  protected:
520  virtual ~CGUISliderType(){}
521  };
522 
523  class CGUIGridType:public CGUIType
524  {
525  public:
526  CGUIGridType(){m_etype=Type_GUIGrid;}
527  virtual bool IsContainer()const{return false;}
528  static const char TypeName[];
529  virtual const char* GetTypeName()const
530  {
531  return TypeName;
532  }
533  protected:
534  virtual ~CGUIGridType(){}
535  };
536 
538  {
539  public:
540  CGUIContainerType(){m_etype=Type_GUIContainer;}
541  virtual bool IsContainer()const{return true;}
542  static const char TypeName[];
543  virtual const char* GetTypeName()const
544  {
545  return TypeName;
546  }
547  protected:
548  virtual ~CGUIContainerType(){}
549  };
551  {
552  public:
553  CGUICanvasType(){m_etype=Type_GUICanvas;}
554  virtual bool IsContainer()const{return false;}
555  static const char TypeName[];
556  virtual const char* GetTypeName()const
557  {
558  return TypeName;
559  }
560  protected:
561  virtual ~CGUICanvasType(){}
562  };
563 
564 }
Definition: Type.h:310
Definition: Type.h:133
void Clone(IObject *obj) const
Clone the object&#39;s contains to a pointer.
Definition: Type.h:299
IType is for type information and validating It contains type information of an object.
Definition: Type.h:75
void Clone(IObject *obj) const
Clone the object&#39;s contains to a pointer.
Definition: Type.h:327
Definition: Type.h:348
IObject * Clone() const
Clone the object&#39;s contains and return a pointer to the newly created object.
Definition: Type.h:326
Definition: Type.h:150
different physics engine has different winding order.
Definition: EventBinding.h:32
IObject * Clone() const
Clone the object&#39;s contains and return a pointer to the newly created object.
Definition: Type.h:214
Definition: Type.h:453
void Clone(IObject *obj) const
Clone the object&#39;s contains to a pointer.
Definition: Type.h:243
void Clone(IObject *obj) const
Clone the object&#39;s contains to a pointer.
Definition: Type.h:271
Definition: Type.h:254
Definition: Type.h:167
Definition: Type.h:397
Definition: Type.h:282
Definition: Type.h:523
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
Definition: Type.h:118
Definition: Type.h:509
Definition: Type.h:101
Definition: Type.h:369
Definition: Type.h:411
Definition: Type.h:550
Definition: enum_maker.hpp:46
void Clone(IObject *obj) const
Clone the object&#39;s contains to a pointer.
Definition: Type.h:215
Definition: Type.h:198
Definition: Type.h:184
Definition: Type.h:537
Definition: Type.h:481
Definition: Type.h:495
Definition: Type.h:425
Definition: Type.h:439
IObject * Clone() const
Clone the object&#39;s contains and return a pointer to the newly created object.
Definition: Type.h:298
IObject * Clone() const
Clone the object&#39;s contains and return a pointer to the newly created object.
Definition: Type.h:242
Definition: Type.h:226
IObject * Clone() const
Clone the object&#39;s contains and return a pointer to the newly created object.
Definition: Type.h:270
Definition: Type.h:49
Definition: Type.h:355
Definition: Type.h:467
Definition: Type.h:383