00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __STORE_H
00012 #define __STORE_H
00013
00014 #include "Gdc2.h"
00015 #include "GContainers.h"
00016 #include "Progress.h"
00017 #include "StoreCommon.h"
00018
00019 namespace Storage1
00020 {
00021 #define STORAGE_ITEM_MAGIC 0x123400AA
00022 #define STORAGE_ITEM_NOSIZE 0x0001
00023 #define STORAGE_MAGIC 0x123400FF
00024
00025 class StorageKitImpl;
00026 class StorageItemImpl;
00027
00028 struct StorageItemHeader {
00029
00030 int Magic;
00031 int Type;
00032 int ObjSize;
00033 int AllocatedSize;
00034
00035 int Next;
00036 int Prev;
00037 int Parent;
00038 int Child;
00039
00040 };
00041
00042 class StorageItemImpl : public GBase, public StorageItem
00043 {
00044 friend class StorageKitImpl;
00045 friend class StoreRef;
00046
00047 private:
00048 int Sizeof();
00049 bool SetSize(int NewSize);
00050 bool MoveToLoc(int NewLoc);
00051 bool WriteHeader(GFile &f);
00052
00053 StorageKitImpl *Tree;
00054
00055 public:
00056 bool Serialize(GFile &f, bool Write, int Flags = 0);
00057
00058 int StoreType;
00059 int StoreSize;
00060 int StoreAllocatedSize;
00061 int StoreLoc;
00062 int StoreNext;
00063 int StorePrev;
00064 int StoreParent;
00065 int StoreChild;
00066
00067 StorageItemImpl *Next;
00068 StorageItemImpl *Prev;
00069 StorageItemImpl *Parent;
00070 StorageItemImpl *Child;
00071
00072 StorageItemImpl();
00073 ~StorageItemImpl();
00074
00075
00076 StorageItem *GetNext();
00077 StorageItem *GetPrev();
00078 StorageItem *GetParent();
00079 StorageItem *GetChild();
00080
00081 StorageItem *CreateNext(StorageObj *Obj);
00082 StorageItem *CreateChild(StorageObj *Obj);
00083 StorageItem *CreateSub(StorageObj *Obj);
00084 bool DeleteChild(StorageItem *Obj);
00085 bool DeleteAllChildren();
00086
00087
00088 int GetType();
00089 void SetType(int i);
00090 int GetTotalSize();
00091 int GetObjectSize();
00092 StorageKit *GetTree();
00093
00094
00095 bool Save();
00096 GFile *GotoObject(const char *file, int line);
00097 bool EndOfObj(GFile &f);
00098 };
00099
00100 class Block {
00101 public:
00102 StorageItemImpl *Item;
00103 int Size;
00104 };
00105
00106 struct StorageHeader {
00107
00108 int Magic;
00109 int Version;
00110 int Reserved2;
00111 int FirstLoc;
00112 int Reserved3[12];
00113 };
00114
00115 class StorageKitImpl : public GBase, public StorageKit
00116 {
00117 friend class StorageItemImpl;
00118
00119 private:
00120 GSemaphore Lock;
00121 char *FileName;
00122 GSubFile File;
00123 bool Status;
00124 int StoreLoc;
00125 int Version;
00126 StorageItemImpl *Root;
00127 bool ReadOnly;
00128
00129 uint UserData;
00130 StorageValidator *Validator;
00131
00132 void AddItem( StorageItemImpl *Item,
00133 List<Block> &Blocks);
00134 StorageItemImpl *CreateItem(StorageObj *Obj);
00135 StorageItemImpl *LoadLocation(int Loc);
00136 bool Serialize(GFile &f, bool Write);
00137 bool SerializeItem(StorageItem *Item, bool Write, int Flags = 0)
00138 {
00139 return (Item) ? ((StorageItemImpl*)Item)->Serialize(File, Write, Flags) : 0;
00140 }
00141
00142 public:
00143 StorageKitImpl(char *FileName);
00144 ~StorageKitImpl();
00145
00146 int GetStatus() { return Status; }
00147 bool GetReadOnly() { return ReadOnly; }
00148 int GetVersion() { return Version; }
00149 void SetVersion(int i);
00150 uint64 GetFileSize();
00151 bool GetPassword(GPassword *p) { return false; }
00152 bool SetPassword(GPassword *p) { return false; }
00153 GSemaphore *GetLock() { return &Lock; }
00154 char *GetFileName() { return FileName; }
00155
00156 StorageItem *GetRoot();
00157 StorageItem *CreateRoot(StorageObj *Obj);
00158
00159 bool Compact(Progress *p, bool Interactive, StorageValidator *Validator = 0);
00160 bool DeleteItem(StorageItem *Item);
00161 bool SeparateItem(StorageItem *Item);
00162 bool AttachItem(StorageItem *Item, StorageItem *To, NodeRelation Relationship = NodeChild);
00163 };
00164 }
00165
00166 #endif