00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef COH_COMPATIBILITY_HPP
00017 #define COH_COMPATIBILITY_HPP
00018
00019
00020
00021 #include <typeinfo>
00022
00023
00024
00025 #if defined(_WIN32)
00026 # define COH_OS_WINDOWS
00027 # define COH_LIB_PREFIX ""
00028 # define COH_LIB_SUFFIX ".dll"
00029 # if defined(_WIN64)
00030 # define COH_OS_WIN64 // Windows 2003/2008/Vista
00031 # define COH_PLATFORM Microsoft Windows x64
00032 # else
00033 # define COH_OS_WIN32 // Windows NT/2000/XP
00034 # define COH_PLATFORM Microsoft Windows x86
00035 # endif
00036 #elif defined(__sun) || defined(sun)
00037 # define COH_OS_SOLARIS // Oracle Solaris
00038 # define COH_OS_UNIX
00039 # define COH_LIB_PREFIX "lib"
00040 # define COH_LIB_SUFFIX ".so"
00041 # include <sys/types.h>
00042 # if defined(__sparc)
00043 # if defined(_LP64)
00044 # define COH_OS_SOLARIS64
00045 # define COH_PLATFORM Oracle Solaris SPARC 64b
00046 # else
00047 # define COH_OS_SOLARIS32
00048 # define COH_PLATFORM Oracle Solaris SPARC 32b
00049 # endif
00050 # elif defined(__x86)
00051 # if defined(_LP64)
00052 # define COH_OS_SOLARIS64
00053 # define COH_PLATFORM Oracle Solaris x64
00054 # else
00055 # define COH_OS_SOLARIS32
00056 # define COH_PLATFORM Oracle Solaris x86
00057 # endif
00058 # endif
00059 #elif defined(__linux__)
00060 # define COH_OS_LINUX // Linux
00061 # define COH_LIB_PREFIX "lib"
00062 # define COH_LIB_SUFFIX ".so"
00063 # define COH_OS_UNIX
00064 # if defined(__x86_64__) || defined(__amd64__)
00065 # define COH_OS_LINUX64
00066 # define COH_PLATFORM Linux x64
00067 # elif defined(__x86_32__) || defined(__i386__)
00068 # define COH_OS_LINUX32
00069 # define COH_PLATFORM Linux x86
00070 # endif
00071 #elif defined(__APPLE__)
00072 # define COH_OS_DARWIN // Mac OS X
00073 # define COH_OS_UNIX
00074 # define COH_LIB_PREFIX "lib"
00075 # define COH_LIB_SUFFIX ".dylib"
00076 # if defined(__x86_64__) || defined(__amd64__)
00077 # define COH_OS_DARWIN64
00078 # define COH_PLATFORM Apple Mac OS X x64
00079 # elif defined(__x86_32__) || defined(__i386__)
00080 # define COH_OS_DARWIN32
00081 # define COH_PLATFORM Apple Mac OS X x86
00082 # endif
00083 #endif
00084
00085 #ifndef COH_PLATFORM
00086 # error "Coherence for C++ does not support this platform."
00087 #endif
00088
00089
00090
00091
00092 #if defined(_MSC_VER) && _MSC_VER >= 1400
00093 # define COH_CC_MSVC // Microsoft Visual C/C++
00094 # if _MSC_VER == 1400
00095 # define COH_CC msvc 2005
00096 # elif _MSC_VER == 1500
00097 # define COH_CC msvc 2008
00098 # elif _MSC_VER == 1600
00099 # define COH_CC msvc 2010
00100 # elif _MSC_VER == 1700
00101 # define COH_CC msvc 2012
00102 # else
00103 # define COH_CC msvc
00104 # endif
00105 #elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590
00106 # define COH_CC_SUN // Forte Developer, or Oracle Solaris Studio
00107 # if defined (STLPORT)
00108 # define COH_CC sunpro stlport
00109 # else
00110 # define COH_CC sunpro
00111 # endif
00112 #elif defined(__GNUG__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
00113 # define COH_CC_GNU // GNU C++
00114 # define COH_CC gcc
00115 #else
00116 # error "Coherence for C++ does not support this compiler or compiler version."
00117 #endif
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #if defined(COH_CC_MSVC)
00129 #define COH_PRAGMA_PUSH \
00130 __pragma(warning(push)) \
00131 \
00132 __pragma(warning(disable : 4250)) \
00133 \
00134 __pragma(warning(disable : 4251)) \
00135 \
00136 __pragma(warning(disable : 4275)) \
00137 \
00138 __pragma(warning(disable : 4521)) \
00139 \
00140 __pragma(warning(disable : 4522)) \
00141
00142 \
00143 __pragma(warning(disable : 4715; disable : 4716))
00144
00145 #define COH_PRAGMA_POP __pragma(warning(pop))
00146 #else
00147 #define COH_PRAGMA_PUSH
00148 #define COH_PRAGMA_POP
00149 #endif
00150
00151
00152
00153
00154
00155
00156 #define COH_NO_WARN(STMT) COH_PRAGMA_PUSH STMT COH_PRAGMA_POP
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 #if defined(COH_CC_MSVC)
00170 #define COH_NO_RETURN_PRE __declspec(noreturn)
00171 #define COH_NO_RETURN_POST
00172 #define COH_NO_RETURN_STMT(expr) expr
00173 #elif defined(COH_CC_GNU)
00174 #define COH_NO_RETURN_PRE
00175 #define COH_NO_RETURN_POST __attribute__((noreturn))
00176 #define COH_NO_RETURN_STMT(expr) expr
00177 #elif defined(COH_CC_SUN)
00178 #define COH_NO_RETURN_PRE
00179 #define COH_NO_RETURN_POST
00180 #define COH_NO_RETURN_STMT(expr)\
00181 do { expr; throw std::exception(); } while (0)
00182 #else
00183 #define COH_NO_RETURN_PRE
00184 #define COH_NO_RETURN_POST
00185 #define COH_NO_RETURN_STMT(expr) expr
00186 #endif
00187
00188
00189
00190
00191
00192
00193
00194 namespace coherence { namespace lang {}}
00195
00196 #define COH_OPEN_NAMESPACE(ns) namespace ns { \
00197 COH_PRAGMA_PUSH \
00198 using namespace coherence::lang;
00199
00200 #define COH_INNER_NAMESPACE(ns) namespace ns {
00201
00202 #define COH_OPEN_NAMESPACE2(ns1, ns2)\
00203 COH_OPEN_NAMESPACE (ns1) COH_INNER_NAMESPACE (ns2)
00204
00205 #define COH_OPEN_NAMESPACE3(ns1, ns2, ns3)\
00206 COH_OPEN_NAMESPACE2 (ns1, ns2) COH_INNER_NAMESPACE (ns3)
00207
00208 #define COH_OPEN_NAMESPACE4(ns1, ns2, ns3, ns4)\
00209 COH_OPEN_NAMESPACE3 (ns1, ns2, ns3) COH_INNER_NAMESPACE (ns4)
00210
00211 #define COH_OPEN_NAMESPACE5(ns1, ns2, ns3, ns4, ns5)\
00212 COH_OPEN_NAMESPACE4 (ns1, ns2, ns3, ns4) COH_INNER_NAMESPACE (ns5)
00213
00214 #define COH_OPEN_NAMESPACE6(ns1, ns2, ns3, ns4, ns5, ns6)\
00215 COH_OPEN_NAMESPACE5 (ns1, ns2, ns3, ns4, ns5) COH_INNER_NAMESPACE (ns6)
00216
00217 #define COH_OPEN_NAMESPACE7(ns1, ns2, ns3, ns4, ns5, ns6, ns7)\
00218 COH_OPEN_NAMESPACE6 (ns1, ns2, ns3, ns4, ns5, ns6) COH_INNER_NAMESPACE (ns7)
00219
00220 #define COH_CLOSE_NAMESPACE COH_PRAGMA_POP }
00221
00222 #define COH_CLOSE_NAMESPACE2 COH_PRAGMA_POP } }
00223
00224 #define COH_CLOSE_NAMESPACE3 COH_PRAGMA_POP } } }
00225
00226 #define COH_CLOSE_NAMESPACE4 COH_PRAGMA_POP } } } }
00227
00228 #define COH_CLOSE_NAMESPACE5 COH_PRAGMA_POP } } } } }
00229
00230 #define COH_CLOSE_NAMESPACE6 COH_PRAGMA_POP } } } } } }
00231
00232 #define COH_CLOSE_NAMESPACE7 COH_PRAGMA_POP } } } } } } }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 #define COH_JOIN(X, Y) COH_DO_JOIN(X, Y)
00247 #define COH_DO_JOIN(X, Y) COH_DO_JOIN2(X, Y)
00248 #define COH_DO_JOIN2(X, Y) X##Y
00249 #ifdef COH_CC_MSVC_NET // MSVC 2002 and later
00250 # define COH_UNIQUE_IDENTIFIER(Name) COH_JOIN(Name, __COUNTER__)
00251 #else
00252 # define COH_UNIQUE_IDENTIFIER(Name) COH_JOIN(Name, __LINE__)
00253 #endif
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 #ifdef COH_EAGER_INIT
00271 # define COH_STATIC_INIT_EX(N, FUNC) \
00272 static const bool COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_) = (FUNC, true)
00273 #else
00274
00275
00276
00277
00278
00279 # define COH_STATIC_INIT_EX(N, FUNC) \
00280 static void COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_)() {FUNC;} \
00281 static coherence::lang::coh_initializer \
00282 COH_UNIQUE_IDENTIFIER(coh_static_init_reg##N##_) \
00283 (&COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_))
00284 #endif
00285
00286 #define COH_STATIC_INIT(FUNC) COH_STATIC_INIT_EX(0, FUNC)
00287
00288 COH_OPEN_NAMESPACE2(coherence,lang)
00289 template <bool x> struct STATIC_ASSERTION_FAILURE;
00290 template<> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
00291 COH_CLOSE_NAMESPACE2
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 #define COH_STATIC_ASSERT(B) \
00310 enum { COH_UNIQUE_IDENTIFIER(coh_static_assert_enum_) =\
00311 sizeof(coherence::lang::STATIC_ASSERTION_FAILURE<(bool)(B)>) }
00312
00313
00314
00315
00316 #if defined(COH_CC_MSVC)
00317 #ifdef COH_BUILD
00318 #define COH_EXPORT __declspec(dllexport)
00319 #else
00320 #define COH_EXPORT __declspec(dllimport)
00321 #endif
00322 #define COH_EXPORT_SPEC __declspec(dllexport)
00323 #define COH_EXPORT_SPEC_MEMBER(DECL)
00324 #else
00325 #define COH_EXPORT
00326 #define COH_EXPORT_SPEC
00327 #define COH_EXPORT_SPEC_MEMBER(DECL) DECL;
00328 #endif
00329
00330
00331
00332
00333 #if defined(COH_CC_MSVC)
00334 #define COH_INLINE __forceinline
00335 #elif defined(COH_CC_GNU)
00336 #define COH_INLINE __attribute__((always_inline)) inline
00337 #else
00338 #define COH_INLINE inline
00339 #endif
00340
00341
00342
00343
00344 #if defined(__GNUC__)
00345 #define COH_CURRENT_FUNCTION __PRETTY_FUNCTION__
00346 #elif defined(__FUNCSIG__)
00347 #define COH_CURRENT_FUNCTION __FUNCSIG__
00348 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
00349 #define COH_CURRENT_FUNCTION __func__
00350 #else
00351 #define COH_CURRENT_FUNCTION "(unknown function)"
00352 #endif
00353
00354
00355
00356
00357
00358
00359
00360 #include <utility>
00361 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 ||\
00362 defined(_POSIX_VERSION) && _POSIX_VERSION >= 200100 ||\
00363 defined(COH_OS_LINUX) &&\
00364 defined(__GLIBC__) &&\
00365 (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) &&\
00366 defined(__GNUC__) ||\
00367 defined(COH_OS_DARWIN) && __MACH__ && !defined(_MSL_USING_MSL_C)
00368 # define COH_HAS_STDINT_H
00369 #endif
00370
00371 #if defined(__GCCXML__) ||\
00372 defined(__GNUC__) ||\
00373 defined(_MSC_VER) && _MSC_VER >= 1310 && defined(_MSC_EXTENSIONS)
00374 # define COH_HAS_LONG_LONG
00375 #endif
00376
00377 #if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) &&\
00378 !defined(_GLIBCPP_USE_LONG_LONG) && \
00379 !defined(_GLIBCXX_USE_LONG_LONG) && \
00380 defined(COH_HAS_LONG_LONG)
00381
00382
00383
00384
00385 # include <ostream>
00386 namespace std
00387 {
00388 template<class E, class T>
00389 inline basic_ostream<E, T>& operator<<
00390 (basic_ostream<E, T>& out, long long l)
00391 {
00392 return out << static_cast<long>(l);
00393 }
00394 template<class E, class T>
00395 inline basic_ostream<E, T>& operator<<
00396 (basic_ostream<E, T>& out, unsigned long long l)
00397 {
00398 return out << static_cast<unsigned long>(l);
00399 }
00400 }
00401 # undef COH_HAS_LONG_LONG
00402 #endif
00403
00404 #if !defined(COH_HAS_LONG_LONG) && !defined(COH_CC_MSVC)
00405 # include <limits.h>
00406 # if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) ||\
00407 defined(ULONGLONG_MAX)
00408 # define COH_HAS_LONG_LONG
00409 # endif
00410 #endif
00411
00412 #if defined(_MSC_VER) && _MSC_VER >= 1200
00413 # define COH_HAS_MS_INT64
00414 #endif
00415
00416
00417
00418
00419 #if defined(COH_HAS_STDINT_H)
00420 # include <stdint.h>
00421 #elif defined(COH_CC_SUN)
00422 # include <inttypes.h>
00423 #else
00424
00425
00426
00427
00428 # include <climits>
00429 # ifdef COH_NAMESPACED_FIXED_INTS
00430 COH_OPEN_NAMESPACE2(coherence,lang)
00431 # endif
00432 COH_STATIC_ASSERT(UCHAR_MAX == 0xFF);
00433 typedef signed char int8_t;
00434 typedef unsigned char uint8_t;
00435 COH_STATIC_ASSERT(USHRT_MAX == 0xFFFF);
00436 typedef short int16_t;
00437 typedef unsigned short uint16_t;
00438 # if UINT_MAX == 0xFFFFFFFF
00439 typedef int int32_t;
00440 typedef unsigned int uint32_t;
00441 # elif ULONG_MAX == 0xFFFFFFFF
00442 typedef long int32_t;
00443 typedef unsigned long uint32_t;
00444 # else
00445 # error int size not correct
00446 # endif
00447 # if defined(COH_HAS_LONG_LONG) &&\
00448 !defined(COH_CC_MSVC) &&\
00449 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
00450 (defined(ULLONG_MAX) ||\
00451 defined(ULONG_LONG_MAX) ||\
00452 defined(ULONGLONG_MAX))
00453 # if defined(ULLONG_MAX)
00454 COH_STATIC_ASSERT(ULLONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00455 # elif defined(ULONG_LONG_MAX)
00456 COH_STATIC_ASSERT
00457 (ULONG_LONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00458 # elif defined(ULONGLONG_MAX)
00459 COH_STATIC_ASSERT
00460 (ULONGLONG_MAX == 0xFFFFFFFFFFFFFFFFULL));
00461 # else
00462 # error long long size not correct
00463 # endif
00464 typedef long long int64_t;
00465 typedef unsigned long long uint64_t;
00466 # elif ULONG_MAX != 0xFFFFFFFF
00467 COH_STATIC_ASSERT(ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00468 typedef long int64_t;
00469 typedef unsigned long uint64_t;
00470 # elif defined(__GNUC__) && defined(COH_HAS_LONG_LONG)
00471 __extension__ typedef long long int64_t;
00472 __extension__ typedef unsigned long long uint64_t;
00473 # elif defined(COH_HAS_MS_INT64)
00474 typedef __int64 int64_t;
00475 typedef unsigned __int64 uint64_t;
00476 # else
00477 # error no 64-bit integer support
00478 # endif
00479 # ifdef COH_NAMESPACED_FIXED_INTS
00480 COH_CLOSE_NAMESPACE2
00481 # endif
00482 #endif
00483
00484
00485
00486
00487 COH_OPEN_NAMESPACE2(coherence,lang)
00488 typedef unsigned char octet_t;
00489 typedef uint16_t char16_t;
00490 typedef uint32_t size32_t;
00491 typedef uint64_t size64_t;
00492 typedef float float32_t; COH_STATIC_ASSERT(sizeof(float32_t) >= sizeof(int32_t));
00493 typedef double float64_t; COH_STATIC_ASSERT(sizeof(float64_t) >= sizeof(int64_t));
00494 COH_CLOSE_NAMESPACE2
00495
00496
00497
00498
00499
00500
00501
00502
00503 #define COH_INT64(HIGH, LOW) int64_t(uint64_t(HIGH) << 32 | uint64_t(LOW))
00504
00505
00506 #define COH_SYMB_STRING(SYMB) #SYMB
00507 #define COH_SYMB_TO_STRING(SYMB) COH_SYMB_STRING(SYMB)
00508
00509
00510
00511
00512 #include <typeinfo>
00513 COH_OPEN_NAMESPACE2(coherence,lang)
00514 class Class;
00515
00516 typedef void (*coh_static_initializer)();
00517
00518
00519
00520
00521 extern COH_EXPORT void coh_register_initializer(
00522 coh_static_initializer pInit, bool fAdd);
00523
00524
00525
00526
00527 class coh_initializer
00528 {
00529 public:
00530
00531 coh_initializer(coh_static_initializer pInit)
00532 : m_pInit(pInit)
00533 {
00534 coh_register_initializer(pInit, true);
00535 }
00536
00537 ~coh_initializer()
00538 {
00539 coh_register_initializer(m_pInit, false);
00540 }
00541
00542 private:
00543 coh_static_initializer m_pInit;
00544 };
00545
00546
00547
00548
00549 extern COH_EXPORT void coh_throw_npe(const std::type_info&);
00550 extern COH_EXPORT void coh_throw_class_cast(const std::type_info&,
00551 const std::type_info&);
00552 extern COH_EXPORT void coh_throw_const_cast(const std::type_info&,
00553 const std::type_info&);
00554 extern COH_EXPORT void coh_throw_illegal_state(const char* achMsg);
00555 extern COH_EXPORT void coh_throw_illegal_argument(const char* achMsg);
00556 extern COH_EXPORT void coh_throw_unsupported_operation(const char* achMsg);
00557 extern COH_EXPORT const Class* coh_loadClassByType(const std::type_info& ti);
00558
00559
00560
00561
00562
00563
00564
00565
00566 template<class A, class B>
00567 class assignment
00568 {
00569 protected:
00570 typedef char PathA;
00571 class Other {char unused[2];};
00572 static PathA route(A*);
00573 static Other route(...);
00574 static B* test();
00575
00576 public:
00577
00578
00579
00580 static A* safe(A* a)
00581 {
00582 return a;
00583 }
00584
00585
00586
00587
00588 static A* safe(...)
00589 {
00590 coh_throw_illegal_state("unsafe cast");
00591 return 0;
00592 }
00593
00594 public:
00595
00596
00597
00598 enum {allowed = (sizeof(route(test())) == sizeof(PathA))};
00599 };
00600
00601
00602
00603
00604 template<class A>
00605 class constness
00606 {
00607 public:
00608 enum {applied = assignment<A, const A>::allowed};
00609 };
00610 COH_CLOSE_NAMESPACE2
00611
00612
00613
00614 #endif // COH_COMPATIBILITY_HPP