/usr/include/dcmtk/ofstd/ofcond.h is in libdcmtk-dev 3.6.1~20160216-4.
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 | /*
*
* Copyright (C) 2001-2015, 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, Uli Schlachter
*
* Purpose: class OFCondition and helper classes
*
*/
#ifndef OFCOND_H
#define OFCOND_H
#include "dcmtk/config/osconfig.h" /* include OS specific configuration first */
#include "dcmtk/ofstd/oftypes.h" /* for class OFBool */
#include "dcmtk/ofstd/ofstring.h" /* for class OFString */
#include "dcmtk/ofstd/ofcast.h"
#define INCLUDE_CSTRING /* for strdup() */
#define INCLUDE_CSTDLIB /* for free() */
#include "dcmtk/ofstd/ofstdinc.h"
// include this file in doxygen documentation
/** @file ofcond.h
* @brief Error handling, codes and strings for all modules
*/
/** 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
};
/** A constant data structure which can be used for an OFCondition.
* The reason this exists is because we need a trivially constructible class
* (= needs no constructor to be run before being usable) that can hold static
* condition codes.
*/
struct DCMTK_OFSTD_EXPORT OFConditionConst
{
/// module identifier. 0 is reserved for global codes.
unsigned short theModule;
/// status code that is unique for each module
unsigned short theCode;
/// condition status enum
OFStatus theStatus;
/// error text
const char *theText;
/** 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 OFConditionConst& arg) const
{
return ((theStatus == arg.theStatus) && (theCode == arg.theCode) && (theModule == arg.theModule));
}
/** 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 OFConditionConst& arg) const
{
return !(*this == arg);
}
};
/** @name global condition constants.
* All constants defined here use module number 0, which is reserved for
* global definitions. Other constants are defined in other modules.
*/
//@{
/// condition constant: successful completion
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_Normal;
/// condition constant: error, function called with illegal parameters
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_IllegalParameter;
/// condition constant: failure, memory exhausted
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_MemoryExhausted;
/// condition constant: error, no character encoding library available
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_NoEncodingLibrary;
/// condition constant: error, no character encoding selected
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_NoEncodingSelected;
/// condition constant: error, could not create temporary file
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_CouldNotCreateTemporaryFile;
/// condition constant: error, invalid filename
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_InvalidFilename;
/// condition constant: error, could not generate filename
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_CouldNotGenerateFilename;
/// condition constant: error, directory does not exist
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_DirectoryDoesNotExist;
/// condition constant: error, directory is not writable
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_DirectoryNotWritable;
/// condition constant: error, could not generate directory name
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_CouldNotGenerateDirectoryName;
/// condition constant: error, call to setuid() failed
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_setuidFailed;
/// condition constant: error, function not yet implemented
extern DCMTK_OFSTD_EXPORT const OFConditionConst EC_NotYetImplemented;
/// status code constant: error, cannot open character encoding
extern DCMTK_OFSTD_EXPORT const unsigned short EC_CODE_CannotOpenEncoding;
/// status code constant: error, cannot close character encoding
extern DCMTK_OFSTD_EXPORT const unsigned short EC_CODE_CannotCloseEncoding;
/// status code constant: error, cannot convert character encoding
extern DCMTK_OFSTD_EXPORT const unsigned short EC_CODE_CannotConvertEncoding;
/// status code constant: error, cannot control character encoding converter
extern DCMTK_OFSTD_EXPORT const unsigned short EC_CODE_CannotControlConverter;
/// status code constant: error, cannot create directory
extern DCMTK_OFSTD_EXPORT const unsigned short EC_CODE_CannotCreateDirectory;
//@}
/** use this macro for creating static OFCondition instances. Instead of an
* OFCondition instance which needs a constructor, an instance of
* OFConditionConst is created. This avoids the problem of static initializers
* (and deinitializers) being executed in undefined order (some other static
* initializer might want to use this OFCondition / OFConditionConst instance).
*/
#define makeOFConditionConst(name, module, code, status, text) \
const OFConditionConst name = { (module), (code), (status), (text) }
/** General purpose class for condition codes. Objects of this class can be
* efficiently passed by value. To make this possible, the contained string is
* not copied when possible.
*/
class DCMTK_OFSTD_EXPORT OFCondition
{
public:
/** constructor for condition code with text
* @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.
*/
OFCondition(unsigned short aModule, unsigned short aCode, OFStatus aStatus, const char *aText)
: theCondition()
, ownsText(OFTrue)
{
theCondition.theModule = aModule;
theCondition.theCode = aCode;
theCondition.theStatus = aStatus;
/* Be nice when someone dares to pass in NULL */
if (aText != NULL) {
theCondition.theText = strdup(aText);
ownsText = OFTrue;
} else {
theCondition.theText = "";
ownsText = OFFalse;
}
}
/** constructor for condition code from constant data
* @param aConst OFConditionConst to use
*/
OFCondition(const OFConditionConst& aConst = EC_Normal)
: theCondition(aConst)
, ownsText(OFFalse)
{
}
/** copy constructor
* @param arg OFCondition to copy
*/
OFCondition(const OFCondition& arg)
: theCondition(arg.theCondition)
, ownsText(arg.ownsText)
{
// Do we need our own copy of the text?
if (ownsText)
{
theCondition.theText = strdup(theCondition.theText);
}
}
/// destructor
~OFCondition()
{
if (ownsText)
{
free(OFconst_cast(char *, theCondition.theText)); // cast away const
}
}
/** copy assignment operator
* @param arg The OFCondition instance to copy
* @return *this
*/
OFCondition& operator=(const OFCondition& arg)
{
if (&arg != this)
{
if (ownsText)
{
free(OFconst_cast(char *, theCondition.theText)); // cast away const
}
theCondition = arg.theCondition;
ownsText = arg.ownsText;
if (ownsText)
{
theCondition.theText = strdup(arg.theCondition.theText);
}
}
return *this;
}
/** get the module identifier for this object.
* @return the module identifier for this object.
* @see code()
*/
inline unsigned short module() const
{
return theCondition.theModule;
}
/** get the status code identifier for this object. This uniquely identifies
* the error code within the module.
* @return the status code identifier for this object.
* @see module()
*/
inline unsigned short code() const
{
return theCondition.theCode;
}
/** get the error status this object represents.
* @return the status for this object.
*/
inline OFStatus status() const
{
return theCondition.theStatus;
}
/** get a human readable text representation of this error code. The returned
* string is owned by this OFCondition instance and must not be modified or
* freed.
* @return the error message text for this object.
*/
inline const char *text() const
{
return theCondition.theText;
}
/** internal function only, don't use yourself.
* @return an equivalent OFConditionConst for this object.
*/
inline const OFConditionConst& condition() const
{
return theCondition;
}
/** check if the status is OK.
* @return true if status is OK, else false
*/
inline OFBool good() const
{
OFStatus s = theCondition.theStatus;
return (s == OF_ok);
}
/** check if the status is not OK, i.e.\ error or failure.
* @return true if status is not OK, else false
*/
inline OFBool bad() const
{
OFStatus s = theCondition.theStatus;
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:
/// The condition information
OFConditionConst theCondition;
/// Does theCondition.theText point to our own heap string which must be freed?
OFBool ownsText;
};
/** returns true if lhs refers to the same OFCondition as rhs
* @param lhs left-hand side condition
* @param rhs right-hand side condition
* @return true if OFCondition::operator==() returns true
*/
inline OFBool operator== (const OFConditionConst& lhs, const OFCondition& rhs)
{
return lhs == rhs.condition();
}
/** returns true if lhs refers to the same OFCondition as rhs
* @param lhs left-hand side condition
* @param rhs right-hand side condition
* @return true if OFCondition::operator==() returns true
*/
inline OFBool operator== (const OFCondition& lhs, const OFConditionConst& rhs)
{
return lhs.condition() == rhs;
}
/** returns true if lhs refers to a different OFCondition as rhs
* @param lhs left-hand side condition
* @param rhs right-hand side condition
* @return true if OFCondition::operator!=() returns true
*/
inline OFBool operator!= (const OFConditionConst& lhs, const OFCondition& rhs)
{
return lhs != rhs.condition();
}
/** returns true if lhs refers to a different OFCondition as rhs
* @param lhs left-hand side condition
* @param rhs right-hand side condition
* @return true if OFCondition::operator!=() returns true
*/
inline OFBool operator!= (const OFCondition& lhs, const OFConditionConst& rhs)
{
return lhs.condition() != rhs;
}
/** this macro is a shortcut for creating user-specific error messages.
*/
#define makeOFCondition(A, B, C, D) OFCondition((A), (B), (C), (D))
#endif
|