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

GContainers.h

Go to the documentation of this file.
00001 
00010 #ifndef _CONTAIN_H_
00011 #define _CONTAIN_H_
00012 
00013 #include "LgiInc.h"
00014 #include "GStream.h"
00015 
00016 class DLinkList;
00017 class DLinkInterator;
00018 
00020 typedef int (*ListSortFunc)(void*, void*, int);
00021 
00022 class LgiClass DLinkList
00023 {
00024     friend class DLinkIterator;
00025     friend class Item;
00026 
00027 protected:
00028     int Items;
00029     class Item *FirstObj, *LastObj;
00030     class ItemIter *Cur;
00031 
00032     ItemIter GetIndex(int Index);
00033     ItemIter GetPtr(void *Ptr, int &Base);
00034 
00035 public:
00036     DLinkList();
00037     virtual ~DLinkList();
00038 
00039     bool IsValid();
00040 
00041     int GetItems() { return Items; }
00042     virtual void Empty();
00043     void *operator [](int Index);
00044     DLinkList &operator =(DLinkList &lst);
00045 
00046     bool Delete();
00047     bool Delete(int Index);
00048     bool Delete(void *p);
00049     bool Insert(void *p, int Index = -1);
00050     void *Current();
00051     void *First();
00052     void *Last();
00053     void *Next();
00054     void *Prev();
00055     int IndexOf(void *p);
00056     bool HasItem(void *p);
00057     void *ItemAt(int i);
00058     void Sort(ListSortFunc Compare, int Data);
00059 };
00060 
00062 class LgiClass DLinkIterator
00063 {
00064 protected:
00065     DLinkList *List;
00066     class ItemIter *Cur;
00067 
00068 public:
00069     DLinkIterator(DLinkList *list);
00070     ~DLinkIterator();
00071 
00072     void *operator [](int Index);
00073     void *Current();
00074     void *First();
00075     void *Last();
00076     void *Next();
00077     void *Prev();
00078     bool HasItem(void *p);
00079     int GetItems();
00080 };
00081 
00083 template <class Type>
00084 class List : public DLinkList
00085 {
00086 public:
00088     virtual bool Delete()           { return DLinkList::Delete(); }
00090     virtual bool Delete(int i)      { return DLinkList::Delete(i); }
00092     virtual bool Delete(Type *p)    { return DLinkList::Delete((void*)p); }
00094     virtual bool Insert
00095     (
00097         Type *p,
00099         int Index = -1
00100     )
00101     { return DLinkList::Insert((void*)p, Index); }
00102 
00103     /*
00105     virtual void Insert
00106     (
00108         List<Type> &l,
00110         int Index = -1
00111     )
00112     {
00113         for (Type *p = l.First(); p; p = l.Next())
00114         {
00115             if (Index >= 0) DLinkList::Insert(p, Index++);
00116             else DLinkList::Insert(p);
00117         }
00118     }
00119     */
00120     
00122     Type *First()                   { return (Type*) DLinkList::First(); }
00124     Type *Last()                    { return (Type*) DLinkList::Last(); }
00126     Type *Next()                    { return (Type*) DLinkList::Next(); }
00128     Type *Prev()                    { return (Type*) DLinkList::Prev(); }
00130     Type *Current()                 { return (Type*) DLinkList::Current(); }
00132     Type *operator [](int Index)    { return ((Type*) ((*((DLinkList*)this))[Index])); }
00133     
00135     int IndexOf(Type *p)            { return DLinkList::IndexOf((void*)p); }
00137     bool HasItem(Type *p)           { return DLinkList::HasItem((void*)p); }
00139     Type *ItemAt(int i)             { return (Type*) DLinkList::ItemAt(i); }
00141     void Sort
00142     (
00144         int (*Compare)(Type *a, Type *b, int data),
00146         int Data
00147     )
00148     { DLinkList::Sort( (int (*)(void *a, void *b, int data)) Compare, Data); }
00149     
00151     void DeleteObjects()
00152     {
00153         for (Type *o=(Type*)DLinkList::First(); o; o=(Type*)DLinkList::Next())
00154         {
00155             DeleteObj(o);
00156         }
00157         DLinkList::Empty();
00158     }
00160     void DeleteArrays()
00161     {
00162         for (Type *o=(Type*)DLinkList::First(); o; o=(Type*)DLinkList::Next())
00163         {
00164             DeleteArray(o);
00165         }
00166         DLinkList::Empty();
00167     }
00168 
00170     List &operator =
00171     (
00173         List<Type> &lst
00174     )
00175     {
00176         DLinkList *l = this;
00177         *l = (DLinkList&)lst;
00178         return *this;
00179     }
00180 };
00181 
00183 template <class Type>
00184 class Iterator : public DLinkIterator
00185 {
00186 public:
00188     Iterator
00189     (
00191         DLinkList *l
00192     ) : DLinkIterator(l) {}
00194     ~Iterator() {}
00195 
00197     Type *operator [](int Index) { return (Type*) (* (DLinkIterator*)this)[Index]; }
00199     Type *First() { return (Type*) DLinkIterator::First(); }
00201     Type *Last() { return (Type*) DLinkIterator::Last(); }
00203     Type *Next() { return (Type*) DLinkIterator::Next(); }
00205     Type *Prev() { return (Type*) DLinkIterator::Prev(); }
00207     Type *Current() { return (Type*) DLinkIterator::Current(); }
00209     bool HasItem(Type *p) { return DLinkIterator::HasItem((Type*)p); }
00210 };
00211 
00220 class LgiClass GBytePipe : public GStream
00221 {
00222 protected:
00223     struct Block
00224     {
00225         int Next;
00226         int Used;
00227         int Size;
00228         uchar *Ptr() { return (uchar*) (this + 1); }
00229 
00230         Block()
00231         {
00232             Next = 0;
00233             Size = 0;
00234             Used = 0;
00235         }
00236     };
00237 
00238     int PreAlloc;
00239     List<Block> Mem;
00240 
00241 public:
00243     GBytePipe
00244     (
00247         int PreAlloc = 0
00248     );
00250     virtual ~GBytePipe();
00251 
00253     virtual bool IsEmpty() { return Mem.GetItems() == 0; }
00255     virtual void Empty();
00258     virtual void *New
00259     (
00263         int AddBytes = 0
00264     );
00267     virtual int Peek
00268     (
00270         uchar *Ptr,
00272         int Size
00273     );
00274 
00276     int64 GetSize();
00278     int Read(void *Buffer, int Size, int Flags = 0);
00280     int Write(void *Buffer, int Size, int Flags = 0);
00281 
00283     int Pop(short &i);
00285     int Pop(int &i);
00287     int Pop(double &i);
00288 
00290     int Push(short i)               { return Write((uchar*)&i, sizeof(i)); }
00292     int Push(int i)                 { return Write((uchar*)&i, sizeof(i)); }
00294     int Push(double i)              { return Write((uchar*)&i, sizeof(i)); }
00295 };
00296 
00298 class LgiClass GStringPipe : public GBytePipe
00299 {
00300 public:
00302     GStringPipe
00303     (
00305         int PreAlloc = -1
00306     ) : GBytePipe(PreAlloc) {}
00307 
00309     virtual int Pop
00310     (
00312         char *Str,
00314         int BufSize
00315     );
00317     virtual int Push
00318     (
00320         char *Str,
00322         int Len=-1
00323     );
00325     virtual int Push
00326     (
00328         char16 *Str,
00330         int Len = -1
00331     );
00332 
00334     bool Printf(char *Str, ...);
00336     bool Printf(char16 *Str, ...);
00337     
00339     char *NewStr();
00341     char16 *NewStrW();
00342 };
00343 
00344 LgiFunc uint LgiHash
00345 (
00347     uchar *In,
00349     int Len,
00351     bool Case       
00352 );
00353 
00354 class GHashEntry;
00355 
00357 class LgiClass GHashTable
00358 {
00359     class GHashTablePrivate *d;
00360 
00361 public:
00363     GHashTable
00364     (
00366         int Size = 0,
00368         bool Case = true
00369     );
00370     
00372     GHashTable
00373     (
00375         List<char> &strs
00376     );
00377     
00379     virtual ~GHashTable();
00380 
00382     void Set
00383     (
00385         List<char> &strs
00386     );
00387 
00389     int64 GetSize();
00390     
00392     void SetSize(int64 s);
00393     
00395     bool GetStringPool();
00396     
00400     void SetStringPool(bool b);
00401     
00403     bool IsCase();
00404 
00406     void IsCase(bool c);
00407     
00409     bool IsOk();
00410 
00412     int Length();
00413 
00415     bool Add
00416     (
00418         char *Key,
00420         void *Value = (void*)1
00421     );
00422     
00424     bool Delete
00425     (
00427         char *Key
00428     );
00429     
00431     void *Find(char *Key);
00432     
00434     void *First(char **Key = 0);
00435     
00437     void *Current(char **Key = 0);
00438     
00440     void *Next(char **Key = 0);
00441 
00443     void Empty();
00444 
00445     #ifdef _DEBUG
00446     int64 Sizeof();
00447     #endif
00448 };
00449 
00450 #endif

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