summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/Config.h
blob: 1f452588ac472a81cb6a5d1bab3cf1c80e2f8b9e (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_UTIL_CONFIG_H
#define ICE_UTIL_CONFIG_H

//
// Endianness
//
// Most CPUs support only one endianness, with the notable exceptions
// of Itanium (IA64) and MIPS.
//
#ifdef __GLIBC__
# include <endian.h>
#endif

#if defined(__i386)     || defined(_M_IX86) || defined(__x86_64)  || \
    defined(_M_X64)     || defined(_M_IA64) || defined(__alpha__) || \
    defined(__ARMEL__) || defined(_M_ARM_FP) || defined(__arm64) || \
    defined(__MIPSEL__) || (defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN))
#   define ICE_LITTLE_ENDIAN
#elif defined(__sparc) || defined(__sparc__) || defined(__hppa)      || \
      defined(__ppc__) || defined(__powerpc) || defined(_ARCH_COM) || \
      defined(__MIPSEB__) || (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN))
#   define ICE_BIG_ENDIAN
#else
#   error "Unknown architecture"
#endif

//
// 32 or 64 bit mode?
//
#if defined(__sun) && (defined(__sparcv9) || defined(__x86_64))    || \
      defined(__linux) && defined(__x86_64)                        || \
      defined(__APPLE__) && defined(__x86_64)                      || \
      defined(__hppa) && defined(__LP64__)                         || \
      defined(_ARCH_COM) && defined(__64BIT__)                     || \
      defined(__alpha__)                                           || \
      defined(_WIN64)
#   define ICE_64
#else
#   define ICE_32
#endif

//
// Check for C++ 11 support
//
// For GCC, we recognize --std=c++0x only for GCC version 4.5 and greater,
// as C++11 support in prior releases was too limited.
//
#if (__cplusplus >= 201103) || \
    ((defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__* 100) + __GNUC_MINOR__) >= 405)) || \
    (defined(_MSC_VER) && (_MSC_VER >= 1600))
#   define ICE_CPP11_COMPILER
#endif

//
// Ensure the C++ compiler supports C++11 when using the C++11 mapping
//
#if defined(ICE_CPP11_MAPPING) && !defined(ICE_CPP11_COMPILER)
#   error "you need a C++11 capable compiler to use the C++11 mapping"
#endif


#if defined(ICE_CPP11_COMPILER) && (!defined(_MSC_VER) || (_MSC_VER >= 1900))
#   define ICE_NOEXCEPT noexcept
#   define ICE_NOEXCEPT_FALSE noexcept(false)
#else
#   define ICE_NOEXCEPT throw()
#   define ICE_NOEXCEPT_FALSE /**/
#endif

//
// Visual Studio 2012 or later, without Windows XP/2003 support
//
#if defined(_MSC_VER) && (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)

//
// Check if building for WinRT
//
#   include <winapifamily.h>
#   if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
#      define ICE_OS_WINRT
#      define ICE_STATIC_LIBS
#   endif

#endif

//
// Support for thread-safe function local static initialization
// (a.k.a. "magic statics")
//
#if defined(__GNUC__) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
#   define ICE_HAS_THREAD_SAFE_LOCAL_STATIC
#endif

//
// Compiler extensions to export and import symbols: see the documentation
// for Visual Studio, Solaris Studio and GCC.
//
#if defined(_WIN32)
#   define ICE_DECLSPEC_EXPORT __declspec(dllexport)
#   define ICE_DECLSPEC_IMPORT __declspec(dllimport)
//
//  ICE_HAS_DECLSPEC_IMPORT_EXPORT defined only for compilers with distinct
//  declspec for IMPORT and EXPORT
#   define ICE_HAS_DECLSPEC_IMPORT_EXPORT
#elif defined(__GNUC__)
#   define ICE_DECLSPEC_EXPORT __attribute__((visibility ("default")))
#   define ICE_DECLSPEC_IMPORT __attribute__((visibility ("default")))
#elif defined(__SUNPRO_CC)
#   define ICE_DECLSPEC_EXPORT __global
#   define ICE_DECLSPEC_IMPORT /**/
#else
#   define ICE_DECLSPEC_EXPORT /**/
#   define ICE_DECLSPEC_IMPORT /**/
#endif

