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
|
#include <precomp.h>
#include <bfc/bfc_assert.h>
#include "xmlobject.h"
#include <new>
#define PILENODE_AUTOINCREMENT 50
/*
CreateXMLParameters(int master_handle)
addParam(master_handle, this_handle, name, id)
master_handle is key into array of name/this-handle/id
*/
class DeleteOnClose
{
public:
~DeleteOnClose()
{
allocd.freeAll();
}
PtrList<XmlObjectParam> allocd;
};
DeleteOnClose deleter;
template <class t_>
struct PileNode
{
PileNode(int num)
{
sizePile = num;
pile = (t_ *)MALLOC(sizeof(t_) * num);
deleter.allocd.addItem(pile);
}
void Rebuild(int num)
{
sizePile = num;
pile = (t_ *)MALLOC(sizeof(t_) * num);
deleter.allocd.addItem(pile);
}
size_t sizePile;
t_ *pile;
void *Get()
{
sizePile--;
return pile++;
}
};
template <class t_>
struct PileList
{
PileList(int numPtrs, PileList<t_> *_next = 0) : node(numPtrs), next(_next)
{
}
PileNode<t_> node;
PileList *next;
void *Get()
{
if (node.sizePile)
{
return node.Get();
}
else
{
while (next && !next->node.sizePile)
{
PileList<t_> *temp = next;
next = temp->next;
delete temp;
}
if (next)
return next->Get();
else
{
node.Rebuild(PILENODE_AUTOINCREMENT);
return node.Get();
}
}
}
};
PileList<XmlObjectParam> *paramPile = 0;
XmlObjectParam::XmlObjectParam(int xmlhandle, wchar_t *xmlattribute, int xmlattributeid)
: xmlattributename(xmlattribute), attributeid(xmlattributeid), handle(xmlhandle)
{
KEYWORDUPPER(xmlattribute);
}
#define CBCLASS XmlObjectI
START_DISPATCH;
CB(SETXMLPARAM, setXmlParam);
CB(GETXMLPARAMVALUE, getXmlParamValue);
CB(GETXMLPARAM, getXmlParam);
END_DISPATCH;
XmlObjectI::XmlObjectI()
{
handlepos = 0;
}
XmlObjectI::~XmlObjectI()
{
params.removeAll();
}
void XmlObjectI::addParam(int xmlhandle, XMLParamPair ¶m, int unused)
//void XmlObjectI::addXmlParam(int xmlhandle, const wchar_t *xmlattribute, int xmlattributeid)
{
if (!paramPile)
paramPile = new PileList<XmlObjectParam>(PILENODE_AUTOINCREMENT);
params.addItem(new(paramPile->Get()) XmlObjectParam(xmlhandle, param.name, param.id));
}
int XmlObjectI::setXmlParamById(int xmlhandle, int xmlattribute, const wchar_t *param, const wchar_t *value)
{
return 0;
}
int XmlObjectI::setXmlParam(const wchar_t *param, const wchar_t *value)
{
int pos = -1;
int r = 0;
params.findItem(param, &pos);
if (pos >= 0)
{
XmlObjectParam *xuop = params.enumItem(pos);
ASSERT(xuop != NULL);
r = setXmlParamById(xuop->getXmlHandle(), xuop->getXmlAttributeId(), param, value);
xuop->setLastValue(value);
}
else
{
onUnknownXmlParam(param, value);
}
return r;
}
const wchar_t *XmlObjectI::getXmlParamValue(int n)
{
return params.enumItem(n)->getLastValue();
}
int XmlObjectI::getXmlParam(const wchar_t *param)
{
int pos=-1;
params.findItem(param, &pos);
return pos;
}
const wchar_t *XmlObjectI::getXmlParamByName(const wchar_t *paramname)
{
int pos = getXmlParam(paramname);
if (pos < 0) return NULL;
return getXmlParamValue(pos);
}
int XmlObjectI::newXmlHandle()
{
return handlepos++;
}
int XmlObjectI::onUnknownXmlParam(const wchar_t *paramname, const wchar_t *strvalue)
{
return 0;
}
void XmlObjectI::hintNumberOfParams(int xmlhandle, int numParams)
{
paramPile = new PileList<XmlObjectParam>(numParams, paramPile);
params.setMinimumSize(params.getNumItems() + numParams);
}
|