Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

Store2.h

00001 /*hdr
00002 **      FILE:           Store.h
00003 **      AUTHOR:         Matthew Allen
00004 **      DATE:           29/10/98
00005 **      DESCRIPTION:    Tree storage
00006 **
00007 **      Copyright (C) 1998 Matthew Allen
00008 **              fret@memecode.com
00009 */
00010 
00011 #ifndef __STORE2_H
00012 #define __STORE2_H
00013 
00014 #include "Gdc2.h"
00015 #include "GContainers.h"
00016 #include "Progress.h"
00017 #include "StoreCommon.h"
00018 
00019 class WriterItem;
00020 class GSubFilePtr;
00021 
00022 namespace Storage2
00023 {
00024     #define STORAGE2_ITEM_MAGIC     0x123400AB
00025     #define STORAGE2_MAGIC          0x123400FE
00026 
00027     class StorageKitImpl;
00028     class StorageItemImpl;
00029     class StorageKitImplPrivate;
00030 
00031     struct StorageItemHeader
00032     {
00033         uint32 Magic;           // sanity check, always == STORAGE2_ITEM_MAGIC
00034 
00035         // object descriptor
00036         uint32 Type;            // application defined object type
00037         uint32 DataLoc;         // location in file of this objects data segment
00038         uint32 DataSize;        // size of this objects data segment
00039         
00040         // heirarchy descriptor
00041         uint32 ParentLoc;       // file location of objects parent
00042         uint32 DirLoc;          // file location of the child directory
00043         uint32 DirCount;        // number of elements in the child directory array
00044         uint32 DirAlloc;        // numder of allocated elements in child directory
00045 
00046         // file io
00047         StorageItemHeader();
00048         bool Serialize(GFile &f, bool Write);
00049     };
00050 
00051     class StorageItemImpl : public StorageItem
00052     {
00053         friend class StorageKitImpl;
00054         friend class StorageKitImplPrivate;
00055         friend class StorageObj;
00056         
00057         friend class WriterItem;
00058 
00059     private:
00060         uint32 StoreLoc;
00061         bool HeaderDirty;
00062         StorageItemHeader *Header;      // pointer to our block in the parents Dir array
00063         StorageItemHeader *Dir;         // an array of children
00064         StorageItemHeader *Temp;        // we own this block of memory
00065 
00066         StorageItemImpl *Next;
00067         StorageItemImpl *Prev;
00068         StorageItemImpl *Parent;
00069         StorageItemImpl *Child;
00070 
00071         StorageKitImpl *Tree;
00072 
00073         bool IncDirSize();
00074         bool DirChange();
00075 
00076         bool SetDirty(bool Dirty);
00077         bool SerializeHeader(GFile &f, bool Write);
00078         bool SerializeObject(GSubFilePtr &f, bool Write);
00079         
00081         void CleanAll();
00082 
00083     public:
00084         StorageItemImpl(StorageItemHeader *header);
00085         ~StorageItemImpl();
00086 
00087         // Heirarchy
00088         StorageItem *GetNext();
00089         StorageItem *GetPrev();
00090         StorageItem *GetParent();
00091         StorageItem *GetChild();
00092 
00093         StorageItem *CreateNext(StorageObj *Obj);
00094         StorageItem *CreateChild(StorageObj *Obj);
00095         StorageItem *CreateSub(StorageObj *Obj);
00096         bool InsertSub(StorageItem *Obj, int At = -1);
00097         bool DeleteChild(StorageItem *Obj);
00098         bool DeleteAllChildren();
00099 
00100         // Properties
00101         int GetType();
00102         void SetType(int i);
00103         int GetTotalSize();
00104         int GetObjectSize();
00105         StorageKit *GetTree();
00106 
00107         // Impl
00108         GFile *GotoObject(char *file, int line);
00109         bool EndOfObj(GFile &f);
00110         bool Save();
00111         
00112         // Debug
00113         int GetStoreLoc() { return StoreLoc; }
00114     };
00115 
00116     struct StorageHeader {
00117 
00118         int Magic;              // always STORAGE2_MAGIC
00119         int Version;            // 0x0
00120         int Reserved1;          // 0x0
00121         int Reserved2;          // 0x0
00122         char Password[32];      // obsured password
00123         int Reserved3[4];       // 0x0
00124     };
00125 
00126     class StorageKitImpl :
00127         public GObject,
00128         public StorageKit,
00129         public GSemaphore
00130     {
00131         friend class StorageItemImpl;
00132         friend class StorageKitImplPrivate;
00133 
00134     protected:
00135         StorageKitImplPrivate *d;
00136     
00137         // File stuff
00138         char *FileName;
00139         bool Status;
00140         int StoreLoc;
00141         int Version;
00142         bool ReadOnly;
00143         GPassword Password;
00144 
00145         class GSubFile *File;
00146         class GSubFilePtr *CreateFilePtr(char *file, int line);
00147 
00148         // Root stuff
00149         StorageItemHeader RootHeader;
00150         StorageItemImpl *Root;
00151 
00152         bool _ValidLoc(uint64 Loc);
00153         bool _Serialize(GFile &f, bool Write);
00154         
00155     public:
00156         StorageKitImpl(char *FileName);
00157         ~StorageKitImpl();
00158 
00159         bool IsOk();
00160         int GetStatus() { return Status; }
00161         bool GetReadOnly() { return ReadOnly; }
00162         int GetVersion() { return Version; }
00163         uint64 GetFileSize();
00164         bool GetPassword(GPassword *p);
00165         bool SetPassword(GPassword *p);
00166         GSemaphore *GetLock();
00167         char *GetFileName() { return FileName; }
00168         
00169         StorageItem *GetRoot();
00170         StorageItem *CreateRoot(StorageObj *Obj);
00171 
00172         bool Compact(Progress *p, bool Interactive, StorageValidator *Validator = 0);
00173         bool DeleteItem(StorageItem *Item);
00174         bool SeparateItem(StorageItem *Item);
00175         bool AttachItem(StorageItem *Item, StorageItem *To, NodeRelation Relationship = NodeChild);
00176     };
00177 
00178 }
00179 
00180 #endif

Generated on Wed Oct 26 14:46:52 2005 for Lgi by  doxygen 1.4.1