//
// Let's use these extensions with IceUtil:
//
#if defined(ICE_UTIL_API_EXPORTS)
#   define ICE_UTIL_API ICE_DECLSPEC_EXPORT
#elif defined(ICE_STATIC_LIBS)
#   define ICE_UTIL_API /**/
#else
#   define ICE_UTIL_API ICE_DECLSPEC_IMPORT
#endif


#if defined(_MSC_VER)
#   define ICE_DEPRECATED_API(msg) __declspec(deprecated(msg))
#elif defined(__clang__)
#   if __has_extension(attribute_deprecated_with_message)
#       define ICE_DEPRECATED_API(msg) __attribute__((deprecated(msg)))
#   else
#       define ICE_DEPRECATED_API(msg) __attribute__((deprecated))
#   endif
#elif defined(__GNUC__)
#   if (__GNUC__ > 4 || (__GNUC__ == 4 &&  __GNUC_MINOR__ >= 5))
// The message option was introduced in GCC 4.5
#      define ICE_DEPRECATED_API(msg) __attribute__((deprecated(msg)))
#   else
#      define ICE_DEPRECATED_API(msg) __attribute__((deprecated))
#   endif
#else
#   define ICE_DEPRECATED_API(msg) /**/
#endif

#ifdef _WIN32
#   include <windows.h>

#   if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x600)
//
// Windows provides native condition variables on Vista and later
//
#      ifndef ICE_HAS_WIN32_CONDVAR
#          define ICE_HAS_WIN32_CONDVAR
#      endif
#   endif
#endif

//
// Some include files we need almost everywhere.
//
#include <cassert>
#include <iostream>
#include <sstream>

#ifndef _WIN32
#   include <pthread.h>
#   include <errno.h>
#endif

#ifdef __APPLE__
#   include <TargetConditionals.h>
#endif

#if !defined(ICE_BUILDING_ICE_UTIL) && defined(ICE_UTIL_API_EXPORTS)
#   define ICE_BUILDING_ICE_UTIL
#endif

#if defined(_MSC_VER)
#   if !defined(ICE_STATIC_LIBS) && (!defined(_DLL) || !defined(_MT))
#       error "Only multi-threaded DLL libraries can be used with Ice!"
#   endif

#   ifdef ICE_CPP11_MAPPING
#      if defined(_DEBUG)
#         if defined(ICE_OS_WINRT)
#            define ICE_LIBNAME(NAME) NAME "37uwp++11D.lib"
#         else
#            define ICE_LIBNAME(NAME) NAME "37++11D.lib"
#         endif
#      else
#         if defined(ICE_OS_WINRT)
#            define ICE_LIBNAME(NAME) NAME "37uwp++11.lib"
#         else
#            define ICE_LIBNAME(NAME) NAME "37++11.lib"
#         endif
#      endif
#   else
#      if defined(_DEBUG)
#         if defined(ICE_OS_WINRT)
#            define ICE_LIBNAME(NAME) NAME "37uwpD.lib"
#         else
#            define ICE_LIBNAME(NAME) NAME "37D.lib"
#         endif
#      else
#         if defined(ICE_OS_WINRT)
#            define ICE_LIBNAME(NAME) NAME "37uwp.lib"
#         else
#            define ICE_LIBNAME(NAME) NAME "37.lib"
#         endif
#      endif
#   endif

//
//  Automatically link with IceUtil[D|++11|++11D].lib
//

#   ifndef ICE_BUILDING_ICE_UTIL
#      pragma comment(lib, ICE_LIBNAME("IceUtil"))
#   endif
#endif

namespace IceUtil
{

//
// By deriving from this class, other classes are made non-copyable.
//
class ICE_UTIL_API noncopyable
{
protected:

    noncopyable() { }
    ~noncopyable() { } // May not be virtual! Classes without virtual
                       // operations also derive from noncopyable.

private:

