CEL: Crystal Entity Layer: physicallayer/persist.h Source File (CEL: Crystal Entity Layer Public API Reference)

| ## Public API Reference

- Main Page
- Classes
- Files

# 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
    00059 enum celPersistenceType
    00060 {
    00061   CEL_PERSIST_TYPE_UNDEF = 0,
    00062   CEL_PERSIST_TYPE_RECORD,
    00063   CEL_PERSIST_TYPE_RECORD_FIRST_PASS,
    00064   CEL_PERSIST_TYPE_SERVER_CONTROL,
    00065   CEL_PERSIST_TYPE_CLIENT_CONTROL,
    00066   CEL_PERSIST_TYPE_SERVER_FORCING
    00067 };
    00068
    00084 enum celPersistenceResult
    00085 {
    00086   CEL_PERSIST_RESULT_UNDEF = 0,
    00087   CEL_PERSIST_RESULT_OK,
    00088   CEL_PERSIST_RESULT_CHEAT_SUSPICIOUS,
    00089   CEL_PERSIST_RESULT_CHEAT_CLEAR,
    00090   CEL_PERSIST_RESULT_ERROR,
    00091   CEL_PERSIST_RESULT_UNKNOWN_PC
    00092 };
    00093
    00094 SCF_VERSION (iCelDataBuffer, 0, 0, 2);
    00095
    00099 struct iCelDataBuffer : public iBase
    00100 {
    00106   virtual long GetSerialNumber () const = 0;
    00107
    00111   virtual size_t GetDataCount () const = 0;
    00112
    00116   virtual void Reset () = 0;
    00117
    00121   virtual celData* GetData () = 0;
    00122
    00126   virtual celData* GetData (size_t idx) = 0;
    00127
    00131   virtual celData* AddData () = 0;
    00132
    00134   virtual void Add (bool v) { AddData ()->Set (v); }
    00135   virtual void Add (int8 v) { AddData ()->Set (v); }
    00136   virtual void Add (int16 v) { AddData ()->Set (v); }
    00137   virtual void Add (int32 v) { AddData ()->Set (v); }
    00138   virtual void Add (uint8 v) { AddData ()->Set (v); }
    00139   virtual void Add (uint16 v) { AddData ()->Set (v); }
    00140   virtual void Add (uint32 v) { AddData ()->Set (v); }
    00141   virtual void Add (float v) { AddData ()->Set (v); }
    00142   virtual void Add (const csVector2& v) { AddData ()->Set (v); }
    00143   virtual void Add (const csVector3& v) { AddData ()->Set (v); }
    00144   virtual void Add (const csColor& v) { AddData ()->Set (v); }
    00145   virtual void Add (const char* v) { AddData ()->Set (v); }
    00146   virtual void Add (iCelPropertyClass* v) { AddData ()->Set (v); }
    00147   virtual void Add (iCelEntity* v) { AddData ()->Set (v); }
    00148   virtual void AddAction (const char* v) { AddData ()->SetAction (v); }
    00149   virtual void AddIBase (iBase* v) { AddData ()->SetIBase (v); }
    00150
    00152   virtual bool GetBool ()
    00153   {
    00154     celData* cd = GetData ();
    00155     return (cd && cd->type == CEL_DATA_BOOL) ? cd->value.bo : false;
    00156   }
    00157   virtual int8 GetInt8 ()
    00158   {
    00159     celData* cd = GetData ();
    00160     return (cd && cd->type == CEL_DATA_BYTE) ? cd->value.b : 0;
    00161   }
    00162   virtual uint8 GetUInt8 ()
    00163   {
    00164     celData* cd = GetData ();
    00165     return (cd && cd->type == CEL_DATA_UBYTE) ? cd->value.ub : 0;
    00166   }
    00167   virtual int16 GetInt16 ()
    00168   {
    00169     celData* cd = GetData ();
    00170     return (cd && cd->type == CEL_DATA_WORD) ? cd->value.w : 0;
    00171   }
    00172   virtual uint16 GetUInt16 ()
    00173   {
    00174     celData* cd = GetData ();
    00175     return (cd && cd->type == CEL_DATA_UWORD) ? cd->value.uw : 0;
    00176   }
    00177   virtual int32 GetInt32 ()
    00178   {
    00179     celData* cd = GetData ();
    00180     return (cd && cd->type == CEL_DATA_LONG) ? cd->value.l : 0;
    00181   }
    00182   virtual uint32 GetUInt32 ()
    00183   {
    00184     celData* cd = GetData ();
    00185     return (cd && cd->type == CEL_DATA_ULONG) ? cd->value.ul : 0;
    00186   }
    00187   virtual float GetFloat ()
    00188   {
    00189     celData* cd = GetData ();
    00190     return (cd && cd->type == CEL_DATA_FLOAT) ? cd->value.f : 0.0f;
    00191   }
    00192   virtual iString* GetString ()
    00193   {
    00194     celData* cd = GetData ();
    00195     return (cd && cd->type == CEL_DATA_STRING) ? cd->value.s : (iString*)0;
    00196   }
    00197   virtual void GetVector2 (csVector2& v)
    00198   {
    00199     celData* cd = GetData ();
    00200     if (cd && cd->type == CEL_DATA_VECTOR2)
    00201     { v.x = cd->value.v.x; v.y = cd->value.v.y; }
    00202     else v.x = v.y = 0;
    00203   }
    00204   virtual void GetVector3 (csVector3& v)
    00205   {
    00206     celData* cd = GetData ();
    00207     if (cd && cd->type == CEL_DATA_VECTOR3)
    00208     { v.x = cd->value.v.x; v.y = cd->value.v.y; v.z = cd->value.v.z; }
    00209     else v.x = v.y = v.z = 0;
    00210   }
    00211   virtual void GetColor (csColor& v)
    00212   {
    00213     celData* cd = GetData ();
    00214     if (cd && cd->type == CEL_DATA_COLOR)
    00215     {
    00216       v.red = cd->value.col.red;
    00217       v.green = cd->value.col.green;
    00218       v.blue = cd->value.col.blue;
    00219     }
    00220     else v.red = v.green= v.blue = 0;
    00221   }
    00222   virtual iCelPropertyClass* GetPC ()
    00223   {
    00224     celData* cd = GetData ();
    00225     return (cd && cd->type == CEL_DATA_PCLASS)
    00226         ? cd->value.pc
    00227         : (iCelPropertyClass*)0;
    00228   }
    00229   virtual iCelEntity* GetEntity ()
    00230   {
    00231     celData* cd = GetData ();
    00232     return (cd && cd->type == CEL_DATA_ENTITY)
    00233         ? cd->value.ent
    00234         : (iCelEntity*)0;
    00235   }
    00236   virtual iBase* GetIBase ()
    00237   {
    00238     celData* cd = GetData ();
    00239     return (cd && cd->type == CEL_DATA_IBASE) ? cd->value.ibase : (iBase*)0;
    00240   }
    00241   virtual csString GetDebugInfo ()
    00242   {
    00243     if (GetDataCount () == 0) return "Data buffer: empty\n";
    00244
    00245     csString txt = "Data buffer:\n";
    00246     size_t i = 0, count = GetDataCount ();
    00247     for ( ; i < count; i++)
    00248       txt.AppendFmt("\t%s\n", GetData (i)->GetDebugInfo ().GetData ());
    00249
    00250     return txt;
    00251   }
    00252 };
    00253
    00254 SCF_VERSION (iCelPersistentDataList, 0, 0, 1);
    00255
    00262 struct iCelPersistentDataList : public iBase
    00263 {
    00267   virtual size_t GetCount () const = 0;
    00268
    00278   virtual bool GetPersistentData (size_t idx, csRef<iCelDataBuffer>& databuf,
    00279         csString& pc_name, csString& pc_tag) const = 0;
    00280
    00290   virtual void AddPersistentData (csRef<iCelDataBuffer>& databuf,
    00291         csString& pc_name, csString& pc_tag) = 0;
    00292 };
    00293
    00294 SCF_VERSION (iCelLocalEntitySet, 0, 0, 1);
    00295
    00303 struct iCelLocalEntitySet : public iBase
    00304 {
    00306   virtual size_t GetEntityCount () const = 0;
    00307
    00309   virtual iCelEntity* GetEntity (size_t idx) const = 0;
    00310
    00312   virtual void AddEntity (iCelEntity* entity) = 0;
    00313
    00315   virtual bool IsLocal (iCelEntity* entity) = 0;
    00317   virtual bool IsLocal (iCelPropertyClass* pc) = 0;
    00318
    00324   virtual csPtr<iCelDataBuffer> SaveExternalEntity (iCelEntity* entity) = 0;
    00325
    00331   virtual iCelEntity* FindExternalEntity (iCelDataBuffer* databuf) = 0;
    00332
    00338   virtual csPtr<iCelDataBuffer> SaveExternalPC (iCelPropertyClass* pc) = 0;
    00339
    00345   virtual iCelPropertyClass* FindExternalPC (iCelDataBuffer* databuf) = 0;
    00346 };
    00347
    00348 SCF_VERSION (iCelPersistence, 0, 1, 1);
    00349
    00354 struct iCelPersistence : public iBase
    00355 {
    00365   virtual bool Load (iCelLocalEntitySet* set, const char* name) = 0;
    00366
    00375   virtual bool Save (iCelLocalEntitySet* set, const char* name) = 0;
    00376
    00384   virtual bool Load (iCelLocalEntitySet* set, iFile* file) = 0;
    00385
    00392   virtual bool Save (iCelLocalEntitySet* set, iFile* file) = 0;
    00393 };
    00394
    00395 #endif // __CEL_PL_PERSIST__