1 /*
2  *
3  *  Copyright (C) 2003-2014, 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: Portable macros for new-style typecasts
19  *
20  */
21 
22 #ifndef OFCAST_H
23 #define OFCAST_H
24 
25 #include "dcmtk/config/osconfig.h"
26 
27 // include this file in doxygen documentation
28 
29 /** @file ofcast.h
30  *  @brief DCMTK cast macros that map to C++ casts if available
31  *
32  *  DCMTK defines its own C++ cast macros that are used throughout DCMTK
33  *  instead of the original C++ cast operators. If the C++ cast operators
34  *  are available on the platform the macros directly map to these. Otherwise
35  *  they map to old C-style casts.
36  *
37  *  In this context, DCMTK has defined a macro OFdynamic_cast that maps to C++'
38  *  dynamic_cast. However, so far dynamic casts are not used within DCMTK since
39  *  they rely on C++' RTTI feature which is deliberately avoided in DCMTK at
40  *  this moment. Thus it is highly recommended to not use dynamic casts in
41  *  DCMTK at all.
42  */
43 
44 #ifdef HAVE_CONST_CAST
45 #define OFconst_cast(x,y) (const_cast< x >(y))
46 #else
47 #define OFconst_cast(x,y) ((x)(y))
48 #endif
49 
50 // OFdynamic_cast should not be used in DCMTK since DCMTK
51 // avoids RTTI usage so far.
52 #ifdef HAVE_DYNAMIC_CAST
53 #define OFdynamic_cast(x,y) (dynamic_cast< x >(y))
54 #else
55 #define OFdynamic_cast(x,y) ((x)(y))
56 #endif
57 
58 #ifdef HAVE_REINTERPRET_CAST
59 #define OFreinterpret_cast(x,y) (reinterpret_cast< x >(y))
60 #else
61 #define OFreinterpret_cast(x,y) ((x)(y))
62 #endif
63 
64 #ifdef HAVE_STATIC_CAST
65 #define OFstatic_cast(x,y) (static_cast< x >(y))
66 #else
67 #define OFstatic_cast(x,y) ((x)(y))
68 #endif
69 
70 #endif
71