    noncopyable(const noncopyable&);
    const noncopyable& operator=(const noncopyable&);
};

//
// Int64 typedef and ICE_INT64 macro for Int64 literal values
//
// Note that on Windows, long is always 32-bit
//
#if defined(_WIN32) && defined(_MSC_VER)
typedef __int64 Int64;
#    define ICE_INT64(n) n##i64
#    define ICE_INT64_FORMAT "%lld"
#elif defined(ICE_64) && !defined(_WIN32)
typedef long Int64;
#    define ICE_INT64(n) n##L
#    define ICE_INT64_FORMAT "%ld"
#else
typedef long long Int64;
#    define ICE_INT64(n) n##LL
#    define ICE_INT64_FORMAT "%lld"
#endif

}

//
// The Ice version.
//
#define ICE_STRING_VERSION "3.7.0" // "A.B.C", with A=major, B=minor, C=patch
#define ICE_INT_VERSION 30700      // AABBCC, with AA=major, BB=minor, CC=patch

//
// Macros to facilitate C++98 -> C++11 transition
//
#ifdef ICE_CPP11_MAPPING // C++11 mapping
#   include <memory>
#   include <future>
#   define ICE_HANDLE ::std::shared_ptr
#   define ICE_INTERNAL_HANDLE ::std::shared_ptr
#   define ICE_PROXY_HANDLE ::std::shared_ptr
#   define ICE_MAKE_SHARED(T, ...) ::std::make_shared<T>(__VA_ARGS__)
#   define ICE_DEFINE_PTR(TPtr, T) typedef ::std::shared_ptr<T> TPtr
#   define ICE_ENUM(CLASS,ENUMERATOR) CLASS::ENUMERATOR
#   define ICE_NULLPTR nullptr
#   define ICE_DYNAMIC_CAST(T,V) ::std::dynamic_pointer_cast<T>(V)
#   define ICE_SHARED_FROM_THIS shared_from_this()
#   define ICE_CHECKED_CAST(T, ...) Ice::checkedCast<T>(__VA_ARGS__)
#   define ICE_UNCHECKED_CAST(T, ...) Ice::uncheckedCast<T>(__VA_ARGS__)
#   define ICE_VALUE_FACTORY ::std::function<::std::shared_ptr<::Ice::Value> (const std::string&)>
#   define ICE_CLOSE_CALLBACK ::std::function<void (const ::std::shared_ptr<::Ice::Connection>&)>
#   define ICE_HEARTBEAT_CALLBACK ::std::function<void (const ::std::shared_ptr<::Ice::Connection>&)>
#   define ICE_IN(T) T
#   define ICE_EXCEPTION_ISSET(T) T
#   define ICE_RETHROW_EXCEPTION(T) ::std::rethrow_exception(T)
#   define ICE_RESET_EXCEPTION(T, V)  T = V
#else // C++98 mapping
#   define ICE_HANDLE ::IceUtil::Handle
#   define ICE_INTERNAL_HANDLE ::IceInternal::Handle
#   define ICE_PROXY_HANDLE ::IceInternal::ProxyHandle
#   define ICE_MAKE_SHARED(T, ...) new T(__VA_ARGS__)
#   define ICE_DEFINE_PTR(TPtr, T) typedef ::IceUtil::Handle<T> TPtr
#   define ICE_ENUM(CLASS,ENUMERATOR) ENUMERATOR
#   define ICE_NULLPTR 0
#   define ICE_DYNAMIC_CAST(T,V) T##Ptr::dynamicCast(V)
#   define ICE_SHARED_FROM_THIS this
#   define ICE_CHECKED_CAST(T, ...) T::checkedCast(__VA_ARGS__)
#   define ICE_UNCHECKED_CAST(T, ...) T::uncheckedCast(__VA_ARGS__)
#   define ICE_VALUE_FACTORY ::Ice::ValueFactoryPtr
#   define ICE_CLOSE_CALLBACK ::Ice::CloseCallbackPtr
#   define ICE_HEARTBEAT_CALLBACK ::Ice::HeartbeatCallbackPtr
#   define ICE_IN(T) const T&
#   define ICE_EXCEPTION_ISSET(T) (T.get() != 0)
#   define ICE_RETHROW_EXCEPTION(T) T->ice_throw()
#   define ICE_RESET_EXCEPTION(T,V) T.reset(V)
#endif

#endif