-
Notifications
You must be signed in to change notification settings - Fork 13
/
uargs.cpp
300 lines (253 loc) · 8.17 KB
/
uargs.cpp
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/************************************************************************
*
* uargs.cpp : class for creating argument lists ("additive notation").
* Ubit GUI Toolkit - Version 6
* (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
*
* ***********************************************************************
* COPYRIGHT NOTICE :
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
* IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
* 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.
* SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
* ***********************************************************************/
#include <ubit/ubit_features.h>
#include <ubit/udefs.hpp>
#include <ubit/unode.hpp>
#include <ubit/ucall.hpp>
#include <ubit/uargs.hpp>
#include <ubit/ustr.hpp>
#include <ubit/uappli.hpp>
using namespace std;
#define NAMESPACE_UBIT namespace ubit {
NAMESPACE_UBIT
const UArgs UArgs::none;
/* test for counting creation/deletion balance
int Ncreate, Ndelete;
UArgsChildren::UArgsChildren() {Ncreate++;}
UArgsChildren::~UArgsChildren() {Ndelete--;}
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UChild operator/(const UCond& cond, UNode& b) {
return UChild(&b, cond);
}
UChild operator/(const UCond& cond, UNode* b) {
if (!b) {
UAppli::error("UArgs::operator/", "null UNode argument in / specification");
return UChild(null, cond);
}
else return UChild(b, cond);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool UArgs::empty() const {
return children->empty();
}
bool UArgs::operator!() const {
return children->empty();
}
UArgs::~UArgs() {
if (children->refcount > 1) children->refcount--;
else if (children->refcount == 1) delete children;
}
UArgs::UArgs() {
children = new UArgsChildren;
children->refcount = 1;
}
UArgs::UArgs(UNode* b) {
children = new UArgsChildren;
children->refcount = 1;
if (!b) UAppli::error("UArgs::UArgs", "null UNode argument in arglist");
else children->push_back(b);
}
UArgs::UArgs(UNode& b) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(b);
}
UArgs::UArgs(const char* s) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(new UStr(s));
}
UArgs::UArgs(const UChild& c) {
children = new UArgsChildren;
children->refcount = 1;
if (!*c) UAppli::error("UArgs::UArgs", "UChild argument pointing to null node");
else children->push_back(c);
}
UArgs::UArgs(const UArgs& a) : children(a.children) {
if (!children) { // cas UArgs::none pas encore initialise...
children = new UArgsChildren;
children->refcount = 0;
}
children->refcount++;
}
UArgs::UArgs(const UArgsImpl& a) : children(a.children) {
if (!children) { // cas UArgs::none pas encore initialise...
children = new UArgsChildren;
children->refcount = 0;
}
children->refcount++;
}
UArgs& UArgs::operator+=(const UArgs& a2) {
// marche pas car operator* est redefini
// children->insert(children->end(), a2.children->begin(), a2.children->end());
for (UChildIter i = a2.children->begin(); i != a2.children->end(); ++i)
children->push_back(i.child());
return *this;
}
// ========================================================= [Elc] ===========
UArgsImpl::~UArgsImpl() {
if (children->refcount > 1) children->refcount--;
else if (children->refcount == 1) delete children;
}
UArgsImpl::UArgsImpl() {
children = new UArgsChildren;
children->refcount = 1;
}
UArgsImpl::UArgsImpl(const UArgsImpl& a) : children(a.children) {
if (!children) { // cas UArgs::none pas encore initialise...
children = new UArgsChildren;
children->refcount = 0;
}
children->refcount++;
}
// dans ce cas il ne faut pas augmenter a, sinon une expression comme :
// ubox(args + string)
// aurait pour effet de rajouter string a args
UArgsImpl::UArgsImpl(const UArgs& a) {
children = new UArgsChildren;
*children = *a.children; // !! la difference importante est ici !!
children->refcount = 1;
}
UArgsImpl::UArgsImpl(const char* s) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(new UStr(s));
}
UArgsImpl::UArgsImpl(UNode* b) {
children = new UArgsChildren;
children->refcount = 1;
if (!b) UAppli::error("UArgs", "null argument in arglist");
else children->push_back(b);
}
UArgsImpl::UArgsImpl(UNode& b) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(b);
}
UArgsImpl::UArgsImpl(const UChild& c) {
children = new UArgsChildren;
children->refcount = 1;
if (!*c) UAppli::error("UArgs", "null UChild argument in arglist");
else children->push_back(c);
}
const UArgsImpl& operator+(const UArgsImpl& a, const char* s) {
a.children->push_back(new UStr(s));
return a;
}
const UArgsImpl& operator+(const UArgsImpl& a, UNode* b) {
if (!b) UAppli::error("UArgs::operator+", "null UNode in arglist");
else a.children->push_back(b);
return a;
}
const UArgsImpl& operator+(const UArgsImpl& a, UNode& b) {
a.children->push_back(b);
return a;
}
const UArgsImpl& operator+(const UArgsImpl& a, const UChild& c) {
if (!*c) UAppli::error("UArgs::operator+", "null UChild in arglist");
else a.children->push_back(c);
return a;
}
// UArgsImpl + UArgs => recopie children de UArgs a la suite de ceux de UArgsImpl
// SANS MODIFIER UArgs
//
const UArgsImpl& operator+(const UArgsImpl& a, const UArgs& a2) {
// marche pas car operator* est redefini
//a.children->insert(a.children->end(), a2.children->begin(), a2.children->end());
for (UChildIter i = a2.children->begin(); i != a2.children->end(); ++i)
a.children->push_back(i.child());
return a;
}
const UArgsImpl& operator+(const _UAttrArgs& attrs, const UArgsImpl& a) { // !!!!!!
for (UChildReverseIter i = attrs.children->rbegin(); i != attrs.children->rend(); ++i)
a.children->push_front(i.child());
return a;
}
// ========================================================= [Elc] ===========
_UAttrArgs::~_UAttrArgs() {
if (children->refcount > 1) children->refcount--;
else if (children->refcount == 1) delete children;
}
_UAttrArgs::_UAttrArgs() {
children = new UArgsChildren;
children->refcount = 1;
}
/*
_UAttrArgs::_UAttrArgs(const UArgsImpl& a) : children(a.children) {
if (!children) { // cas UArgs::none pas encore initialise...
children = new UArgsChildren;
children->refcount = 0;
}
children->refcount++;
}
*/
_UAttrArgs::_UAttrArgs(UAttr* n) {
children = new UArgsChildren;
children->refcount = 1;
if (!n) UAppli::error("UArgs", "null UAttr argument in arglist");
else children->push_back(n);
}
_UAttrArgs::_UAttrArgs(UAttr& n) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(n);
}
_UAttrArgs::_UAttrArgs(UCall* n) {
children = new UArgsChildren;
children->refcount = 1;
if (!n) UAppli::error("UArgs", "null UChild argument in arglist");
else children->push_back(n);
}
_UAttrArgs::_UAttrArgs(UCall& n) {
children = new UArgsChildren;
children->refcount = 1;
children->push_back(n);
}
/*
_UAttrArgs::_UAttrArgs(const UChild& c) {
children = new UArgsChildren;
children->refcount = 1;
if (!*c) UAppli::error("UArgs::UArgs", "null UChild argument in arglist");
else children->push_back(c);
}
*/
const _UAttrArgs& operator,(const _UAttrArgs& a, UAttr* n) {
if (!n) UAppli::error("UArgs::operator,", "null UAttr argument in arglist");
else a.children->push_back(n);
return a;
}
const _UAttrArgs& operator,(const _UAttrArgs& a, UAttr& n) {
a.children->push_back(n);
return a;
}
const _UAttrArgs& operator,(const _UAttrArgs& a, UCall* n) {
if (!n) UAppli::error("UArgs::operator,", "null UCall argument in arglist");
else a.children->push_back(n);
return a;
}
const _UAttrArgs& operator,(const _UAttrArgs& a, UCall& n) {
a.children->push_back(n);
return a;
}
/*
const _UAttrArgs& operator+(const _UAttrArgs& a, const UChild& c) {
if (!*c) UAppli::error("UArgs::operator,", "null UChild argument in arglist");
else a.children->push_back(c);
return a;
}
*/
}