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_UNKNOWN = -1, 00043 CEL_DATA_NONE = 0, 00045 CEL_DATA_BOOL, 00047 CEL_DATA_BYTE, 00049 CEL_DATA_WORD, 00051 CEL_DATA_LONG, 00053 CEL_DATA_UBYTE, 00055 CEL_DATA_UWORD, 00057 CEL_DATA_ULONG, 00059 CEL_DATA_FLOAT, 00061 CEL_DATA_VECTOR2, 00063 CEL_DATA_VECTOR3, 00065 CEL_DATA_VECTOR4, 00067 CEL_DATA_STRING, 00069 CEL_DATA_PCLASS, 00071 CEL_DATA_ENTITY, 00073 CEL_DATA_ACTION, 00075 CEL_DATA_COLOR, 00077 CEL_DATA_COLOR4, 00079 CEL_DATA_IBASE, 00081 CEL_DATA_PARAMETER, 00083 CEL_DATA_LAST 00084 }; 00085 00089 struct celData 00090 { 00091 celDataType type; 00092 union 00093 { 00094 bool bo; 00095 int8 b; 00096 uint8 ub; 00097 int16 w; 00098 uint16 uw; 00099 int32 l; 00100 uint32 ul; 00101 float f; 00102 iString* s; 00103 struct 00104 { 00105 float x, y, z, w; 00106 } v; 00107 struct 00108 { 00109 float red, green, blue, alpha; 00110 } col; 00111 iCelPropertyClass* pc; 00112 iCelEntity* ent; 00113 iBase* ibase; 00114 struct 00115 { 00116 iString* parname; 00117 celDataType partype; 00118 } par; 00119 } value; 00120 00121 celData () : type (CEL_DATA_NONE) { } 00122 celData (const celData& copy) 00123 { 00124 type = copy.type; 00125 value = copy.value; 00126 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef (); 00127 else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef (); 00128 } 00129 const celData& operator= (const celData& copy) 00130 { 00131 Copy (copy); 00132 return *this; 00133 } 00134 ~celData() 00135 { 00136 Clear (); 00137 } 00138 00139 void Copy (const celData& copy) 00140 { 00141 Clear (); 00142 type = copy.type; 00143 value = copy.value; 00144 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->IncRef (); 00145 else if (type == CEL_DATA_PARAMETER) value.par.parname->IncRef (); 00146 } 00147 00148 bool operator== (const celData& other) const 00149 { 00150 if (type != other.type) return false; 00151 switch (type) 00152 { 00153 case CEL_DATA_NONE: return true; 00154 case CEL_DATA_BOOL: return value.bo == other.value.bo; 00155 case CEL_DATA_BYTE: return value.b == other.value.b; 00156 case CEL_DATA_WORD: return value.w == other.value.w; 00157 case CEL_DATA_LONG: return value.l == other.value.l; 00158 case CEL_DATA_UBYTE: return value.ub == other.value.ub; 00159 case CEL_DATA_UWORD: return value.uw == other.value.uw; 00160 case CEL_DATA_ULONG: return value.ul == other.value.ul; 00161 case CEL_DATA_FLOAT: return value.f == other.value.f; 00162 case CEL_DATA_VECTOR2: return value.v.x == other.value.v.x && 00163 value.v.y == other.value.v.y; 00164 case CEL_DATA_VECTOR3: return value.v.x == other.value.v.x && 00165 value.v.y == other.value.v.y && 00166 value.v.z == other.value.v.z; 00167 case CEL_DATA_VECTOR4: return value.v.x == other.value.v.x && 00168 value.v.y == other.value.v.y && 00169 value.v.z == other.value.v.z && 00170 value.v.w == other.value.v.w; 00171 case CEL_DATA_STRING: return value.s == other.value.s; 00172 case CEL_DATA_PCLASS: return value.pc == other.value.pc; 00173 case CEL_DATA_ENTITY: return value.ent == other.value.ent; 00174 case CEL_DATA_ACTION: return value.s == other.value.s; 00175 case CEL_DATA_COLOR: return value.col.red == other.value.col.red && 00176 value.col.green == other.value.col.green && 00177 value.col.blue == other.value.col.blue; 00178 case CEL_DATA_COLOR4: return value.col.red == other.value.col.red && 00179 value.col.green == other.value.col.green && 00180 value.col.blue == other.value.col.blue && 00181 value.col.alpha == other.value.col.alpha; 00182 case CEL_DATA_IBASE: return value.ibase == other.value.ibase; 00183 case CEL_DATA_PARAMETER: return value.par.partype == other.value.par.partype && 00184 value.par.parname == other.value.par.parname; 00185 default: 00186 printf ("INTERNAL ERROR! Bad type %d\n", type); 00187 fflush (stdout); 00188 return false; 00189 } 00190 } 00191 00192 void Clear () 00193 { 00194 if (type == CEL_DATA_STRING || type == CEL_DATA_ACTION) value.s->DecRef (); 00195 else if (type == CEL_DATA_PARAMETER) value.par.parname->DecRef (); 00196 type = CEL_DATA_NONE; 00197 } 00201 void Set (bool v) { Clear (); type = CEL_DATA_BOOL; value.bo = v; } 00202 void Set (int8 v) { Clear (); type = CEL_DATA_BYTE; value.b = v; } 00203 void Set (uint8 v) { Clear (); type = CEL_DATA_UBYTE; value.ub = v; } 00204 void Set (int16 v) { Clear (); type = CEL_DATA_WORD; value.w = v; } 00205 void Set (uint16 v) { Clear (); type = CEL_DATA_UWORD; value.uw = v; } 00206 void Set (int32 v) { Clear (); type = CEL_DATA_LONG; value.l = v; } 00207 void Set (uint32 v) { Clear (); type = CEL_DATA_ULONG; value.ul = v; } 00208 void Set (float v) { Clear (); type = CEL_DATA_FLOAT; value.f = v; } 00209 void Set (const csVector2& v) 00210 { 00211 Clear (); 00212 type = CEL_DATA_VECTOR2; 00213 value.v.x = v.x; 00214 value.v.y = v.y; 00215 } 00216 void Set (const csVector3& v) 00217 { 00218 Clear (); 00219 type = CEL_DATA_VECTOR3; 00220 value.v.x = v.x; 00221 value.v.y = v.y; 00222 value.v.z = v.z; 00223 } 00224 void Set (const csVector4& v) 00225 { 00226 Clear (); 00227 type = CEL_DATA_VECTOR4; 00228 value.v.x = v.x; 00229 value.v.y = v.y; 00230 value.v.z = v.z; 00231 value.v.w = v.w; 00232 } 00233 void Set (const csColor& v) 00234 { 00235 Clear (); 00236 type = CEL_DATA_COLOR; 00237 value.col.red = v.red; 00238 value.col.green = v.green; 00239 value.col.blue = v.blue; 00240 } 00241 void Set (const csColor4& v) 00242 { 00243 Clear (); 00244 type = CEL_DATA_COLOR4; 00245 value.col.red = v.red; 00246 value.col.green = v.green; 00247 value.col.blue = v.blue; 00248 value.col.alpha = v.alpha; 00249 } 00250 void Set (const char* s) 00251 { 00252 Clear (); 00253 type = CEL_DATA_STRING; 00254 value.s = new scfString (s); 00255 } 00256 void Set (iCelPropertyClass* pc) 00257 { 00258 Clear (); 00259 type = CEL_DATA_PCLASS; 00260 value.pc = pc; 00261 } 00262 void Set (iCelEntity* ent) 00263 { 00264 Clear (); 00265 type = CEL_DATA_ENTITY; 00266 value.ent = ent; 00267 } 00268 void SetAction (const char* s) 00269 { 00270 Clear (); 00271 type = CEL_DATA_ACTION; 00272 value.s = new scfString (s); 00273 } 00274 void SetIBase (iBase* b) 00275 { 00276 Clear (); 00277 type = CEL_DATA_IBASE; 00278 value.ibase = b; 00279 } 00280 void SetParameter (const char* s, celDataType t) 00281 { 00282 Clear (); 00283 type = CEL_DATA_PARAMETER; 00284 value.par.parname = new scfString (s); 00285 value.par.partype = t; 00286 } 00287 }; 00288 00289 struct iCelDataArrayReadOnly : public iArrayReadOnly<celData> 00290 { 00291 SCF_IARRAYREADONLY_INTERFACE(iCelDataArrayReadOnly); 00292 }; 00293 00294 struct iCelDataArray : public iArrayChangeAll<celData> 00295 { 00296 SCF_IARRAYCHANGEALL_INTERFACE(iCelDataArray); 00297 }; 00298 00299 #endif // __CEL_PL_DATATYPE__ 00300
Generated for CEL: Crystal Entity Layer 2.1 by doxygen 1.6.1
