OFFIS DCMTK
Version 3.6.0
Main Page
Related Pages
Classes
Files
File List
File Members
ofstd
include
dcmtk
ofstd
ofcond.h
1
/*
2
*
3
* Copyright (C) 1997-2010, OFFIS e.V.
4
* All rights reserved. See COPYRIGHT file for details.
5
*
6
* This software and supporting documentation were developed by
7
*
8
* OFFIS e.V.
9
* R&D Division Health
10
* Escherweg 2
11
* D-26121 Oldenburg, Germany
12
*
13
*
14
* Module: ofstd
15
*
16
* Author: Marco Eichelberg
17
*
18
* Purpose: class OFCondition and helper classes
19
*
20
* Last Update: $Author: joergr $
21
* Update Date: $Date: 2010-10-14 13:15:50 $
22
* CVS/RCS Revision: $Revision: 1.10 $
23
* Status: $State: Exp $
24
*
25
* CVS/RCS Log at end of file
26
*
27
*/
28
29
30
#ifndef OFCOND_H
31
#define OFCOND_H
32
33
#include "dcmtk/config/osconfig.h"
34
#include "dcmtk/ofstd/oftypes.h"
/* for class OFBool */
35
#include "dcmtk/ofstd/ofstring.h"
/* for class OFString */
36
#include "dcmtk/ofstd/ofcast.h"
37
38
#define INCLUDE_CASSERT
39
#include "dcmtk/ofstd/ofstdinc.h"
40
43
enum
OFStatus
44
{
46
OF_ok,
47
49
OF_error,
50
52
OF_failure
53
};
54
55
58
class
OFConditionBase
59
{
60
public
:
61
63
OFConditionBase
()
64
{
65
}
66
68
OFConditionBase
(
const
OFConditionBase
&
/* arg */
)
69
{
70
}
71
73
virtual
~OFConditionBase
()
74
{
75
}
76
82
virtual
const
OFConditionBase
*
clone
()
const
= 0;
83
87
virtual
unsigned
long
codeAndModule
()
const
= 0;
88
90
virtual
OFStatus
status
()
const
= 0;
91
93
virtual
const
char
*
text
()
const
= 0;
94
99
virtual
OFBool
deletable
()
const
= 0;
100
102
unsigned
short
module
()
const
103
{
104
return
OFstatic_cast(
unsigned
short
,((
codeAndModule
() >> 16) & 0xFFFF));
105
}
106
108
unsigned
short
code
()
const
109
{
110
return
OFstatic_cast(
unsigned
short
,(
codeAndModule
() & 0xFFFF));
111
}
112
118
OFBool
operator==
(
const
OFConditionBase
& arg)
const
119
{
120
return
((
status
() == arg.
status
()) && (
codeAndModule
() == arg.
codeAndModule
()));
121
}
122
128
OFBool
operator!=
(
const
OFConditionBase
& arg)
const
129
{
130
return
((
status
() != arg.
status
()) || (
code
() != arg.
code
()) || (
module
() != arg.
module
()));
131
}
132
133
private
:
134
136
OFConditionBase
&
operator=
(
const
OFConditionBase
& arg);
137
138
};
139
140
141
146
class
OFConditionConst
:
public
OFConditionBase
147
{
148
public
:
149
158
OFConditionConst
(
unsigned
short
aModule,
unsigned
short
aCode, OFStatus aStatus,
const
char
*aText)
159
:
OFConditionBase
()
160
,
theCodeAndModule
(OFstatic_cast(unsigned long, aCode) | OFstatic_cast(unsigned long, aModule << 16))
161
,
theStatus
(aStatus)
162
,
theText
(aText)
163
{
164
}
165
167
OFConditionConst
(
const
OFConditionConst
& arg)
168
:
OFConditionBase
(arg)
169
,
theCodeAndModule
(arg.
theCodeAndModule
)
170
,
theStatus
(arg.
theStatus
)
171
,
theText
(arg.
theText
)
172
{
173
}
174
176
virtual
~OFConditionConst
()
177
{
178
}
179
184
virtual
const
OFConditionBase
*
clone
()
const
;
185
189
virtual
unsigned
long
codeAndModule
()
const
;
190
192
virtual
OFStatus
status
()
const
;
193
195
virtual
const
char
*
text
()
const
;
196
201
virtual
OFBool
deletable
()
const
;
202
203
private
:
204
206
OFConditionConst
&
operator=
(
const
OFConditionConst
& arg);
207
209
unsigned
long
theCodeAndModule
;
210
212
OFStatus
theStatus
;
213
215
const
char
*
theText
;
216
217
};
218
219
220
224
class
OFConditionString
:
public
OFConditionBase
225
{
226
public
:
227
235
OFConditionString
(
unsigned
short
aModule,
unsigned
short
aCode, OFStatus aStatus,
const
char
*aText)
236
:
OFConditionBase
()
237
,
theCodeAndModule
(OFstatic_cast(unsigned long, aCode) | OFstatic_cast(unsigned long, aModule << 16))
238
,
theStatus
(aStatus)
239
,
theText
()
240
{
241
if
(aText)
theText
= aText;
242
}
243
245
OFConditionString
(
const
OFConditionString
& arg)
246
:
OFConditionBase
(arg)
247
,
theCodeAndModule
(arg.
theCodeAndModule
)
248
,
theStatus
(arg.
theStatus
)
249
,
theText
(arg.
theText
)
250
{
251
}
252
254
virtual
~OFConditionString
()
255
{
256
}
257
262
virtual
const
OFConditionBase
*
clone
()
const
;
263
267
virtual
unsigned
long
codeAndModule
()
const
;
268
270
virtual
OFStatus
status
()
const
;
271
273
virtual
const
char
*
text
()
const
;
274
279
virtual
OFBool
deletable
()
const
;
280
281
private
:
283
OFConditionString
&
operator=
(
const
OFConditionString
& arg);
284
286
unsigned
long
theCodeAndModule
;
287
289
OFStatus
theStatus
;
290
292
OFString
theText
;
293
};
294
295
296
// global constant used by OFCondition default constructor.
297
extern
const
OFConditionConst
ECC_Normal;
298
299
305
class
OFCondition
306
{
307
public
:
308
314
OFCondition
(
OFConditionString
*base)
315
:
theCondition
(base)
316
{
317
assert(
theCondition
);
318
}
319
325
#ifdef OFCONDITION_STRICT_MODE
326
// in strict mode OFCondition has no default constructor.
327
OFCondition
(
const
OFConditionConst
& base)
328
#else
329
OFCondition
(
const
OFConditionConst
& base = ECC_Normal)
330
#endif
331
:
theCondition
(&base)
332
{
333
assert(
theCondition
);
334
}
335
337
OFCondition
(
const
OFCondition
& arg)
338
:
theCondition
(arg.
theCondition
->clone())
339
{
340
assert(
theCondition
);
341
}
342
344
~OFCondition
()
345
{
346
if
(
theCondition
->
deletable
())
347
{
348
delete
OFconst_cast(
OFConditionBase
*,
theCondition
);
// cast away const
349
}
350
}
351
353
OFCondition
&
operator=
(
const
OFCondition
& arg)
354
{
355
if
(&arg !=
this
)
356
{
357
if
(
theCondition
->
deletable
())
358
{
359
delete
OFconst_cast(
OFConditionBase
*,
theCondition
);
// cast away const
360
}
361
theCondition
= arg.
theCondition
->
clone
();
362
assert(
theCondition
);
363
}
364
return
*
this
;
365
}
366
368
inline
unsigned
short
module
()
const
369
{
370
return
theCondition
->
module
();
371
}
372
374
inline
unsigned
short
code
()
const
375
{
376
return
theCondition
->
code
();
377
}
378
380
inline
OFStatus
status
()
const
381
{
382
return
theCondition
->
status
();
383
}
384
386
inline
const
char
*
text
()
const
387
{
388
return
theCondition
->
text
();
389
}
390
392
inline
OFBool
good
()
const
393
{
394
OFStatus s =
theCondition
->
status
();
395
return
(s == OF_ok);
396
}
397
399
inline
OFBool
bad
()
const
400
{
401
OFStatus s =
theCondition
->
status
();
402
return
(s != OF_ok);
403
}
404
405
#ifdef OFCONDITION_IMPLICIT_BOOL_CONVERSION
406
/* Implicit conversion from OFCondition to bool might
407
* not always be a good idea since it can hide unwanted constructs.
408
* Therefore, we disable this operator by default.
409
*/
410
414
inline
operator
OFBool()
const
415
{
416
return
good
();
417
}
418
#endif
419
425
inline
OFBool
operator==
(
const
OFCondition
& arg)
const
426
{
427
return
(*
theCondition
== *arg.
theCondition
);
428
}
429
435
inline
OFBool
operator!=
(
const
OFCondition
& arg)
const
436
{
437
return
(*
theCondition
!= *arg.
theCondition
);
438
}
439
440
private
:
441
443
const
OFConditionBase
*
theCondition
;
444
445
};
446
447
448
/* global condition constants.
449
* All constants defined here use module number 0 which is reserved for
450
* global definitions. Other constants are defined elsewhere.
451
*/
452
454
extern
const
OFCondition
EC_Normal;
455
457
extern
const
OFCondition
EC_IllegalParameter;
458
460
extern
const
OFCondition
EC_MemoryExhausted;
461
462
465
#define makeOFCondition(A, B, C, D) OFCondition(new OFConditionString((A), (B), (C), (D)))
466
467
468
#endif
469
470
/*
471
* CVS/RCS Log:
472
* $Log: ofcond.h,v $
473
* Revision 1.10 2010-10-14 13:15:50 joergr
474
* Updated copyright header. Added reference to COPYRIGHT file.
475
*
476
* Revision 1.9 2005/12/08 16:05:50 meichel
477
* Changed include path schema for all DCMTK header files
478
*
479
* Revision 1.8 2003/12/05 10:37:41 joergr
480
* Removed leading underscore characters from preprocessor symbols (reserved
481
* symbols). Updated copyright date where appropriate.
482
*
483
* Revision 1.7 2003/07/09 13:57:43 meichel
484
* Adapted type casts to new-style typecast operators defined in ofcast.h
485
*
486
* Revision 1.6 2003/07/04 13:31:51 meichel
487
* Fixed issues with compiling with HAVE_STD_STRING
488
*
489
* Revision 1.5 2003/06/12 13:15:59 joergr
490
* Fixed inconsistent API documentation reported by Doxygen.
491
*
492
* Revision 1.4 2001/11/09 15:44:39 joergr
493
* Removed ";" from macro definition to avoid compiler warnings reported by
494
* Sun CC 2.0.1.
495
*
496
* Revision 1.3 2001/10/12 10:42:26 meichel
497
* Introduced conditional define OFCONDITION_STRICT_MODE in which the
498
* compatibility options related to the transition to OFCondition are disabled:
499
* No OFCondition default constructor, no typedefs for E_Condition, CONDITION,
500
* no macros for SUCCESS and condition aliases.
501
*
502
* Revision 1.2 2001/09/25 17:07:24 meichel
503
* Disabled implicit conversion to bool, added default constructor
504
* to class OFCondition.
505
*
506
* Revision 1.1 2001/08/23 16:08:37 meichel
507
* Initial release of class OFCondition, a generic approach for condition codes
508
*
509
*
510
*/
Generated on Thu Dec 20 2012 for
OFFIS DCMTK
Version 3.6.0 by
Doxygen
1.8.2