-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathobjs.h
260 lines (209 loc) · 6.91 KB
/
objs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* This source file is part of the Atlantis Little Helper program.
* Copyright (C) 2001 Maxim Shariy.
*
* Atlantis Little Helper is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Atlantis Little Helper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Atlantis Little Helper; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __OBJS_IS_OBJECTS_FOUNDATION_H_INCL__
#define __OBJS_IS_OBJECTS_FOUNDATION_H_INCL__
#include "cstr.h"
#include "collection.h"
enum EValueType
{
eLong,
eCharPtr,
};
enum EPropertyType
{
eNormal,
eOriginal,
eBoth
};
#define MAX_PROP_COLL_KEYS 16
// property errors
#define PE_OK ( 0)
#define PE_NOT_IMPLEMENTED (-1)
#define PE_INV_NAME (-2)
#define PE_INV_VALUE_TYPE (-3)
#define PE_INV_PROP_TYPE (-4)
//=============================================================
class CStrInt
{
public:
CStrInt(){m_key=NULL; m_value=0;};
CStrInt(const char * key, int value)
{
m_key = key?strdup(key ):NULL;
m_value = value;
};
~CStrInt()
{
if (m_key)
free((void*)m_key);
}
const char * m_key;
int m_value;
};
//-----------------------------------------------------------------
class CStrIntColl : public CSortedCollection
{
public:
CStrIntColl() : CSortedCollection() {};
CStrIntColl(int nDelta) : CSortedCollection(nDelta) {};
virtual ~CStrIntColl() {FreeAll();};
protected:
virtual void FreeItem(void * pItem) {if (pItem) delete (CStrInt*)pItem;};
virtual int Compare(void * pItem1, void * pItem2) const
{
return SafeCmp( ((CStrInt*)pItem1)->m_key, ((CStrInt*)pItem2)->m_key );
};
};
//-------------------------------------------------------------------
class CStrStr
{
public:
CStrStr(){m_key=NULL; m_value=NULL;};
CStrStr(const char * key, const char * value)
{
m_key = key?strdup(key ):NULL;
m_value = value?strdup(value):NULL;
};
~CStrStr()
{
if (m_key)
free((void*)m_key);
if (m_value)
free((void*)m_value);
}
const char * m_key;
const char * m_value;
};
//-----------------------------------------------------------------
class CStrStrColl : public CSortedCollection
{
public:
CStrStrColl() : CSortedCollection() {};
CStrStrColl(int nDelta) : CSortedCollection(nDelta) {};
virtual ~CStrStrColl() {FreeAll();};
protected:
virtual void FreeItem(void * pItem) {if (pItem) delete (CStrStr*)pItem;};
virtual int Compare(void * pItem1, void * pItem2) const
{
return SafeCmp( ((CStrStr*)pItem1)->m_key, ((CStrStr*)pItem2)->m_key );
};
};
//-------------------------------------------------------------------
class CStrStrColl2 : public CSortedCollection
{
public:
CStrStrColl2() : CSortedCollection() {};
CStrStrColl2(int nDelta) : CSortedCollection(nDelta) {};
virtual ~CStrStrColl2() {FreeAll();};
protected:
virtual void FreeItem(void * pItem) {if (pItem) delete (CStrStr*)pItem;};
virtual int Compare(void * pItem1, void * pItem2) const
{
int x = SafeCmp( ((CStrStr*)pItem1)->m_key, ((CStrStr*)pItem2)->m_key );
if (0==x)
x = SafeCmp( ((CStrStr*)pItem1)->m_value, ((CStrStr*)pItem2)->m_value );
return x;
};
};
//-------------------------------------------------------------------
struct TEvent
{
unsigned long id;
void * data;
};
//-------------------------------------------------------------------
class TObject
{
public:
TObject() {};
virtual ~TObject() {};
virtual BOOL HandleEvent(TEvent *) {return FALSE;};
};
//-------------------------------------------------------------------
class TProperty
{
public:
TProperty();
TProperty(const char * name, EValueType type, const void * value);
~TProperty();
int SetValue(EValueType type,
const void * value,
EPropertyType proptype = eNormal
);
const char * m_name;
EValueType m_type;
void * m_value;
void * m_valueorg;
};
//-------------------------------------------------------------------
class TPropertyColl : public CSortedCollection
{
public:
TPropertyColl() : CSortedCollection() {};
TPropertyColl(int nDelta) : CSortedCollection(nDelta) {};
protected:
virtual void FreeItem(void * pItem) {if (pItem) delete (TProperty*)pItem;};
virtual int Compare(void * pItem1, void * pItem2) const;
};
//-------------------------------------------------------------------
class TPropertyHolder : public TObject
{
public:
TPropertyHolder();
virtual ~TPropertyHolder();
virtual BOOL GetProperty(const char * name,
EValueType & valuetype,
const void *& value, // returns pointer to inner location
EPropertyType proptype = eNormal
);
virtual int SetProperty(const char * name,
EValueType type,
const void * value,
EPropertyType proptype = eNormal
);
virtual void DelProperty(const char * name);
virtual void ResetNormalProperties();
virtual const char * ResolveAlias(const char * alias) {return alias;};
virtual CStrStrColl * GetPropertyGroups() {return NULL;};
virtual const char * GetPropertyName(int no);
protected:
BOOL GetJustProperty (const char * name,
EValueType & valuetype,
const void *& value, // returns pointer to inner location
EPropertyType proptype = eNormal
);
TPropertyColl m_Properties;
};
//-------------------------------------------------------------------
class TPropertyHolderColl : public CResortableCollection
{
public:
TPropertyHolderColl();
TPropertyHolderColl(int nDelta);
virtual ~TPropertyHolderColl();
void SetSortMode(const char ** keys, int keycount);
protected:
virtual void FreeItem(void * pItem);
virtual int Compare(void * pItem1, void * pItem2) const;
void ClearKeys();
int m_KeyCount;
char * m_Key[MAX_PROP_COLL_KEYS];
};
//-------------------------------------------------------------------
#endif