My Project
AttributeField.h
1 #pragma once
2 #include "Variable.h"
3 
4 namespace ParaEngine
5 {
6  using namespace std;
7 
8  enum SIMPLE_SCHEMA
9  {
10  SCHEMA_RGB = 0,
11  SCHEMA_FILE,
12  SCHEMA_SCRIPT,
13  SCHEMA_INTEGER,
14  SCHEMA_FLOAT,
15  SCHEMA_DIALOG,
16  };
17 
20  {
21  public:
23  ~CAttributeField();
24  public:
25  union any_offset{
26  void* ptr_fun;
27  int offset_data;
28  };
29  any_offset m_offsetSetFunc;
30  any_offset m_offsetGetFunc;
31 
32 
34  DWORD m_type;
35 
38  string m_sSchematics;
40  string m_sHelpString;
41 
42  protected:
44  string m_sFieldname;
45  /* hash of filed name, used to fast query*/
46  size_t m_hash;
47  public:
48  void SetFieldname(const string& sFieldname);
49 
50  const string& GetFieldname() const;
51 
52  size_t GetHash() const;
53 
54  static std::hash<string> HashFunc;
60  const char* GetTypeAsString();
61 
63  inline bool HasGetFunction() { return (m_offsetGetFunc.ptr_fun != 0); }
65  inline bool HasSetFunction() { return (m_offsetSetFunc.ptr_fun != 0); }
66 
67  inline HRESULT Call(void* obj)
68  {
69  if (m_offsetSetFunc.ptr_fun != 0)
70  return ((HRESULT(*)(void* obj))m_offsetSetFunc.ptr_fun)(obj);
71  else if (m_offsetGetFunc.ptr_fun != 0)
72  return ((HRESULT(*)(void* obj))m_offsetSetFunc.ptr_fun)(obj);
73  else
74  return E_FAIL;
75  };
76  inline HRESULT Get(void* obj)
77  {
78  if (m_offsetGetFunc.ptr_fun != 0)
79  return ((HRESULT(*)(void* obj))m_offsetSetFunc.ptr_fun)(obj);
80  else
81  return E_FAIL;
82  };
83  /* attention should be paid: alway explicitly pass the parameter type to the function. e.g. Set(obj, (bool)bValue)*/
84  template <class datatype>
85  inline HRESULT Set(void* obj, datatype p1)
86  {
87  if (m_offsetSetFunc.ptr_fun != 0)
88  return ((HRESULT(*)(void* obj, datatype p1))m_offsetSetFunc.ptr_fun)(obj, p1);
89  else
90  return E_FAIL;
91  };
92  // this ensure that Matrix4 is always passed by reference. when defining attribute, one should always use const Matrix4&
93  inline HRESULT Set(void* obj, const Matrix4& p1)
94  {
95  if (m_offsetSetFunc.ptr_fun != 0)
96  return ((HRESULT(*)(void* obj, const Matrix4& p1))m_offsetSetFunc.ptr_fun)(obj, p1);
97  else
98  return E_FAIL;
99  };
100  template <class datatype>
101  inline HRESULT Set(void* obj, datatype p1, datatype p2)
102  {
103  if (m_offsetSetFunc.ptr_fun != 0)
104  return ((HRESULT(*)(void* obj, datatype p1, datatype p2))m_offsetSetFunc.ptr_fun)(obj, p1, p2);
105  else
106  return E_FAIL;
107  };
108  template <class datatype>
109  inline HRESULT Set(void* obj, datatype p1, datatype p2, datatype p3)
110  {
111  if (m_offsetSetFunc.ptr_fun != 0)
112  return ((HRESULT(*)(void* obj, datatype p1, datatype p2, datatype p3))m_offsetSetFunc.ptr_fun)(obj, p1, p2, p3);
113  else
114  return E_FAIL;
115  };
116  template <class datatype>
117  inline HRESULT Set(void* obj, datatype p1, datatype p2, datatype p3, datatype p4)
118  {
119  if (m_offsetSetFunc.ptr_fun != 0)
120  return ((HRESULT(*)(void* obj, datatype p1, datatype p2, datatype p3, datatype p4))m_offsetSetFunc.ptr_fun)(obj, p1, p2, p3, p4);
121  else
122  return E_FAIL;
123  };
124  template <class datatype>
125  inline HRESULT Get(void* obj, datatype* p1)
126  {
127  if (m_offsetGetFunc.ptr_fun != 0)
128  return ((HRESULT(*)(void* obj, datatype* p1))m_offsetGetFunc.ptr_fun)(obj, p1);
129  else
130  return E_FAIL;
131  };
132  template <class datatype>
133  inline HRESULT Get(void* obj, datatype* p1, datatype* p2)
134  {
135  if (m_offsetGetFunc.ptr_fun != 0)
136  return ((HRESULT(*)(void* obj, datatype* p1, datatype* p2))m_offsetGetFunc.ptr_fun)(obj, p1, p2);
137  else
138  return E_FAIL;
139  };
140  template <class datatype>
141  inline HRESULT Get(void* obj, datatype* p1, datatype* p2, datatype* p3)
142  {
143  if (m_offsetGetFunc.ptr_fun != 0)
144  return ((HRESULT(*)(void* obj, datatype* p1, datatype* p2, datatype* p3))m_offsetGetFunc.ptr_fun)(obj, p1, p2, p3);
145  else
146  return E_FAIL;
147  };
148  template <class datatype>
149  inline HRESULT Get(void* obj, datatype* p1, datatype* p2, datatype* p3, datatype* p4)
150  {
151  if (m_offsetGetFunc.ptr_fun != 0)
152  return ((HRESULT(*)(void* obj, datatype* p1, datatype* p2, datatype* p3, datatype* p4))m_offsetGetFunc.ptr_fun)(obj, p1, p2, p3, p4);
153  else
154  return E_FAIL;
155  };
156  public:
167  static const char* GetSimpleSchema(SIMPLE_SCHEMA schema);
168  static const char* GetSimpleSchemaOfRGB(){ return GetSimpleSchema(SCHEMA_RGB); };
169  static const char* GetSimpleSchemaOfFile(){ return GetSimpleSchema(SCHEMA_FILE); };
170  static const char* GetSimpleSchemaOfScript(){ return GetSimpleSchema(SCHEMA_SCRIPT); };
171  static const char* GetSimpleSchemaOfInt(int nMin, int nMax);
172  static const char* GetSimpleSchemaOfFloat(float nMin, float nMax);
173 
184  const char* GetSchematicsType();
185 
192  bool GetSchematicsMinMax(float& fMin, float& fMax);
193  };
194 }
string m_sSchematics
additional schematics for describing the display format of the data.
Definition: AttributeField.h:38
Definition: AttributeField.h:25
for a single attribute field
Definition: AttributeField.h:19
DWORD m_type
see ATTRIBUTE_FIELDTYPE
Definition: AttributeField.h:34
bool HasSetFunction()
whether has set function.
Definition: AttributeField.h:65
string m_sHelpString
a help string.
Definition: AttributeField.h:40
different physics engine has different winding order.
Definition: EventBinding.h:32
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
string m_sFieldname
field name: e.g.
Definition: AttributeField.h:44
bool HasGetFunction()
whether has get function.
Definition: AttributeField.h:63