/usr/include/dcmtk/ofstd/ofcond.h is in libdcmtk2-dev 3.6.0-15.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | /*
*
* Copyright (C) 1997-2010, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: ofstd
*
* Author: Marco Eichelberg
*
* Purpose: class OFCondition and helper classes
*
* Last Update: $Author: joergr $
* Update Date: $Date: 2010-10-14 13:15:50 $
* CVS/RCS Revision: $Revision: 1.10 $
* Status: $State: Exp $
*
* CVS/RCS Log at end of file
*
*/
#ifndef OFCOND_H
#define OFCOND_H
#include "dcmtk/config/osconfig.h"
#include "dcmtk/ofstd/oftypes.h" /* for class OFBool */
#include "dcmtk/ofstd/ofstring.h" /* for class OFString */
#include "dcmtk/ofstd/ofcast.h"
#define INCLUDE_CASSERT
#include "dcmtk/ofstd/ofstdinc.h"
/** this enumeration describes the return status of an operation.
*/
enum OFStatus
{
/// no error, operation has completed successfully
OF_ok,
/// operation has not completed successfully
OF_error,
/// application failure
OF_failure
};
/** abstract base class for condition codes
*/
class OFConditionBase
{
public:
/// default constructor
OFConditionBase()
{
}
/// copy constructor
OFConditionBase(const OFConditionBase& /* arg */)
{
}
/// destructor
virtual ~OFConditionBase()
{
}
/** this method returns a pointer to a OFConditionBase object containing a clone
* of this object. If deletable() is true, the clone must be a deep copy allocated
* on the heap. If deletable() is false, the clone should be a pointer to this.
* @return clone of this object, either deep copy or alias.
*/
virtual const OFConditionBase *clone() const = 0;
/** returns a combined code and module for this object.
* code is lower 16 bits, module is upper 16 bits
*/
virtual unsigned long codeAndModule() const = 0;
/// returns the status for this object.
virtual OFStatus status() const = 0;
/// returns the error message text for this object.
virtual const char *text() const = 0;
/** checks if this object is deletable, e.g. all instances
* of this class are allocated on the heap.
* @return true if deletable, false otherwise
*/
virtual OFBool deletable() const = 0;
/// returns the module identifier for this object.
unsigned short module() const
{
return OFstatic_cast(unsigned short,((codeAndModule() >> 16) & 0xFFFF));
}
/// returns the status code identifier for this object.
unsigned short code() const
{
return OFstatic_cast(unsigned short,(codeAndModule() & 0xFFFF));
}
/** comparison operator.
* Compares status, code and module but not error text.
* @param arg argument to compare to
* @return true if equal, false otherwise
*/
OFBool operator==(const OFConditionBase& arg) const
{
return ((status() == arg.status()) && (codeAndModule() == arg.codeAndModule()));
}
/** comparison operator, not equal.
* Compares status, code and module but not error text.
* @param arg argument to compare to
* @return false if equal, true otherwise
*/
OFBool operator!=(const OFConditionBase& arg) const
{
return ((status() != arg.status()) || (code() != arg.code()) || (module() != arg.module()));
}
private:
/// private unimplemented copy assignment operator
OFConditionBase& operator=(const OFConditionBase& arg);
};
/** this class is used to declare global condition constants.
* OFError instances may keep multiple aliased pointers to an instance of
* this class. Therefore, instances should be global constants.
*/
class OFConditionConst: public OFConditionBase
{
public:
/** constructor.
* @param aModule module identifier. 0 is reserved for global codes,
* other constants are defined elsewhere.
* @param aCode status code that is unique for each module
* @param aStatus condition status enum
* @param aText error text. The text is not copied, so the pointer must
* remain valid for the full lifetime of this object.
*/
OFConditionConst(unsigned short aModule, unsigned short aCode, OFStatus aStatus, const char *aText)
: OFConditionBase()
, theCodeAndModule(OFstatic_cast(unsigned long, aCode) | OFstatic_cast(unsigned long, aModule << 16))
, theStatus(aStatus)
, theText(aText)
{
}
/// copy constructor
OFConditionConst(const OFConditionConst& arg)
: OFConditionBase(arg)
, theCodeAndModule(arg.theCodeAndModule)
, theStatus(arg.theStatus)
, theText(arg.theText)
{
}
/// destructor
virtual ~OFConditionConst()
{
}
/** this method returns a pointer to a OFConditionBase object containing a clone
* of this object. In this case, deletable() is false and clone just returns a pointer to this.
* @return alias of this object
*/
virtual const OFConditionBase *clone() const;
/** returns a combined code and module for this object.
* code is lower 16 bits, module is upper 16 bits
*/
virtual unsigned long codeAndModule() const;
/// returns the status for this object.
virtual OFStatus status() const;
/// returns the error message text for this object.
virtual const char *text() const;
/** checks if this object is deletable, e.g. all instances
* of this class are allocated on the heap.
* @return always false for this class
*/
virtual OFBool deletable() const;
private:
/// private undefined copy assignment operator
OFConditionConst& operator=(const OFConditionConst& arg);
/// code/module identification. Code is lower 16 bits, module is upper 16 bits
unsigned long theCodeAndModule;
/// status
OFStatus theStatus;
/// condition description
const char *theText;
};
/** this class is used to declare condition codes with
* user defined error messages.
*/
class OFConditionString: public OFConditionBase
{
public:
/** constructor.
* @param aModule module identifier. 0 is reserved for global codes,
* other constants are defined elsewhere.
* @param aCode status code that is unique for each module
* @param aStatus condition status enum
* @param aText error text. The text is copied.
*/
OFConditionString(unsigned short aModule, unsigned short aCode, OFStatus aStatus, const char *aText)
: OFConditionBase()
, theCodeAndModule(OFstatic_cast(unsigned long, aCode) | OFstatic_cast(unsigned long, aModule << 16))
, theStatus(aStatus)
, theText()
{
if (aText) theText = aText;
}
/// copy constructor
OFConditionString(const OFConditionString& arg)
: OFConditionBase(arg)
, theCodeAndModule(arg.theCodeAndModule)
, theStatus(arg.theStatus)
, theText(arg.theText)
{
}
/// destructor
virtual ~OFConditionString()
{
}
/** this method returns a pointer to a OFConditionBase object containing a clone
* of this object. The clone is a deep copy allocated on the heap.
* @return deep copy of this object
*/
virtual const OFConditionBase *clone() const;
/** returns a combined code and module for this object.
* code is lower 16 bits, module is upper 16 bits
*/
virtual unsigned long codeAndModule() const;
/// returns the status for this object.
virtual OFStatus status() const;
/// returns the error message text for this object.
virtual const char *text() const;
/** checks if this object is deletable, e.g. all instances
* of this class are allocated on the heap.
* @return true if deletable, false otherwise
*/
virtual OFBool deletable() const;
private:
/// private undefined copy assignment operator
OFConditionString& operator=(const OFConditionString& arg);
/// code/module identification. Code is lower 16 bits, module is upper 16 bits
unsigned long theCodeAndModule;
/// status
OFStatus theStatus;
/// condition description
OFString theText;
};
// global constant used by OFCondition default constructor.
extern const OFConditionConst ECC_Normal;
/** General purpose class for condition codes. Objects of this class can be
* efficiently passed by value since they only contain a single pointer and
* no virtual methods. The condition code is maintained by the object of class
* OFConditionBase pointed to.
*/
class OFCondition
{
public:
/** constructor for condition code with user-defined error text
* @param base pointer to error base, which must be allocated on the heap.
* The object pointed to is deleted upon destruction of this object.
* Pointer must not be NULL.
*/
OFCondition(OFConditionString *base)
: theCondition(base)
{
assert(theCondition);
}
/** constructor for condition code with global const condition object
* @param base reference to condition base, which must be guaranteed
* to exist for the lifetime of this (and every derived) object
* since it is only referenced but not copied.
*/
#ifdef OFCONDITION_STRICT_MODE
// in strict mode OFCondition has no default constructor.
OFCondition(const OFConditionConst& base)
#else
OFCondition(const OFConditionConst& base = ECC_Normal)
#endif
: theCondition(&base)
{
assert(theCondition);
}
/// copy constructor
OFCondition(const OFCondition& arg)
: theCondition(arg.theCondition->clone())
{
assert(theCondition);
}
/// destructor
~OFCondition()
{
if (theCondition->deletable())
{
delete OFconst_cast(OFConditionBase *, theCondition); // cast away const
}
}
/// copy assignment operator
OFCondition& operator=(const OFCondition& arg)
{
if (&arg != this)
{
if (theCondition->deletable())
{
delete OFconst_cast(OFConditionBase *, theCondition); // cast away const
}
theCondition = arg.theCondition->clone();
assert(theCondition);
}
return *this;
}
/// returns the module identifier for this object.
inline unsigned short module() const
{
return theCondition->module();
}
/// returns the status code identifier for this object.
inline unsigned short code() const
{
return theCondition->code();
}
/// returns the status for this object.
inline OFStatus status() const
{
return theCondition->status();
}
/// returns the error message text for this object.
inline const char *text() const
{
return theCondition->text();
}
/// returns true if status is OK
inline OFBool good() const
{
OFStatus s = theCondition->status();
return (s == OF_ok);
}
/// returns true if status is not OK, i. e. error or failure
inline OFBool bad() const
{
OFStatus s = theCondition->status();
return (s != OF_ok);
}
#ifdef OFCONDITION_IMPLICIT_BOOL_CONVERSION
/* Implicit conversion from OFCondition to bool might
* not always be a good idea since it can hide unwanted constructs.
* Therefore, we disable this operator by default.
*/
/** conversion operator to bool.
* @return true if status is OK, false otherwise
*/
inline operator OFBool() const
{
return good();
}
#endif
/** comparison operator. Compares status, code and module
* but not error text.
* @param arg error to compare to
* @return true if equal, false otherwise
*/
inline OFBool operator==(const OFCondition& arg) const
{
return (*theCondition == *arg.theCondition);
}
/** comparison operator. Compares status, code and module
* but not error text.
* @param arg error to compare to
* @return true if equal, false otherwise
*/
inline OFBool operator!=(const OFCondition& arg) const
{
return (*theCondition != *arg.theCondition);
}
private:
/// pointer to the condition base object
const OFConditionBase *theCondition;
};
/* global condition constants.
* All constants defined here use module number 0 which is reserved for
* global definitions. Other constants are defined elsewhere.
*/
/// condition constant: successful completion
extern const OFCondition EC_Normal;
/// condition constant: error, function called with illegal parameters
extern const OFCondition EC_IllegalParameter;
/// condition constant: failure, memory exhausted
extern const OFCondition EC_MemoryExhausted;
/** this macro is a shortcut for creating user-specific error messages.
*/
#define makeOFCondition(A, B, C, D) OFCondition(new OFConditionString((A), (B), (C), (D)))
#endif
/*
* CVS/RCS Log:
* $Log: ofcond.h,v $
* Revision 1.10 2010-10-14 13:15:50 joergr
* Updated copyright header. Added reference to COPYRIGHT file.
*
* Revision 1.9 2005/12/08 16:05:50 meichel
* Changed include path schema for all DCMTK header files
*
* Revision 1.8 2003/12/05 10:37:41 joergr
* Removed leading underscore characters from preprocessor symbols (reserved
* symbols). Updated copyright date where appropriate.
*
* Revision 1.7 2003/07/09 13:57:43 meichel
* Adapted type casts to new-style typecast operators defined in ofcast.h
*
* Revision 1.6 2003/07/04 13:31:51 meichel
* Fixed issues with compiling with HAVE_STD_STRING
*
* Revision 1.5 2003/06/12 13:15:59 joergr
* Fixed inconsistent API documentation reported by Doxygen.
*
* Revision 1.4 2001/11/09 15:44:39 joergr
* Removed ";" from macro definition to avoid compiler warnings reported by
* Sun CC 2.0.1.
*
* Revision 1.3 2001/10/12 10:42:26 meichel
* Introduced conditional define OFCONDITION_STRICT_MODE in which the
* compatibility options related to the transition to OFCondition are disabled:
* No OFCondition default constructor, no typedefs for E_Condition, CONDITION,
* no macros for SUCCESS and condition aliases.
*
* Revision 1.2 2001/09/25 17:07:24 meichel
* Disabled implicit conversion to bool, added default constructor
* to class OFCondition.
*
* Revision 1.1 2001/08/23 16:08:37 meichel
* Initial release of class OFCondition, a generic approach for condition codes
*
*
*/
|