00001 #ifndef __STORE_COMMON_H
00002 #define __STORE_COMMON_H
00003
00004 #include "GPassword.h"
00005
00006 class StorageItem;
00007 class StorageObj;
00008 class StorageKit;
00009
00010 enum NodeRelation
00011 {
00012 NodeChild,
00013 NodeNext,
00014 NodePrev,
00015 };
00016
00017 class GSubFilePtr;
00018 class GSubFile : public GFile
00019 {
00020 GSemaphore *Lck;
00021 GArray<GSubFilePtr*> Ptrs;
00022
00023 public:
00024 GSubFile(GSemaphore *lock);
00025 ~GSubFile();
00026
00027 GSubFilePtr *Create(char *file, int line);
00028 void Detach(GSubFilePtr *Ptr);
00029 bool Lock();
00030 bool LockWithTimeout(int Timeout );
00031 void Unlock();
00032 };
00033
00034 class GSubFilePtr : public GFile
00035 {
00036 friend class GSubFile;
00037 GSubFile *File;
00038
00039
00040 bool Sub;
00041 int64 Start;
00042 int64 Len;
00043
00044
00045 char *SrcFile;
00046 int SrcLine;
00047
00048
00049 int64 OurPos;
00050 bool OurStatus;
00051 bool OurSwap;
00052
00053
00054 int64 ActualPos;
00055 bool ActualStatus;
00056 bool ActualSwap;
00057
00058 bool SaveState();
00059 bool RestoreState();
00060
00061 public:
00062 GSubFilePtr(GSubFile *Parent, char *file, int line);
00063 ~GSubFilePtr();
00064
00066 void SetSub
00067 (
00069 int start,
00071 int len
00072 );
00073
00075 void ClearSub();
00076
00077
00078 int Open(char *Str = 0, int Int = 0);
00079 bool IsOpen();
00080 int Close();
00081 int64 GetSize();
00082 int64 SetSize(int64 Size);
00083 int64 GetPos();
00084 int64 SetPos(int64 pos);
00085 int64 Seek(int64 To, int Whence);
00086 GStream *Clone();
00087 bool Eof();
00088 bool GetStatus();
00089 void SetStatus(bool s);
00090 int Read(void *Buffer, int Size, int Flags = 0);
00091 int Write(void *Buffer, int Size, int Flags = 0);
00092 int ReadStr(char *Buf, int Size);
00093 int WriteStr(char *Buf, int Size);
00094 int Print(char *Format, ...);
00095 };
00096
00097 class StorageItem
00098 {
00099 public:
00100 StorageObj *Object;
00101
00102 virtual ~StorageItem() {}
00103
00104
00105 virtual int GetType() = 0;
00106 virtual void SetType(int i) = 0;
00107 virtual int GetTotalSize() = 0;
00108 virtual int GetObjectSize() = 0;
00109 virtual StorageKit *GetTree() = 0;
00110
00111
00112 virtual StorageItem *GetNext() = 0;
00113 virtual StorageItem *GetPrev() = 0;
00114 virtual StorageItem *GetParent() = 0;
00115 virtual StorageItem *GetChild() = 0;
00116 virtual StorageItem *CreateNext(StorageObj *Obj) = 0;
00117 virtual StorageItem *CreateChild(StorageObj *Obj) = 0;
00118 virtual StorageItem *CreateSub(StorageObj *Obj) = 0;
00119 virtual bool DeleteChild(StorageItem *Obj) = 0;
00120 virtual bool DeleteAllChildren() = 0;
00121
00122
00123 virtual bool Save() = 0;
00124 virtual GFile *GotoObject(char *file, int line) = 0;
00125 virtual bool EndOfObj(GFile &f) = 0;
00126 };
00127
00128 class StorageObj
00129 {
00130 friend class StorageKit;
00131
00132 bool StoreDirty;
00133
00134 public:
00135 StorageItem *Store;
00136
00137 StorageObj()
00138 {
00139 StoreDirty = false;
00140 Store = 0;
00141 }
00142
00143 virtual ~StorageObj()
00144 {
00145 if (Store)
00146 {
00147 Store->Object = 0;
00148 DeleteObj(Store);
00149 }
00150 }
00151
00152 bool GetDirty() { return StoreDirty; }
00153
00154 virtual int Type() = 0;
00155 virtual int Sizeof() = 0;
00156 virtual bool Serialize(GFile &f, bool Write) = 0;
00157 virtual bool SetDirty(bool d = true) { StoreDirty = d; return true; }
00158 };
00159
00160 class StorageValidator
00161 {
00162 public:
00163 virtual bool CompactValidate(GView *Parent, StorageItem *Item) = 0;
00164 virtual void CompactDone(StorageItem *Item) = 0;
00165 };
00166
00167 class StorageKit
00168 {
00169 protected:
00170 void StorageObj_SetDirty(StorageObj *Obj, bool d)
00171 {
00172 Obj->StoreDirty = d;
00173 }
00174
00175 public:
00176 virtual ~StorageKit() {}
00177
00178
00179 virtual int GetStatus() = 0;
00180 virtual bool GetReadOnly() = 0;
00181 virtual int GetVersion() = 0;
00182 virtual uint64 GetFileSize() = 0;
00183 virtual bool GetPassword(GPassword *p) = 0;
00184 virtual bool SetPassword(GPassword *p) = 0;
00185 virtual GSemaphore *GetLock() = 0;
00186 virtual char *GetFileName() = 0;
00187
00188
00189 virtual StorageItem *GetRoot() = 0;
00190 virtual StorageItem *CreateRoot(StorageObj *Obj) = 0;
00191 virtual bool DeleteItem(StorageItem *Item) = 0;
00192 virtual bool SeparateItem(StorageItem *Item) = 0;
00193 virtual bool AttachItem(StorageItem *Item, StorageItem *To, NodeRelation Relationship = NodeChild) = 0;
00194
00195
00196 virtual bool Compact(Progress *p, bool Interactive, StorageValidator *Validator = 0) = 0;
00197 };
00198
00199 #endif