cloudy
trunk
Main Page
Related Pages
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
source
utilitymacros.h
Go to the documentation of this file.
1
/* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2
* others. For conditions of distribution and use see copyright notice in license.txt */
3
4
#ifndef _UTILITYMACROS_H_
5
#define _UTILITYMACROS_H_
6
9
18
20
52
55
/*
56
// ------------- include guards -----------------
57
*/
58
59
60
#ifdef UTILITYMACROS_H
61
# error Multiple #included file!
62
#endif
63
#define UTILITYMACROS_H
64
65
66
/* --------------- definitions ------------------ */
67
68
74
#define REPEAT_2(x) x x
75
#define REPEAT_4(x) REPEAT_2 (x) REPEAT_2 (x)
76
#define REPEAT_8(x) REPEAT_4 (x) REPEAT_4 (x)
77
#define REPEAT_16(x) REPEAT_8 (x) REPEAT_8 (x)
78
#define REPEAT_32(x) REPEAT_16 (x) REPEAT_16 (x)
79
#define REPEAT_64(x) REPEAT_32 (x) REPEAT_32 (x)
80
#define REPEAT_128(x) REPEAT_64 (x) REPEAT_64 (x)
81
#define REPEAT_256(x) REPEAT_128 (x) REPEAT_128 (x)
82
#define REPEAT_512(x) REPEAT_256 (x) REPEAT_256 (x)
83
#define REPEAT_1024(x) REPEAT_512 (x) REPEAT_512 (x)
84
85
91
#define REPEAT(count, what) REPEAT_##count (what)
92
93
99
#define REPEAT_WC_2(x) x, x
100
#define REPEAT_WC_4(x) REPEAT_WC_2 (x), REPEAT_WC_2 (x)
101
#define REPEAT_WC_8(x) REPEAT_WC_4 (x), REPEAT_WC_4 (x)
102
#define REPEAT_WC_16(x) REPEAT_WC_8 (x), REPEAT_WC_8 (x)
103
#define REPEAT_WC_32(x) REPEAT_WC_16 (x), REPEAT_WC_16 (x)
104
#define REPEAT_WC_64(x) REPEAT_WC_32 (x), REPEAT_WC_32 (x)
105
#define REPEAT_WC_128(x) REPEAT_WC_64 (x), REPEAT_WC_64 (x)
106
#define REPEAT_WC_256(x) REPEAT_WC_128 (x), REPEAT_WC_128 (x)
107
#define REPEAT_WC_512(x) REPEAT_WC_256 (x), REPEAT_WC_256 (x)
108
#define REPEAT_WC_1024(x) REPEAT_WC_512 (x), REPEAT_WC_512 (x)
109
110
116
#define REPEAT_WC(count, text) REPEAT_WC_##count (text)
117
118
125
#define UNIQUE_NAME_1(prefix, x) prefix##x
126
#define UNIQUE_NAME_2(prefix, x) UNIQUE_NAME_1 (prefix, x)
127
128
#define UNIQUE_NAME_WP(prefix) UNIQUE_NAME_2 (prefix, __LINE__)
129
130
#define UNIQUE_NAME UNIQUE_NAME_WP (uniqueNameOnLine_)
131
132
138
#define LINE_STRING_1(x) #x
139
#define LINE_STRING_2(x) LINE_STRING_1 (x)
140
141
#define LINE_STRING LINE_STRING_2 (__LINE__)
142
143
151
#define HERE __FILE__ "(" LINE_STRING "):"
152
153
160
#define ONCE(execution_code) \
161
{ \
162
static int UNIQUE_NAME = 0; \
163
if( !UNIQUE_NAME ) \
164
{ \
165
UNIQUE_NAME = 1; \
166
{ execution_code } \
167
} \
168
}
169
170
176
#define SKIP(skip_count, execution_code) \
177
{ \
178
static int UNIQUE_NAME = 0; \
179
if( ++UNIQUE_NAME >= (skip_count) ) \
180
{ \
181
UNIQUE_NAME = 0; \
182
{ execution_code } \
183
} \
184
}
185
186
192
#define REV_SKIP(skip_count, execution_code) \
193
{ \
194
static int UNIQUE_NAME = 0; \
195
if( ++UNIQUE_NAME >= (skip_count) ) \
196
UNIQUE_NAME = 0; \
197
else \
198
{ \
199
execution_code \
200
} \
201
}
202
203
209
#define LOOP_C(count, loop_code) \
210
\
211
{ \
212
int UNIQUE_NAME = (count); \
213
for(; UNIQUE_NAME > 0; --UNIQUE_NAME) \
214
{ loop_code } \
215
}
216
217
227
#define LOOP(count) for(int UNIQUE_NAME = (count); \
228
UNIQUE_NAME > 0; \
229
--UNIQUE_NAME)
230
/* loop body here*/
231
232
239
#define AT_START(execution_code) \
240
\
241
static struct t_UNIQUE_NAME \
242
{ \
243
UNIQUE_NAME() \
244
{ \
245
execution_code \
246
} \
247
} \
248
UNIQUE_NAME_WP (atStartVarOnLine_);
249
250
257
#define AT_END(execution_code) \
258
\
259
static struct t_UNIQUE_NAME \
260
{ \
261
~UNIQUE_NAME() \
262
{ \
263
execution_code \
264
} \
265
} \
266
UNIQUE_NAME_WP (atStartVarOnLine_);
267
268
273
class
DelayedAssigner_T_Base
274
{
275
public
:
276
virtual
~DelayedAssigner_T_Base
()
277
{}
278
};
279
280
287
template
<
class
Type>
288
class
DelayedAssigner_T
:
public
DelayedAssigner_T_Base
289
{
290
Type&
itsVarRef
;
/* Reference to be assigned to*/
291
Type
itsValue
;
/* Value to be remembered and assigned*/
292
293
public
:
294
DelayedAssigner_T
(Type &var_ref)
295
:
itsVarRef
(var_ref)
296
,
itsValue
(var_ref)
297
{}
298
299
DelayedAssigner_T
(Type &var_ref,
const
Type &value)
/* separate*/
300
:
itsVarRef
(var_ref)
301
,
itsValue
(value)
302
{}
303
304
~DelayedAssigner_T
()
305
{
306
itsVarRef
=
itsValue
;
307
}
308
};
309
310
316
#define DELAYED_ASSIGN_T(Type, var_ref, value) \
317
\
318
DelayedAssigner_T<Type> UNIQUE_NAME (var_ref, value);
319
320
326
#define SAVE_T(Type, var_ref) \
327
\
328
DelayedAssigner_T<Type> UNIQUE_NAME (var_ref);
329
330
337
template
<
class
Type>
inline
338
DelayedAssigner_T<Type>
makeDelayedAssigner_T
(Type &var)
339
{
340
return
DelayedAssigner_T<Type>
(var);
341
}
342
349
template
<
class
Type>
inline
350
DelayedAssigner_T <Type>
351
makeDelayedAssigner_T
(Type &var,
const
Type& value)
352
{
353
return
DelayedAssigner_T<Type>
(var, value);
354
}
355
356
364
template
<
class
Type>
inline
365
DelayedAssigner_T_Base
*
newDelayedAssigner_T
(Type &var)
366
{
367
return
new
DelayedAssigner_T<Type>
(var);
368
}
369
370
379
template
<
class
Base,
size_t
SIZE>
380
class
UnivesalStorage_T
381
{
382
char
itsStorage
[SIZE];
/* binary storage*/
383
public
:
384
385
template
<
class
From>
386
UnivesalStorage_T
(
const
From& from)
387
{
388
/* Static checks for mismatched parameter type:*/
389
typedef
char
assertSize [
sizeof
(from) == SIZE];
390
/* will not compile if sizeof 'From' is wrong*/
391
if
(
const
Base* assertInheritence = &from)
392
(void)0;
/* will not compile if 'From' is not : public Base */
393
394
new
(
itsStorage
) From (from);
/* placement new & copy ctor*/
395
}
396
397
~UnivesalStorage_T
()
398
{
399
((Base*)
itsStorage
)->~Base();
/* hopefully virtual*/
400
}
401
};
402
403
409
#define SAVE(var_ref) \
410
\
411
UnivesalStorage_T \
412
< DelayedAssigner_T_Base, \
413
sizeof (makeDelayedAssigner_T (var_ref)) > \
414
UNIQUE_NAME (makeDelayedAssigner_T (var_ref));
415
416
422
#define DELAYED_ASSIGN(var_ref, value) \
423
\
424
UnivesalStorage_T \
425
< DelayedAssigner_T_Base, \
426
sizeof (makeDelayedAssigner_T (var_ref)) > \
427
UNIQUE_NAME (makeDelayedAssigner_T ((var_ref), (value)));
428
429
430
/* ---------------------- end of file ------------------------*/
431
432
#endif
/* _UTILITYMACROS_H_ */
Generated for cloudy by
1.8.3.1