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(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 ObjProperties :
00096 public GBase
00097 {
00098 friend class ObjTree;
00099
00100
00101 ObjProperties *Parent;
00102 ObjProperties *Next;
00103 ObjProperties *Leaf;
00104
00105
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 !(*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.Length(); }
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
00152 void Empty();
00153 int SizeofData();
00154
00155 bool Set(char *Name, int n);
00156 bool Set(char *Name, double n);
00157 bool Set(char *Name, char *n);
00158 bool Set(char *Name, void *Data, int Len);
00159 bool Set(Prop *p);
00160
00161 bool Get(char *Name, int &n);
00162 bool Get(char *Name, double &n);
00163 bool Get(char *Name, char *&n);
00164 bool Get(char *Name, void *&Data, int &Len);
00165 bool Get(Prop *&p);
00166
00167 bool Serialize(GFile &f, bool Write);
00168 bool SerializeText(GFile &f, bool Write);
00169 };
00170
00171 class ObjTree : public GBase
00172 {
00173 ObjProperties *Root;
00174
00175 public:
00176 ObjTree();
00177 virtual ~ObjTree();
00178
00179 ObjProperties *GetRoot();
00180 ObjProperties *GetLeaf(char *Name, bool Create = false);
00181
00182 bool Set(char *Name, int n);
00183 bool Set(char *Name, double n);
00184 bool Set(char *Name, char *n);
00185
00186 bool Get(char *Name, int &n);
00187 bool Get(char *Name, double &n);
00188 bool Get(char *Name, char *&n);
00189
00190 void Print();
00191 bool Serialize(GFile &f, bool Write);
00192 bool SerializeObj(GFile &f, bool Write);
00193 bool SerializeText(GFile &f, bool Write);
00194 };
00195
00196 #endif
00197