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

GProperties.h

00001 /*hdr
00002 **      FILE:           GProperties.h
00003 **      AUTHOR:         Matthew Allen
00004 **      DATE:           8/4/98
00005 **      DESCRIPTION:    Property hndling
00006 **
00007 **      Copyright (C) 1998, Matthew Allen
00008 **              fret@memecode.com
00009 */
00010 
00011 #ifndef __PROP_H
00012 #define __PROP_H
00013 
00014 #include <string.h>
00015 #include "GContainers.h"
00016 #include "LgiClass.h"
00017 
00018 #define OBJ_NULL        0
00019 #define OBJ_INT         1
00020 #define OBJ_FLOAT       2
00021 #define OBJ_STRING      3
00022 #define OBJ_BINARY      4
00023 #define OBJ_CUSTOM      16
00024 
00025 typedef union
00026 {
00027     int Int;
00028     double Dbl;
00029     char *Cp;
00030 } MultiValue;
00031 
00032 class LgiClass Prop
00033 {
00034 public:
00035     char *Name;
00036     int Type;
00037     int Size;
00038     MultiValue Value;
00039 
00040     Prop()
00041     {
00042         Size = 0;
00043         Name = 0;
00044         Type = OBJ_NULL;
00045         ZeroObj(Value);
00046     }
00047 
00048     Prop(char *n)
00049     {
00050         if (n)
00051         {
00052             Name = NEW(char[strlen(n)+1]);
00053             if (Name)
00054             {
00055                 strcpy(Name, n);
00056             }
00057         }
00058         else
00059         {
00060             Name = 0;
00061         }
00062 
00063         Type = OBJ_NULL;
00064         ZeroObj(Value);
00065     }
00066 
00067     virtual ~Prop()
00068     {
00069         DeleteArray(Name);
00070         EmptyData();
00071     }
00072 
00073     void EmptyData()
00074     {
00075         if (Type == OBJ_STRING OR Type == OBJ_BINARY)
00076         {
00077             DeleteArray(Value.Cp);
00078         }
00079 
00080         Type = OBJ_NULL;
00081     }
00082 
00083     bool operator ==(Prop &p);
00084     bool operator ==(char *n);
00085 
00086     bool Serialize(GFile &f, bool Write);
00087     bool SerializeText(GFile &f, bool Write);
00088 };
00089 
00090 class ObjTree;
00091 class ObjProperties;
00092 
00093 typedef ObjProperties *pObjProperties;
00094 
00095 class LgiClass ObjProperties :
00096     public GObject
00097 {
00098     friend class ObjTree;
00099 
00100     // Tree
00101     ObjProperties *Parent;
00102     ObjProperties *Next;
00103     ObjProperties *Leaf;
00104 
00105     // Node
00106     Prop *Current;
00107     List<Prop> Properties;
00108 
00109     Prop *FindProp(char *Name);
00110 
00111 public:
00112     ObjProperties();
00113     ObjProperties(char *n);
00114     virtual ~ObjProperties();
00115 
00116     ObjProperties &operator =(ObjProperties &props);
00117 
00118     bool operator ==(char *n)
00119     {
00120         if (Name())
00121         {   
00122             return stricmp(Name(), (n) ? n : (char*)"") == 0;
00123         }
00124         return false;
00125     }
00126 
00127     bool operator !=(char *n)
00128     {
00129         return NOT (*this == n);
00130     }
00131 
00132     ObjProperties *GetParent() { return Parent; }
00133     pObjProperties &GetNext() { return Next; }
00134     pObjProperties &GetLeaf() { return Leaf; }
00135     ObjProperties *CreateNext(char *n);
00136     ObjProperties *CreateLeaf(char *n);
00137     ObjProperties *FindLeaf(char *n);
00138 
00139     char *KeyName();
00140     int KeyType();
00141     void *KeyValue();
00142     Prop *GetProp();
00143     int GetPropertyCount() { return Properties.GetItems(); }
00144 
00145     bool Find(char *Name);
00146     bool FirstKey();
00147     bool LastKey();
00148     bool NextKey();
00149     bool PrevKey();
00150     bool DeleteKey(char *Name = 0);
00151     int SizeofData();
00152 
00153     bool Set(char *Name, int n);
00154     bool Set(char *Name, double n);
00155     bool Set(char *Name, char *n);
00156     bool Set(char *Name, void *Data, int Len);
00157     bool Set(Prop *p);
00158 
00159     bool Get(char *Name, int &n);
00160     bool Get(char *Name, double &n);
00161     bool Get(char *Name, char *&n);
00162     bool Get(char *Name, void *&Data, int &Len);
00163     bool Get(Prop *&p);
00164 
00165     bool Serialize(GFile &f, bool Write);
00166     bool SerializeText(GFile &f, bool Write);
00167 };
00168 
00169 class LgiClass ObjTree : public GObject {
00170 
00171     ObjProperties *Root;
00172 
00173 public:
00174     ObjTree();
00175     virtual ~ObjTree();
00176 
00177     ObjProperties *GetRoot();
00178     ObjProperties *GetLeaf(char *Name, bool Create = false);
00179 
00180     bool Set(char *Name, int n);
00181     bool Set(char *Name, double n);
00182     bool Set(char *Name, char *n);
00183 
00184     bool Get(char *Name, int &n);
00185     bool Get(char *Name, double &n);
00186     bool Get(char *Name, char *&n);
00187 
00188     void Print();
00189     bool Serialize(GFile &f, bool Write);
00190     bool SerializeObj(GFile &f, bool Write);
00191     bool SerializeText(GFile &f, bool Write);
00192 };
00193 
00194 #endif
00195 

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