My Project
BaseTable.h
1 #include <map>
2 #include <vector>
3 #include "ICollection.h"
4 namespace ParaEngine
5 {
6  class CBaseTable;
7 
8  enum Table_Row_Column_Type{
9  Table_Neutral,
10  Table_Column,
11  Table_Row
12  };
13 
17  class CBaseRowColumn:public IObject
18  {
19  public:
20  friend class CBaseTable;
21  friend class CDataRow;
22 
27  virtual IObject* Clone()const;
28  virtual void Clone(IObject *obj)const;
29 
30  virtual void Clear();
35  virtual bool Equals(const IObject*obj)const;
36 
37  bool Update();//update the row or column from the CBaseTable
38 
44  //call mdata's Add()
45  virtual int Add(IObject& obj);
46 
52  //call CBaseTable::SetAt();
53  virtual int SetAt(IObject& obj, int index);
54 
59  //call m_data's Insert()
60  virtual int Insert(IObject& obj, int index);
61 
66  //call corresponding CBaseTable::GetAt
67  virtual const IObject* GetAt(int index)const;
68  virtual IObject* GetAt(int index);
69 
74  virtual int Resize(int newsize);
75  virtual int Size()const{return m_data.Size();}
76 
81  virtual bool IsValid()const;
82 
87  virtual int Remove(int index);
88  protected:
89  CBaseRowColumn():m_bIsFixedSize(false),m_etype(Table_Neutral),m_nIndex(-1),m_parent(NULL){}
90  CBaseRowColumn(int index, int etype):m_bIsFixedSize(false),m_etype(etype),m_nIndex(index),m_parent(NULL){}
91  CBaseRowColumn(int index, int etype,bool fixedsize):m_bIsFixedSize(fixedsize),m_etype(etype),m_nIndex(index),m_parent(NULL){}
92  CBaseRowColumn(int index, bool fixedsize):m_bIsFixedSize(fixedsize),m_etype(Table_Neutral),m_nIndex(index),m_parent(NULL){}
93  virtual ~CBaseRowColumn(){
94  m_data.Clear();
95  }
99  virtual int InternalSetAt(IObject& obj, int index);
100  //only the row or column that is not related to a CBaseTable is m_bIsFixedSize==false;
101  bool m_bIsFixedSize;
102  int m_nIndex;//the row or column index of this object in the CBaseTable
103  CBaseTable* m_parent;
105  int m_etype;//identify if this is a row, column or neutral. enumeration Table_Row_Column_Type
106 
107  };
108 
109 
110 
111  //any change in this table will make all CBaseRow and CBaseColumn object of it Invalid
115  {
116  public:
117  CBaseTable(){}
118  CBaseTable(int rowsize,int columnsize);
122  virtual ~CBaseTable();
129  virtual int InsertRow(int index);
137  //assign correct type of the input row, check if index valid,
138  virtual int InsertRow(CBaseRowColumn& row, int index);
143  virtual CBaseRowColumn* GetRow(int index);
144  // virtual const CBaseRowColumn* GetRow(int index)const;
151  virtual int InsertColumn(int index);
159  //assign correct type of the input column, check if index valid,
160  virtual int InsertColumn(CBaseRowColumn& column, int index);
165  virtual const IObject* GetAt(int row, int column)const;
166  virtual IObject* GetAt(int row, int column);
167 
172  virtual int SetAt(IObject& obj, int row, int column);
173 
174  //delete the column and its reference in the CBaseTable
175  virtual void DeleteColumn(int index);
176  //delete the row and its reference in the CBaseTable
177  virtual void DeleteRow(int index);
178 
179  //delete all rows and columns
180  virtual void Clear();
181 
182  virtual int NumberOfRows(){return m_nRowSize;}
183  virtual int NumberOfColumns(){return m_nColumnSize;}
184 #ifdef _DEBUG
185  static void test();
186 #endif
187  friend class CBaseRowColumn;
188  protected:
189  Collection_Vector<CBaseRowColumn> m_Rows;//the rows generated from this table
190  int m_nRowSize,m_nColumnSize;
191  };
192 
193 }
194 
195 //any change in this table will make all CBaseRow and CBaseColumn object of it Invalid
201 // class CBaseTable
202 // {
203 // public:
204 // CBaseTable():m_bRowValid(true),m_bColumnValid(true){}
205 // CBaseTable(int rowsize,int columnsize);
206 // /**
207 // * Release all resource, output error if some of the rows and columns are not properly release via ReleaseXX() functions
208 // */
209 // virtual ~CBaseTable();
210 // /**
211 // * insert a new row at a given position, return the newly inserted row (it is an empty row)
212 // * the row is filled with null (using Resize())
213 // * will invalidate the rows which are larger than index and all columns.
214 // * One shall delete or release the input CBaseRowColumn.
215 // */
216 // virtual int InsertRow(int index);
217 // /**
218 // * insert an existing row at a given position
219 // * if the size of the input object does not match the CBaseTable's, the input object's
220 // * Resize() will be called to set the correct size;
221 // * will invalidate the rows which are larger than index and all columns.
222 // * One shall delete or release the input CBaseRowColumn.
223 // */
224 // //assign correct type of the input row, check if index valid,
225 // virtual int InsertRow(CBaseRowColumn& row, int index);
226 // /**
227 // * get a row, you should release it after use
228 // * @return: NULL if not exists.
229 // */
230 // virtual CBaseRowColumn* GetRow(int index);
231 // // virtual const CBaseRowColumn* GetRow(int index)const;
232 // /**
233 // * insert a new column at a given position, return the newly inserted column (it is an empty column)
234 // * the column is filled with null(using Resize())
235 // * will invalidate the columns which are larger than index and all rows.
236 // * One shall delete or release the input CBaseRowColumn.
237 // */
238 // virtual int InsertColumn(int index);
239 // /**
240 // * insert an existing column at a given position
241 // * if the size of the input object does not match the CBaseTable's, the input object's
242 // * Resize() will be called to set the correct size;
243 // * will invalidate the columns which are larger than index and all rows.
244 // * One shall delete or release the input CBaseRowColumn.
245 // */
246 // //assign correct type of the input column, check if index valid,
247 // virtual int InsertColumn(CBaseRowColumn& column, int index);
248 // /**
249 // * get a column, you should release it after use
250 // * @return: NULL if not exists.
251 // */
252 // virtual CBaseRowColumn* GetColumn(int index);
253 // // virtual const CBaseRowColumn* GetColumn(int index)const;
254 // /**
255 // * get the IObject at a given position
256 // * @return: NULL if not exists.
257 // */
258 // virtual const IObject* GetAt(int row, int column)const;
259 // virtual IObject* GetAt(int row, int column);
260 //
261 // /**
262 // * Set the IObject at a given position
263 // * @return: -1 if failed
264 // */
265 // virtual int SetAt(IObject& obj, int row, int column);
266 //
267 // //delete the column and its reference in the CBaseTable
268 // virtual void DeleteColumn(int index);
269 // //delete the row and its reference in the CBaseTable
270 // virtual void DeleteRow(int index);
271 //
272 // //delete all rows and columns
273 // virtual void Clear();
274 //
275 // /**
276 // * Clean the row and column cache. It will make Update operation faster
277 // */
278 // virtual void CleanCache();
279 // //update rows or columns
280 // virtual bool Update();
281 //
282 // virtual int NumberOfRows(){return m_nRowSize;}
283 // virtual int NumberOfColumns(){return m_nColumnSize;}
284 // #ifdef _DEBUG
285 // static void test();
286 // #endif
287 // friend class CBaseRowColumn;
288 // protected:
289 // Collection_Map<CBaseRowColumn> m_Rows;//the rows generated from this table
290 // Collection_Map<CBaseRowColumn> m_Columns;//the columns generated from this table
291 // Collection_Vector<IObject> m_data;//pos=row*columnsize+column
292 // int m_nRowSize,m_nColumnSize;
293 // bool m_bRowValid;//marks all the rows as valid or invalid
294 // bool m_bColumnValid;//marks all the columns as valid or invalid
295 // };
Definition: GLType.h:217
virtual const IObject * GetAt(int index) const
get the IObject at a given position
Definition: BaseTable.cpp:118
virtual int SetAt(IObject &obj, int index)
Set the object at a given position in a row or column This will change the corresponding records in t...
Definition: BaseTable.cpp:77
virtual int Resize(int newsize)
Resize the current row or column, if m_IsFixedSize==true, it will fail.
Definition: BaseTable.cpp:92
different physics engine has different winding order.
Definition: EventBinding.h:32
Although this class inherits the CRefCounted interface, I don&#39;t manage it in GC.
Definition: BaseTable.h:17
Definition: BaseTable.h:114
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
virtual int Remove(int index)
Remove an object, if m_IsFixedSize==true, it will fail.
Definition: BaseTable.cpp:148
virtual int InternalSetAt(IObject &obj, int index)
Internal function.
Definition: BaseTable.cpp:84
virtual IObject * Clone() const
Clone never clones the m_nIndex, m_parent, m_bIsFixedSize new object is: m_nIndex=-1;m_parent=NULL;m_...
Definition: BaseTable.cpp:18
virtual int Add(IObject &obj)
Add an object to the row or column, will failed if m_bIsFixedSize==true Only the. ...
Definition: BaseTable.cpp:62
virtual bool Equals(const IObject *obj) const
Size and corresponding members of the two objects must equal to return true; It uses the Equals() mem...
Definition: BaseTable.cpp:42
virtual bool IsValid() const
Check if the data in the row or column is valid if not valid, the row or column&#39;s Update() must be ca...
Definition: BaseTable.cpp:140
Default behavior of the collection adds only reference.
Definition: ICollection.h:35
children of data row is some addition data rows.
Definition: DataTable.h:166
virtual int Insert(IObject &obj, int index)
insert an object at a given position,, will failed if m_bIsFixedSize==true
Definition: BaseTable.cpp:105