CEL

Public API Reference

physicallayer/persist.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,
00018     MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __CEL_PL_PERSIST__
00022 #define __CEL_PL_PERSIST__
00023 
00024 #include "cstypes.h"
00025 #include "csutil/scf.h"
00026 #include "csutil/util.h"
00027 #include "csutil/array.h"
00028 
00029 #include "physicallayer/datatype.h"
00030 
00031 struct iCelPropertyClass;
00032 struct iCelEntity;
00033 struct iFile;
00034 struct celData;
00035 
00057 enum celPersistenceType
00058 {
00059   CEL_PERSIST_TYPE_UNDEF = 0,
00060   CEL_PERSIST_TYPE_RECORD,
00061   CEL_PERSIST_TYPE_RECORD_FIRST_PASS,
00062   CEL_PERSIST_TYPE_SERVER_CONTROL,
00063   CEL_PERSIST_TYPE_CLIENT_CONTROL,
00064   CEL_PERSIST_TYPE_SERVER_FORCING
00065 };
00066 
00080 enum celPersistenceResult
00081 {
00082   CEL_PERSIST_RESULT_UNDEF = 0,
00083   CEL_PERSIST_RESULT_OK,
00084   CEL_PERSIST_RESULT_CHEAT_SUSPICIOUS,
00085   CEL_PERSIST_RESULT_CHEAT_CLEAR,
00086   CEL_PERSIST_RESULT_ERROR,
00087   CEL_PERSIST_RESULT_UNKNOWN_PC
00088 };
00089 
00093 struct iCelDataBuffer : public virtual iBase
00094 {
00095   SCF_INTERFACE (iCelDataBuffer, 0, 0, 2);
00096 
00102   virtual long GetSerialNumber () const = 0;
00103 
00107   virtual size_t GetDataCount () const = 0;
00108 
00112   virtual void Reset () = 0;
00113 
00117   virtual celData* GetData () = 0;
00118 
00122   virtual celData* GetData (size_t idx) = 0;
00123 
00127   virtual celData* AddData () = 0;
00128 
00130   virtual void Add (bool v) { AddData ()->Set (v); }
00131   virtual void Add (int8 v) { AddData ()->Set (v); }
00132   virtual void Add (int16 v) { AddData ()->Set (v); }
00133   virtual void Add (int32 v) { AddData ()->Set (v); }
00134   virtual void Add (uint8 v) { AddData ()->Set (v); }
00135   virtual void Add (uint16 v) { AddData ()->Set (v); }
00136   virtual void Add (uint32 v) { AddData ()->Set (v); }
00137   virtual void Add (float v) { AddData ()->Set (v); }
00138   virtual void Add (const csVector2& v) { AddData ()->Set (v); }
00139   virtual void Add (const csVector3& v) { AddData ()->Set (v); }
00140   virtual void Add (const csColor& v) { AddData ()->Set (v); }
00141   virtual void Add (const char* v) { AddData ()->Set (v); }
00142   virtual void Add (iCelPropertyClass* v) { AddData ()->Set (v); }
00143   virtual void Add (iCelEntity* v) { AddData ()->Set (v); }
00144   virtual void AddAction (const char* v) { AddData ()->SetAction (v); }
00145   virtual void AddIBase (iBase* v) { AddData ()->SetIBase (v); }
00146 
00148   virtual bool GetBool ()
00149   {
00150     celData* cd = GetData ();
00151     return (cd && cd->type == CEL_DATA_BOOL) ? cd->value.bo : false;
00152   }
00153   virtual int8 GetInt8 ()
00154   {
00155     celData* cd = GetData ();
00156     return (cd && cd->type == CEL_DATA_BYTE) ? cd->value.b : 0;
00157   }
00158   virtual uint8 GetUInt8 ()
00159   {
00160     celData* cd = GetData ();
00161     return (cd && cd->type == CEL_DATA_UBYTE) ? cd->value.ub : 0;
00162   }
00163   virtual int16 GetInt16 ()
00164   {
00165     celData* cd = GetData ();
00166     return (cd && cd->type == CEL_DATA_WORD) ? cd->value.w : 0;
00167   }
00168   virtual uint16 GetUInt16 ()
00169   {
00170     celData* cd = GetData ();
00171     return (cd && cd->type == CEL_DATA_UWORD) ? cd->value.uw : 0;
00172   }
00173   virtual int32 GetInt32 ()
00174   {
00175     celData* cd = GetData ();
00176     return (cd && cd->type == CEL_DATA_LONG) ? cd->value.l : 0;
00177   }
00178   virtual uint32 GetUInt32 ()
00179   {
00180     celData* cd = GetData ();
00181     return (cd && cd->type == CEL_DATA_ULONG) ? cd->value.ul : 0;
00182   }
00183   virtual float GetFloat ()
00184   {
00185     celData* cd = GetData ();
00186     return (cd && cd->type == CEL_DATA_FLOAT) ? cd->value.f : 0.0f;
00187   }
00188   virtual iString* GetString ()
00189   {
00190     celData* cd = GetData ();
00191     return (cd && cd->type == CEL_DATA_STRING) ? cd->value.s : (iString*)0;
00192   }
00193   virtual void GetVector2 (csVector2& v)
00194   {
00195     celData* cd = GetData ();
00196     if (cd && cd->type == CEL_DATA_VECTOR2)
00197     { v.x = cd->value.v.x; v.y = cd->value.v.y; }
00198     else v.x = v.y = 0;
00199   }
00200   virtual void GetVector3 (csVector3& v)
00201   {
00202     celData* cd = GetData ();
00203     if (cd && cd->type == CEL_DATA_VECTOR3)
00204     { v.x = cd->value.v.x; v.y = cd->value.v.y; v.z = cd->value.v.z; }
00205     else v.x = v.y = v.z = 0;
00206   }
00207   virtual void GetColor (csColor& v)
00208   {
00209     celData* cd = GetData ();
00210     if (cd && cd->type == CEL_DATA_COLOR)
00211     {
00212       v.red = cd->value.col.red;
00213       v.green = cd->value.col.green;
00214       v.blue = cd->value.col.blue;
00215     }
00216     else v.red = v.green= v.blue = 0;
00217   }
00218   virtual iCelPropertyClass* GetPC ()
00219   {
00220     celData* cd = GetData ();
00221     return (cd && cd->type == CEL_DATA_PCLASS)
00222         ? cd->value.pc
00223         : (iCelPropertyClass*)0;
00224   }
00225   virtual iCelEntity* GetEntity ()
00226   {
00227     celData* cd = GetData ();
00228     return (cd && cd->type == CEL_DATA_ENTITY)
00229         ? cd->value.ent
00230         : (iCelEntity*)0;
00231   }
00232   virtual iBase* GetIBase ()
00233   {
00234     celData* cd = GetData ();
00235     return (cd && cd->type == CEL_DATA_IBASE) ? cd->value.ibase : (iBase*)0;
00236   }
00237   virtual csString GetDebugInfo ()
00238   {
00239     if (GetDataCount () == 0) return "Data buffer: empty\n";
00240 
00241     csString txt = "Data buffer:\n";
00242     size_t i = 0, count = GetDataCount ();
00243     for ( ; i < count; i++)
00244       txt.AppendFmt("\t%s\n", GetData (i)->GetDebugInfo ().GetData ());
00245 
00246     return txt;
00247   }
00248 };
00249 
00256 struct iCelPersistentDataList : public virtual iBase
00257 {
00258   SCF_INTERFACE (iCelPersistentDataList, 0, 0, 1);
00259 
00263   virtual size_t GetCount () const = 0;
00264 
00274   virtual bool GetPersistentData (size_t idx, csRef<iCelDataBuffer>& databuf, 
00275         csString& pc_name, csString& pc_tag) const = 0;
00276 
00286   virtual void AddPersistentData (csRef<iCelDataBuffer>& databuf, 
00287         csString& pc_name, csString& pc_tag) = 0;
00288 };
00289 
00297 struct iCelLocalEntitySet : public virtual iBase
00298 {
00299   SCF_INTERFACE (iCelLocalEntitySet, 0, 0, 1);
00300 
00302   virtual size_t GetEntityCount () const = 0;
00303   
00305   virtual iCelEntity* GetEntity (size_t idx) const = 0;
00306 
00308   virtual void AddEntity (iCelEntity* entity) = 0;
00309 
00311   virtual bool IsLocal (iCelEntity* entity) = 0;
00313   virtual bool IsLocal (iCelPropertyClass* pc) = 0;
00314 
00320   virtual csPtr<iCelDataBuffer> SaveExternalEntity (iCelEntity* entity) = 0;
00321 
00327   virtual iCelEntity* FindExternalEntity (iCelDataBuffer* databuf) = 0;
00328 
00334   virtual csPtr<iCelDataBuffer> SaveExternalPC (iCelPropertyClass* pc) = 0;
00335 
00341   virtual iCelPropertyClass* FindExternalPC (iCelDataBuffer* databuf) = 0;
00342 };
00343 
00348 struct iCelPersistence : public virtual iBase
00349 {
00350   SCF_INTERFACE (iCelPersistence, 0, 1, 1);
00351 
00361   virtual bool Load (iCelLocalEntitySet* set, const char* name) = 0;
00362 
00371   virtual bool Save (iCelLocalEntitySet* set, const char* name) = 0;
00372 
00380   virtual bool Load (iCelLocalEntitySet* set, iFile* file) = 0;
00381 
00388   virtual bool Save (iCelLocalEntitySet* set, iFile* file) = 0;
00389 };
00390 
00391 #endif // __CEL_PL_PERSIST__

Generated for CEL: Crystal Entity Layer 1.2 by doxygen 1.4.7