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 "csgeom/vector4.h" 00028 #include "csutil/cscolor.h" 00029 00030 struct iCelPropertyClass; 00031 struct iCelEntity; 00032 00037 enum celDataType 00038 { 00039 CEL_DATA_NONE = 0, 00040 CEL_DATA_BOOL, 00041 CEL_DATA_BYTE, 00042 CEL_DATA_WORD, 00043 CEL_DATA_LONG, 00044 CEL_DATA_UBYTE, 00045 CEL_DATA_UWORD, 00046 CEL_DATA_ULONG, 00047 CEL_DATA_FLOAT, 00048 CEL_DATA_VECTOR2, 00049 CEL_DATA_VECTOR3, 00050 CEL_DATA_VECTOR4, 00051 CEL_DATA_STRING, 00052 CEL_DATA_PCLASS, 00053 CEL_DATA_ENTITY, 00054 CEL_DATA_ACTION, 00055 CEL_DATA_COLOR, 00056 CEL_DATA_COLOR4, 00057 CEL_DATA_IBASE, 00058 CEL_DATA_PARAMETER, 00059 00060 CEL_DATA_LAST 00061 }; 00062 00066 struct celData 00067 { 00068 celDataType type; 00069 union 00070 { 00071 bool bo; 00072 int8 b; 00073 uint8 ub; 00074 int16 w; 00075 uint16 uw; 00076 int32 l; 00077 uint32 ul; 00078 float f; 00079 iString* s; 00080 struct 00081 { 00082 float x, y, z, w; 00083 } v; 00084 struct 00085 { 00086 float red, green, blue, alpha; 00087 } col; 00088 iCelPropertyClass* pc; 00089 iCelEntity* ent; 00090 iBase* ibase; 00091 struct 00092 { 00093 iString* parname; 00094 celDataType partype; 00095 } par; 00096 } value; 00097 00098 celData () : type (CEL_DATA_NONE) { } 00099 celData (const celData& copy) 00100 { 00101 type = copy.type; 00102 value = copy.value; 00103 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef (); 00104 else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef (); 00105 } 00106 const celData& operator= (const celData& copy) 00107 { 00108 Clear (); 00109 type = copy.type; 00110 value = copy.value; 00111 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef (); 00112 else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef (); 00113 return *this; 00114 } 00115 ~celData() 00116 { 00117 Clear (); 00118 } 00119 void Clear () 00120 { 00121 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->DecRef (); 00122 else if (type == CEL_DATA_PARAMETER) value.par.parname->DecRef (); 00123 type = CEL_DATA_NONE; 00124 } 00128 void Set (bool v) { Clear (); type = CEL_DATA_BOOL; value.bo = v; } 00129 void Set (int8 v) { Clear (); type = CEL_DATA_BYTE; value.b = v; } 00130 void Set (uint8 v) { Clear (); type = CEL_DATA_UBYTE; value.ub = v; } 00131 void Set (int16 v) { Clear (); type = CEL_DATA_WORD; value.w = v; } 00132 void Set (uint16 v) { Clear (); type = CEL_DATA_UWORD; value.uw = v; } 00133 void Set (int32 v) { Clear (); type = CEL_DATA_LONG; value.l = v; } 00134 void Set (uint32 v) { Clear (); type = CEL_DATA_ULONG; value.ul = v; } 00135 void Set (float v) { Clear (); type = CEL_DATA_FLOAT; value.f = v; } 00136 void Set (const csVector2& v) 00137 { 00138 Clear (); 00139 type = CEL_DATA_VECTOR2; 00140 value.v.x = v.x; 00141 value.v.y = v.y; 00142 } 00143 void Set (const csVector3& v) 00144 { 00145 Clear (); 00146 type = CEL_DATA_VECTOR3; 00147 value.v.x = v.x; 00148 value.v.y = v.y; 00149 value.v.z = v.z; 00150 } 00151 void Set (const csVector4& v) 00152 { 00153 Clear (); 00154 type = CEL_DATA_VECTOR4; 00155 value.v.x = v.x; 00156 value.v.y = v.y; 00157 value.v.z = v.z; 00158 value.v.w = v.w; 00159 } 00160 void Set (const csColor& v) 00161 { 00162 Clear (); 00163 type = CEL_DATA_COLOR; 00164 value.col.red = v.red; 00165 value.col.green = v.green; 00166 value.col.blue = v.blue; 00167 } 00168 void Set (const csColor4& v) 00169 { 00170 Clear (); 00171 type = CEL_DATA_COLOR4; 00172 value.col.red = v.red; 00173 value.col.green = v.green; 00174 value.col.blue = v.blue; 00175 value.col.alpha = v.alpha; 00176 } 00177 void Set (const char* s) 00178 { 00179 Clear (); 00180 type = CEL_DATA_STRING; 00181 value.s = new scfString (s); 00182 } 00183 void Set (iCelPropertyClass* pc) 00184 { 00185 Clear (); 00186 type = CEL_DATA_PCLASS; 00187 value.pc = pc; 00188 } 00189 void Set (iCelEntity* ent) 00190 { 00191 Clear (); 00192 type = CEL_DATA_ENTITY; 00193 value.ent = ent; 00194 } 00195 void SetAction (const char* s) 00196 { 00197 Clear (); 00198 type = CEL_DATA_ACTION; 00199 value.s = new scfString (s); 00200 } 00201 void SetIBase (iBase* b) 00202 { 00203 Clear (); 00204 type = CEL_DATA_IBASE; 00205 value.ibase = b; 00206 } 00207 void SetParameter (const char* s, celDataType t) 00208 { 00209 Clear (); 00210 type = CEL_DATA_PARAMETER; 00211 value.par.parname = new scfString (s); 00212 value.par.partype = t; 00213 } 00214 csString GetDebugInfo (); 00215 }; 00216 00217 #endif // __CEL_PL_DATATYPE__ 00218
Generated for CEL: Crystal Entity Layer 1.2 by doxygen 1.4.7
