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 "LgiOsDefs.h"
00015 #include "GStream.h"
00016 
00017 class DLinkList;
00018 class DLinkInterator;
00019 
00021 typedef int (*ListSortFunc)(void*, void*, int);
00022 
00023 class LgiClass DLinkList
00024 {
00025     friend class DLinkIterator;
00026     friend class Item;
00027 
00028 protected:
00029     int Items;
00030     class Item *FirstObj, *LastObj;
00031     class ItemIter *Cur;
00032 
00033     ItemIter GetIndex(int Index);
00034     ItemIter GetPtr(void *Ptr, int &Base);
00035 
00036 public:
00037     DLinkList();
00038     virtual ~DLinkList();
00039 
00040     bool IsValid();
00041 
00042     int Length() { return Items; }
00043     virtual void Empty();
00044     void *operator [](int Index);
00045     DLinkList &operator =(DLinkList &lst);
00046 
00047     bool Delete();
00048     bool Delete(int Index);
00049     bool Delete(void *p);
00050     bool Insert(void *p, int Index = -1);
00051     void *Current();
00052     void *First();
00053     void *Last();
00054     void *Next();
00055     void *Prev();
00056     int IndexOf(void *p);
00057     bool HasItem(void *p);
00058     void *ItemAt(int i);
00059     void Sort(ListSortFunc Compare, int Data);
00060 };
00061 
00063 class LgiClass DLinkIterator
00064 {
00065 protected:
00066     DLinkList *List;
00067     class ItemIter *Cur;
00068 
00069 public:
00070     DLinkIterator(DLinkList *list);
00071     ~DLinkIterator();
00072 
00073     void *operator [](int Index);
00074     void *Current();
00075     void *First();
00076     void *Last();
00077     void *Next();
00078     void *Prev();
00079     bool HasItem(void *p);
00080     int IndexOf(void *p);
00081     int Length();
00082 };
00083 
00085 template <class Type>
00086 class List : public DLinkList
00087 {
00088 public:
00090     virtual bool Delete()           { return DLinkList::Delete(); }
00092     virtual bool Delete(int i)      { return DLinkList::Delete(i); }
00094     virtual bool Delete(Type *p)    { return DLinkList::Delete((void*)p); }
00096     virtual bool Insert
00097     (
00099         Type *p,
00101         int Index = -1
00102     )
00103     { return DLinkList::Insert((void*)p, Index); }
00104 
00105     /*
00107     virtual void Insert
00108     (
00110         List<Type> &l,
00112         int Index = -1
00113     )
00114     {
00115         for (Type *p = l.First(); p; p = l.Next())
00116         {
00117             if (Index >= 0) DLinkList::Insert(p, Index++);
00118             else DLinkList::Insert(p);
00119         }
00120     }
00121     */
00122     
00124     Type *First()                   { return (Type*) DLinkList::First(); }
00126     Type *Last()                    { return (Type*) DLinkList::Last(); }
00128     Type *Next()                    { return (Type*) DLinkList::Next(); }
00130     Type *Prev()                    { return (Type*) DLinkList::Prev(); }
00132     Type *Current()                 { return (Type*) DLinkList::Current(); }
00134     Type *operator [](int Index)    { return ((Type*) ((*((DLinkList*)this))[Index])); }
00135     
00137     int IndexOf(Type *p)            { return DLinkList::IndexOf((void*)p); }
00139     bool HasItem(Type *p)           { return DLinkList::HasItem((void*)p); }
00141     Type *ItemAt(int i)             { return (Type*) DLinkList::ItemAt(i); }
00143     void Sort
00144     (
00146         int (*Compare)(Type *a, Type *b, int data),
00148         int Data
00149     )
00150     { DLinkList::Sort( (int (*)(void *a, void *b, int data)) Compare, Data); }
00151     
00153     void DeleteObjects()
00154     {
00155         for (Type *o=(Type*)DLinkList::First(); o; o=(Type*)DLinkList::Next())
00156         {
00157             DeleteObj(o);
00158         }
00159         DLinkList::Empty();
00160     }
00162     void DeleteArrays()
00163     {
00164         for (Type *o=(Type*)DLinkList::First(); o; o=(Type*)DLinkList::Next())
00165         {
00166             DeleteArray(o);
00167         }
00168         DLinkList::Empty();
00169     }
00170 
00172     List &operator =
00173     (
00175         List<Type> &lst
00176     )
00177     {
00178         DLinkList *l = this;
00179         *l = (DLinkList&)lst;
00180         return *this;
00181     }
00182 };
00183 
00185 template <class Type>
00186 class Iterator : public DLinkIterator
00187 {
00188 public:
00190     Iterator
00191     (
00193         DLinkList *l
00194     ) : DLinkIterator(l) {}
00196     ~Iterator() {}
00197 
00199     Type *operator [](int Index) { return (Type*) (* (DLinkIterator*)this)[Index]; }
00201     Type *First() { return (Type*) DLinkIterator::First(); }
00203     Type *Last() { return (Type*) DLinkIterator::Last(); }
00205     Type *Next() { return (Type*) DLinkIterator::Next(); }
00207     Type *Prev() { return (Type*) DLinkIterator::Prev(); }
00209     Type *Current() { return (Type*) DLinkIterator::Current(); }
00211     bool HasItem(Type *p) { return DLinkIterator::HasItem((Type*)p); }
00213     int IndexOf(Type *p) { return DLinkIterator::IndexOf((Type*)p); }
00214 };
00215 
00224 class LgiClass GBytePipe : public GStream
00225 {
00226 protected:
00227     struct Block
00228     {
00229         int Next;
00230         int Used;
00231         int Size;
00232         uchar *Ptr() { return (uchar*) (this + 1); }
00233 
00234         Block()
00235         {
00236             Next = 0;
00237             Size = 0;
00238             Used = 0;
00239         }
00240     };
00241 
00242     int PreAlloc;
00243     List<Block> Mem;
00244 
00245 public:
00247     GBytePipe
00248     (
00251         int PreAlloc = 0
00252     );
00254     virtual ~GBytePipe();
00255 
00257     virtual bool IsEmpty() { return Mem.Length() == 0; }
00259     virtual void Empty();
00262     virtual void *New
00263     (
00267         int AddBytes = 0
00268     );
00271     virtual int Peek
00272     (
00274         uchar *Ptr,
00276         int Size
00277     );
00278 
00280     int64 GetSize();
00282     int Read(void *Buffer, int Size, int Flags = 0);
00284     int Write(void *Buffer, int Size, int Flags = 0);
00285 
00287     int Pop(short &i);
00289     int Pop(int &i);
00291     int Pop(double &i);
00292 
00294     int Push(short i)               { return Write((uchar*)&i, sizeof(i)); }
00296     int Push(int i)                 { return Write((uchar*)&i, sizeof(i)); }
00298     int Push(double i)              { return Write((uchar*)&i, sizeof(i)); }
00299 };
00300 
00302 class LgiClass GStringPipe : public GBytePipe
00303 {
00304 public:
00306     GStringPipe
00307     (
00309         int PreAlloc = -1
00310     ) : GBytePipe(PreAlloc) {}
00311     
00312     ~GStringPipe() {}
00313 
00315     virtual int Pop
00316     (
00318         char *Str,
00320         int BufSize
00321     );
00323     virtual int Push
00324     (
00326         char *Str,
00328         int Len=-1
00329     );
00331     virtual int Push
00332     (
00334         char16 *Str,
00336         int Len = -1
00337     );
00338 
00340     bool Printf(char *Str, ...);
00342     bool Printf(char16 *Str, ...);
00343     
00345     char *NewStr();
00347     char16 *NewStrW();
00348 };
00349 
00350 LgiFunc uint LgiHash
00351 (
00353     uchar *In,
00355     int Len,
00357     bool Case       
00358 );
00359 
00360 class GHashEntry;
00361 
00363 class LgiClass GHashTable
00364 {
00365     class GHashTablePrivate *d;
00366 
00367 public:
00369     GHashTable
00370     (
00372         int Size = 0,
00374         bool Case = true
00375     );
00376     
00378     GHashTable
00379     (
00381         List<char> &strs
00382     );
00383     
00385     virtual ~GHashTable();
00386 
00388     void Set
00389     (
00391         List<char> &strs
00392     );
00393 
00395     int64 GetSize();
00396     
00398     void SetSize(int64 s);
00399     
00401     bool GetStringPool();
00402     
00406     void SetStringPool(bool b);
00407     
00409     bool IsCase();
00410 
00412     void IsCase(bool c);
00413     
00415     bool IsOk();
00416 
00418     int Length();
00419 
00421     bool Add
00422     (
00424         char *Key,
00426         void *Value = (void*)1
00427     );
00428     
00430     bool Delete
00431     (
00433         char *Key
00434     );
00435     
00437     void *Find(char *Key);
00438     
00440     void *First(char **Key = 0);
00441     
00443     void *Current(char **Key = 0);
00444     
00446     void *Next(char **Key = 0);
00447 
00449     void Empty();
00450 
00452     int64 Sizeof();
00453 };
00454 
00455 #endif

Generated on Tue May 2 10:24:41 2006 for Lgi by  doxygen 1.4.1