CEL

Public API Reference

physicallayer/datatype.h

00001 /*
00002     Crystal Space Entity Layer
00003     Copyright (C) 2001 by Jorrit Tyberghein
00004   
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009   
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014   
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __CEL_PL_DATATYPE__
00021 #define __CEL_PL_DATATYPE__
00022 
00023 #include "cstypes.h"
00024 #include "csutil/scfstr.h"
00025 #include "csgeom/vector2.h"
00026 #include "csgeom/vector3.h"
00027 #include "csutil/cscolor.h"
00028 
00029 struct iCelPropertyClass;
00030 struct iCelEntity;
00031 
00036 enum celDataType
00037 {
00038   CEL_DATA_NONE = 0,
00039   CEL_DATA_BOOL,
00040   CEL_DATA_BYTE,
00041   CEL_DATA_WORD,
00042   CEL_DATA_LONG,
00043   CEL_DATA_UBYTE,
00044   CEL_DATA_UWORD,
00045   CEL_DATA_ULONG,
00046   CEL_DATA_FLOAT,
00047   CEL_DATA_VECTOR2,
00048   CEL_DATA_VECTOR3,
00049   CEL_DATA_STRING,
00050   CEL_DATA_PCLASS,
00051   CEL_DATA_ENTITY,
00052   CEL_DATA_ACTION,
00053   CEL_DATA_COLOR,
00054   CEL_DATA_IBASE,
00055   CEL_DATA_PARAMETER,
00056 
00057   CEL_DATA_LAST
00058 };
00059 
00063 struct celData
00064 {
00065   celDataType type;
00066   union
00067   {
00068     bool bo;
00069     int8 b;
00070     uint8 ub;
00071     int16 w;
00072     uint16 uw;
00073     int32 l;
00074     uint32 ul;
00075     float f;
00076     iString* s;
00077     struct
00078     {
00079       float x, y, z;
00080     } v;
00081     struct
00082     {
00083       float red, green, blue;
00084     } col;
00085     iCelPropertyClass* pc;
00086     iCelEntity* ent;
00087     iBase* ibase;
00088     struct
00089     {
00090       iString* parname;
00091       celDataType partype;
00092     } par;
00093   } value;
00094 
00095   celData () : type (CEL_DATA_NONE) { }
00096   celData (const celData& copy)
00097   {
00098     type = copy.type;
00099     value = copy.value;
00100     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef ();
00101     else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef ();
00102   }
00103   const celData& operator= (const celData& copy)
00104   {
00105     Clear ();
00106     type = copy.type;
00107     value = copy.value;
00108     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef ();
00109     else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef ();
00110     return *this;
00111   }
00112   ~celData()
00113   {
00114     Clear ();
00115   }
00116   void Clear ()
00117   {
00118     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->DecRef ();
00119     else if (type == CEL_DATA_PARAMETER) value.par.parname->DecRef ();
00120     type = CEL_DATA_NONE;
00121   }
00125   void Set (bool v) { Clear (); type = CEL_DATA_BOOL; value.bo = v; }
00126   void Set (int8 v) { Clear (); type = CEL_DATA_BYTE; value.b = v; }
00127   void Set (uint8 v) { Clear (); type = CEL_DATA_UBYTE; value.ub = v; }
00128   void Set (int16 v) { Clear (); type = CEL_DATA_WORD; value.w = v; }
00129   void Set (uint16 v) { Clear (); type = CEL_DATA_UWORD; value.uw = v; }
00130   void Set (int32 v) { Clear (); type = CEL_DATA_LONG; value.l = v; }
00131   void Set (uint32 v) { Clear (); type = CEL_DATA_ULONG; value.ul = v; }
00132   void Set (float v) { Clear (); type = CEL_DATA_FLOAT; value.f = v; }
00133   void Set (const csVector2& v)
00134   {
00135     Clear ();
00136     type = CEL_DATA_VECTOR2;
00137     value.v.x = v.x;
00138     value.v.y = v.y;
00139   }
00140   void Set (const csVector3& v)
00141   {
00142     Clear ();
00143     type = CEL_DATA_VECTOR3;
00144     value.v.x = v.x;
00145     value.v.y = v.y;
00146     value.v.z = v.z;
00147   }
00148   void Set (const csColor& v)
00149   {
00150     Clear ();
00151     type = CEL_DATA_COLOR;
00152     value.col.red = v.red;
00153     value.col.green = v.green;
00154     value.col.blue = v.blue;
00155   }
00156   void Set (const char* s)
00157   {
00158     Clear ();
00159     type = CEL_DATA_STRING;
00160     value.s = new scfString (s);
00161   }
00162   void Set (iCelPropertyClass* pc)
00163   {
00164     Clear ();
00165     type = CEL_DATA_PCLASS;
00166     value.pc = pc;
00167   }
00168   void Set (iCelEntity* ent)
00169   {
00170     Clear ();
00171     type = CEL_DATA_ENTITY;
00172     value.ent = ent;
00173   }
00174   void SetAction (const char* s)
00175   {
00176     Clear ();
00177     type = CEL_DATA_ACTION;
00178     value.s = new scfString (s);
00179   }
00180   void SetIBase (iBase* b)
00181   {
00182     Clear ();
00183     type = CEL_DATA_IBASE;
00184     value.ibase = b;
00185   }
00186   void SetParameter (const char* s, celDataType t)
00187   {
00188     Clear ();
00189     type = CEL_DATA_PARAMETER;
00190     value.par.parname = new scfString (s);
00191     value.par.partype = t;
00192   }
00193   csString GetDebugInfo ();
00194 };
00195 
00196 #endif // __CEL_PL_DATATYPE__
00197 

Generated for CEL: Crystal Entity Layer by doxygen 1.4.7