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