Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

MyObject.h

Go to the documentation of this file.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 *********************************************************************************** */
00018 
00023 #ifndef INCLUDE_MY_OBJECT_H
00024 #define INCLUDE_MY_OBJECT_H
00025 
00026 class Object;
00027 typedef void * (Object::*Obj_CallBack) (void *);
00028 
00084 class Object 
00085 {
00086 public:
00087         void *thisParent;
00088         int type;
00089         LONG param; // parametre suplementaire
00090         Obj_CallBack callBackAlloc;
00091 
00092 public:
00093         Object()
00094         {
00095                 param = 0;
00096                 thisParent=NULL;
00097                 type=-1;
00098                 callBackAlloc=NULL;
00099         }
00100 
00101         Object(int _type,void *_thisParent)
00102         {
00103                 type = _type;
00104                 thisParent = _thisParent;
00105         }
00106 
00107         void operator= (Object &source)
00108         {
00109                 param = source.param;
00110                 type = source.type;     
00111                 callBackAlloc = source.callBackAlloc;
00112                 thisParent = (*this.*callBackAlloc)(source.thisParent);
00113         }
00114 };
00115 
00124 template <class T,int V> class BaseObj : public Object
00125 {
00126 public:
00127         T elem;
00128 
00129         BaseObj() : Object(V,(void *)this) 
00130         {
00131                 callBackAlloc = (Obj_CallBack) Duplicate;
00132         }
00133 
00134         void * Duplicate (void *_in)
00135         {
00136                 BaseObj<T,V> *in = (BaseObj<T,V> *)_in;
00137                 BaseObj<T,V> *out = new BaseObj<T,V>;
00138                 *out = *in;
00139                 return (void *)out;
00140         }
00141 
00142         void operator=(BaseObj<T,V> &source)
00143         {
00144                 elem = source.elem;
00145         }
00146 };
00147 
00148 #define CBASE_INDEX_INT         0
00149 #define CBASE_INDEX_FLOAT       1
00150 #define CBASE_INDEX_DOUBLE      2
00151 #define CBASE_INDEX_STRING      3
00152 #define CBASE_INDEX_CUSTOM      4
00153 
00154 #define CBase_int BaseObj<int,CBASE_INDEX_INT>
00155 #define CBase_float BaseObj<float,CBASE_INDEX_FLOAT>
00156 #define CBase_double BaseObj<double,CBASE_INDEX_DOUBLE>
00157 #define CBase_string BaseObj<MyString,CBASE_INDEX_STRING>
00158 
00159 /* Visuel de class virtuel ******************************************************
00160  class A
00161  {
00162  public:
00163          int var_a;
00164 
00165          virtual void meth_a()
00166          {
00167                  var_a=10;
00168          }
00169 
00170          void meth_a2()
00171          {
00172                  meth_a();
00173          }
00174  };
00175 
00176  class B: public A
00177  {
00178  public:
00179          int var_b;
00180 
00181          void meth_a()
00182          {
00183                  var_b=20;
00184          }
00185  };
00186 
00187  // test:
00188  A a;
00189  B b;
00190 
00191  a.meth_a();
00192  a.meth_a2();
00193  b.meth_a();
00194  b.meth_a2();
00195  A *c = &b;
00196  c->meth_a2();
00197 
00198  // classe de text pour les object
00199  class CTest
00200  {
00201  public:
00202  int i;
00203  MyString text;
00204 
00205  CTest()
00206  {
00207  text="";
00208  i=0;
00209  }
00210  void operator=(CTest &source)
00211  {
00212  i = source.i;
00213  text = source.text;
00214  }
00215  };
00216 */
00217 
00218 #endif

Generated on Fri Aug 20 19:19:47 2004 for 3d Controls by doxygen 1.3.6