00001
00002
00003
00004
00005
00006
00007
00008
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 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(const char *n)
00049 {
00050 if (n)
00051 {
00052 Name = NewStr(n);
00053 }
00054 else
00055 {
00056 Name = 0;
00057 }
00058
00059 Type = OBJ_NULL;
00060 ZeroObj(Value);
00061 }
00062
00063 virtual ~Prop()
00064 {
00065 DeleteArray(Name);
00066 EmptyData();
00067 }
00068
00069 void EmptyData()
00070 {
00071 if (Type == OBJ_STRING OR Type == OBJ_BINARY)
00072 {
00073 DeleteArray(Value.Cp);
00074 }
00075
00076 Type = OBJ_NULL;
00077 }
00078
00079 bool operator ==(Prop &p);
00080 bool operator ==(const char *n);
00081
00082 bool Serialize(GFile &f, bool Write);
00083 bool SerializeText(GFile &f, bool Write);
00084 };
00085
00086 class ObjTree;
00087 class ObjProperties;
00088
00089 typedef ObjProperties *pObjProperties;
00090
00091 class ObjProperties :
00092 public GBase
00093 {
00094 friend class ObjTree;
00095
00096
00097 ObjProperties *Parent;
00098 ObjProperties *Next;
00099 ObjProperties *Leaf;
00100
00101
00102 Prop *Current;
00103 List<Prop> Properties;
00104
00105 Prop *FindProp(const char *Name);
00106
00107 public:
00108 ObjProperties();
00109 ObjProperties(char *n);
00110 virtual ~ObjProperties();
00111
00112 ObjProperties &operator =(ObjProperties &props);
00113
00114 bool operator ==(const char *n)
00115 {
00116 if (Name())
00117 {
00118 return stricmp(Name(), (n) ? n : (char*)"") == 0;
00119 }
00120 return false;
00121 }
00122
00123 bool operator !=(char *n)
00124 {
00125 return !(*this == n);
00126 }
00127
00128 ObjProperties *GetParent() { return Parent; }
00129 pObjProperties &GetNext() { return Next; }
00130 pObjProperties &GetLeaf() { return Leaf; }
00131 ObjProperties *CreateNext(char *n);
00132 ObjProperties *CreateLeaf(char *n);
00133 ObjProperties *FindLeaf(char *n);
00134
00135 char *KeyName();
00136 int KeyType();
00137 void *KeyValue();
00138 Prop *GetProp();
00139 int GetPropertyCount() { return Properties.Length(); }
00140
00141 bool Find(char *Name);
00142 bool FirstKey();
00143 bool LastKey();
00144 bool NextKey();
00145 bool PrevKey();
00146 bool DeleteKey(char *Name = 0);
00147
00148 void Empty();
00149 int SizeofData();
00150
00151 bool Set(const char *Name, int n);
00152 bool Set(const char *Name, double n);
00153 bool Set(const char *Name, const char *n);
00154 bool Set(const char *Name, void *Data, int Len);
00155 bool Set(Prop *p);
00156
00157 bool Get(const char *Name, int &n);
00158 bool Get(const char *Name, double &n);
00159 bool Get(const char *Name, char *&n);
00160 bool Get(const char *Name, void *&Data, int &Len);
00161 bool Get(Prop *&p);
00162
00163 bool Serialize(GFile &f, bool Write);
00164 bool SerializeText(GFile &f, bool Write);
00165 };
00166
00167 class ObjTree : public GBase
00168 {
00169 ObjProperties *Root;
00170
00171 public:
00172 ObjTree();
00173 virtual ~ObjTree();
00174
00175 ObjProperties *GetRoot();
00176 ObjProperties *GetLeaf(char *Name, bool Create = false);
00177
00178 bool Set(char *Name, int n);
00179 bool Set(char *Name, double n);
00180 bool Set(char *Name, char *n);
00181
00182 bool Get(char *Name, int &n);
00183 bool Get(char *Name, double &n);
00184 bool Get(char *Name, char *&n);
00185
00186 void Print();
00187 bool Serialize(GFile &f, bool Write);
00188 bool SerializeObj(GFile &f, bool Write);
00189 bool SerializeText(GFile &f, bool Write);
00190 };
00191
00192 #endif
00193