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 "csutil/scfarray.h"
00026 #include "csgeom/vector2.h"
00027 #include "csgeom/vector3.h"
00028 #include "csgeom/vector4.h"
00029 #include "csutil/cscolor.h"
00030 
00031 struct iCelPropertyClass;
00032 struct iCelEntity;
00033 
00038 enum celDataType
00039 {
00041   CEL_DATA_NONE = 0,
00043   CEL_DATA_BOOL,
00045   CEL_DATA_BYTE,
00047   CEL_DATA_WORD,
00049   CEL_DATA_LONG,
00051   CEL_DATA_UBYTE,
00053   CEL_DATA_UWORD,
00055   CEL_DATA_ULONG,
00057   CEL_DATA_FLOAT,
00059   CEL_DATA_VECTOR2,
00061   CEL_DATA_VECTOR3,
00063   CEL_DATA_VECTOR4,
00065   CEL_DATA_STRING,
00067   CEL_DATA_PCLASS,
00069   CEL_DATA_ENTITY,
00071   CEL_DATA_ACTION,
00073   CEL_DATA_COLOR,
00075   CEL_DATA_COLOR4,
00077   CEL_DATA_IBASE,
00079   CEL_DATA_PARAMETER,
00081   CEL_DATA_LAST
00082 };
00083 
00087 struct celData
00088 {
00089   celDataType type;
00090   union
00091   {
00092     bool bo;
00093     int8 b;
00094     uint8 ub;
00095     int16 w;
00096     uint16 uw;
00097     int32 l;
00098     uint32 ul;
00099     float f;
00100     iString* s;
00101     struct
00102     {
00103       float x, y, z, w;
00104     } v;
00105     struct
00106     {
00107       float red, green, blue, alpha;
00108     } col;
00109     iCelPropertyClass* pc;
00110     iCelEntity* ent;
00111     iBase* ibase;
00112     struct
00113     {
00114       iString* parname;
00115       celDataType partype;
00116     } par;
00117   } value;
00118 
00119   celData () : type (CEL_DATA_NONE) { }
00120   celData (const celData& copy)
00121   {
00122     type = copy.type;
00123     value = copy.value;
00124     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef ();
00125     else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef ();
00126   }
00127   const celData& operator= (const celData& copy)
00128   {
00129     Clear ();
00130     type = copy.type;
00131     value = copy.value;
00132     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef ();
00133     else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef ();
00134     return *this;
00135   }
00136   ~celData()
00137   {
00138     Clear ();
00139   }
00140   void Clear ()
00141   {
00142     if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->DecRef ();
00143     else if (type == CEL_DATA_PARAMETER) value.par.parname->DecRef ();
00144     type = CEL_DATA_NONE;
00145   }
00149   void Set (bool v) { Clear (); type = CEL_DATA_BOOL; value.bo = v; }
00150   void Set (int8 v) { Clear (); type = CEL_DATA_BYTE; value.b = v; }
00151   void Set (uint8 v) { Clear (); type = CEL_DATA_UBYTE; value.ub = v; }
00152   void Set (int16 v) { Clear (); type = CEL_DATA_WORD; value.w = v; }
00153   void Set (uint16 v) { Clear (); type = CEL_DATA_UWORD; value.uw = v; }
00154   void Set (int32 v) { Clear (); type = CEL_DATA_LONG; value.l = v; }
00155   void Set (uint32 v) { Clear (); type = CEL_DATA_ULONG; value.ul = v; }
00156   void Set (float v) { Clear (); type = CEL_DATA_FLOAT; value.f = v; }
00157   void Set (const csVector2& v)
00158   {
00159     Clear ();
00160     type = CEL_DATA_VECTOR2;
00161     value.v.x = v.x;
00162     value.v.y = v.y;
00163   }
00164   void Set (const csVector3& v)
00165   {
00166     Clear ();
00167     type = CEL_DATA_VECTOR3;
00168     value.v.x = v.x;
00169     value.v.y = v.y;
00170     value.v.z = v.z;
00171   }
00172   void Set (const csVector4& v)
00173   {
00174     Clear ();
00175     type = CEL_DATA_VECTOR4;
00176     value.v.x = v.x;
00177     value.v.y = v.y;
00178     value.v.z = v.z;
00179     value.v.w = v.w;
00180   }
00181   void Set (const csColor& v)
00182   {
00183     Clear ();
00184     type = CEL_DATA_COLOR;
00185     value.col.red = v.red;
00186     value.col.green = v.green;
00187     value.col.blue = v.blue;
00188   }
00189   void Set (const csColor4& v)
00190   {
00191     Clear ();
00192     type = CEL_DATA_COLOR4;
00193     value.col.red = v.red;
00194     value.col.green = v.green;
00195     value.col.blue = v.blue;
00196     value.col.alpha = v.alpha;
00197   }
00198   void Set (const char* s)
00199   {
00200     Clear ();
00201     type = CEL_DATA_STRING;
00202     value.s = new scfString (s);
00203   }
00204   void Set (iCelPropertyClass* pc)
00205   {
00206     Clear ();
00207     type = CEL_DATA_PCLASS;
00208     value.pc = pc;
00209   }
00210   void Set (iCelEntity* ent)
00211   {
00212     Clear ();
00213     type = CEL_DATA_ENTITY;
00214     value.ent = ent;
00215   }
00216   void SetAction (const char* s)
00217   {
00218     Clear ();
00219     type = CEL_DATA_ACTION;
00220     value.s = new scfString (s);
00221   }
00222   void SetIBase (iBase* b)
00223   {
00224     Clear ();
00225     type = CEL_DATA_IBASE;
00226     value.ibase = b;
00227   }
00228   void SetParameter (const char* s, celDataType t)
00229   {
00230     Clear ();
00231     type = CEL_DATA_PARAMETER;
00232     value.par.parname = new scfString (s);
00233     value.par.partype = t;
00234   }
00235   csString GetDebugInfo ();
00236 };
00237 
00238 struct iCelDataArrayReadOnly : public iArrayReadOnly<celData>
00239 {
00240   SCF_IARRAYREADONLY_INTERFACE(iCelDataArrayReadOnly);
00241 };
00242 
00243 struct iCelDataArray : public iArrayChangeAll<celData>
00244 {
00245   SCF_IARRAYCHANGEALL_INTERFACE(iCelDataArrayReadOnly);
00246 };
00247 
00248 #endif // __CEL_PL_DATATYPE__
00249 

Generated for CEL: Crystal Entity Layer 2.0 by doxygen 1.7.6.1