1 //  Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved.
2 //
3 //  Redistribution and use in source and binary forms, with or without modifica-
4 //  tion, are permitted provided that the following conditions are met:
5 //
6 //  1. Redistributions of  source code must  retain the above copyright  notice,
7 //     this list of conditions and the following disclaimer.
8 //
9 //  2. Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //
13 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
14 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
16 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
17 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
18 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
19 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
20 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
21 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
22 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 #ifndef DCMTK_LOG4CPLUS_CONFIG_HXX
25 #define DCMTK_LOG4CPLUS_CONFIG_HXX
26 
27 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
28 
29 #include "dcmtk/ofstd/ofdefine.h"     /* We need DCMTK_DECL_EXPORT/_IMPORT */
30 
31 #ifdef oflog_EXPORTS
32 #  define DCMTK_INSIDE_LOG4CPLUS
33 #endif
34 
35 #if defined (_WIN32)
36 #  include "dcmtk/oflog/config/win32.h"
37 #elif (defined(__MWERKS__) && defined(__MACOS__))
38 #  include "dcmtk/oflog/config/macosx.h"
39 #else
40 #  include "dcmtk/oflog/config/defines.h"
41 #endif
42 
43 #if ! defined (DCMTK_OFLOG_UNICODE) && ! defined (DCMTK_LOG4CPLUS_HAVE_VSNPRINTF_S) \
44     && ! defined (DCMTK_LOG4CPLUS_HAVE__VSNPRINTF_S) \
45     && ! defined (DCMTK_LOG4CPLUS_HAVE_VSNPRINTF) \
46     && ! defined (DCMTK_LOG4CPLUS_HAVE__VSNPRINTF)
47 #  undef DCMTK_LOG4CPLUS_USE_POOR_MANS_SNPRINTF
48 #  define DCMTK_LOG4CPLUS_USE_POOR_MANS_SNPRINTF
49 #endif
50 
51 # if ! defined (DCMTK_LOG4CPLUS_WORKING_LOCALE) \
52   && ! defined (DCMTK_LOG4CPLUS_WORKING_C_LOCALE) \
53   && ! defined (DCMTK_LOG4CPLUS_WITH_ICONV)
54 # define DCMTK_LOG4CPLUS_POOR_MANS_CHCONV
55 #endif
56 
57 #ifndef DCMTK_LOG4CPLUS_DECLSPEC_EXPORT
58 #define DCMTK_LOG4CPLUS_DECLSPEC_EXPORT /* empty */
59 #endif
60 
61 #ifndef DCMTK_LOG4CPLUS_DECLSPEC_IMPORT
62 #define DCMTK_LOG4CPLUS_DECLSPEC_IMPORT /* empty */
63 #endif
64 
65 #ifndef DCMTK_LOG4CPLUS_DECLSPEC_PRIVATE
66 #define DCMTK_LOG4CPLUS_DECLSPEC_PRIVATE /* empty */
67 #endif
68 
69 #define DCMTK_LOG4CPLUS_PRIVATE DCMTK_LOG4CPLUS_DECLSPEC_PRIVATE
70 
71 #if !defined(_WIN32)
72 #  define DCMTK_LOG4CPLUS_USE_BSD_SOCKETS
73 #  if !defined(DCMTK_LOG4CPLUS_SINGLE_THREADED)
74 #    define DCMTK_LOG4CPLUS_USE_PTHREADS
75 #  endif
76 #endif // !_WIN32
77 
78 #if defined (DCMTK_INSIDE_LOG4CPLUS)
79 #  undef DCMTK_LOG4CPLUS_EXPORT
80 #  define DCMTK_LOG4CPLUS_EXPORT DCMTK_DECL_EXPORT
81 #else
82 #  undef DCMTK_LOG4CPLUS_EXPORT
83 #  define DCMTK_LOG4CPLUS_EXPORT DCMTK_DECL_IMPORT
84 #endif // defined (DCMTK_INSIDE_LOG4CPLUS)
85 
86 #if defined (DCMTK_LOG4CPLUS_INLINES_ARE_EXPORTED) \
87     && defined (DCMTK_LOG4CPLUS_BUILD_DLL)
88 #  define DCMTK_LOG4CPLUS_INLINE_EXPORT inline
89 #else
90 #  define DCMTK_LOG4CPLUS_INLINE_EXPORT
91 #endif
92 
93 #if defined (DCMTK_OFLOG_UNICODE)
94 #  if defined (_MSC_VER) && _MSC_VER >= 1400
95 #    define DCMTK_LOG4CPLUS_FSTREAM_ACCEPTS_WCHAR_T
96 #  endif
97 #  if defined (_MSC_VER) && _MSC_VER >= 1600
98 #    define DCMTK_LOG4CPLUS_HAVE_CODECVT_UTF8_FACET
99 #    define DCMTK_LOG4CPLUS_HAVE_CODECVT_UTF16_FACET
100 #  endif
101 #endif
102 
103 // C++11 stuff
104 
105 #if ! defined (__has_feature)
106 //! __has_feature(X) is Clangs way for testing features.
107 //! Define it to 0 if it does not exist.
108 #  define __has_feature(X) 0
109 #endif
110 
111 #if (defined (_MSC_VER) && _MSC_VER >= 1600) \
112     || defined (__GXX_EXPERIMENTAL_CXX0X__)
113 #  define DCMTK_LOG4CPLUS_HAVE_CXX11_SUPPORT
114 #endif
115 
116 #if defined (DCMTK_LOG4CPLUS_HAVE_CXX11_SUPPORT) \
117     || __has_feature (cxx_rvalue_references)
118 #  define DCMTK_LOG4CPLUS_HAVE_RVALUE_REFS
119 #endif
120 
121 #if ! defined (DCMTK_OFLOG_UNICODE) && defined (__GNUC__) && __GNUC__ >= 3
122 #  define DCMTK_LOG4CPLUS_FORMAT_ATTRIBUTE(archetype, format_index, first_arg_index) \
123     __attribute__ ((format (archetype, format_index, first_arg_index)))
124 #else
125 #  define DCMTK_LOG4CPLUS_FORMAT_ATTRIBUTE(archetype, fmt_index, first_arg_index) \
126     /* empty */
127 #endif
128 
129 #if defined (__GNUC__) && __GNUC__ >= 3
130 #  define DCMTK_LOG4CPLUS_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
131 #  define DCMTK_LOG4CPLUS_ATTRIBUTE_PURE __attribute__ ((__pure__))
132 #  define DCMTK_LOG4CPLUS_BUILTIN_EXPECT(exp, c) __builtin_expect ((exp), (c))
133 #else
134 #  define DCMTK_LOG4CPLUS_ATTRIBUTE_NORETURN /* empty */
135 #  define DCMTK_LOG4CPLUS_ATTRIBUTE_PURE /* empty */
136 #  define DCMTK_LOG4CPLUS_BUILTIN_EXPECT(exp, c) (exp)
137 #endif
138 
139 #define DCMTK_LOG4CPLUS_LIKELY(cond) DCMTK_LOG4CPLUS_BUILTIN_EXPECT(!! (cond), 1)
140 #define DCMTK_LOG4CPLUS_UNLIKELY(cond) DCMTK_LOG4CPLUS_BUILTIN_EXPECT(!! (cond), 0)
141 
142 #if defined (_MSC_VER)                                             \
143     || (defined (__COMO__) && __COMO_VERSION__ >= 400) /* ??? */   \
144     || (defined (__DMC__) && __DMC__ >= 0x700) /* ??? */           \
145     || (defined (__clang__) && __clang_major__ >= 3)               \
146     || (defined (__GNUC__) && (__GNUC__ >= 4                       \
147             || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)))
148 #  define DCMTK_LOG4CPLUS_HAVE_PRAGMA_ONCE
149 #  pragma once
150 #endif
151 
152 #include "dcmtk/oflog/helpers/threadcf.h"
153 
154 #if defined(__cplusplus)
155 namespace dcmtk
156 {
157 namespace log4cplus
158 {
159 
160 //! Per thread cleanup function. Users should call this function before
161 //! a thread ends its execution. It frees resources allocated in thread local
162 //! storage. It is important only for multi-threaded static library builds
163 //! of log4cplus and user threads. In all other cases the clean up is provided
164 //! automatically by other means.
165 DCMTK_LOG4CPLUS_EXPORT void threadCleanup ();
166 
167 } // namespace log4cplus
168 } // end namespace dcmtk
169 
170 #endif
171 
172 #endif // DCMTK_LOG4CPLUS_CONFIG_HXX
173