Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47891-01

coherence/lang/compatibility.hpp

00001 /*
00002 * compatibility.hpp
00003 *
00004 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_COMPATIBILITY_HPP
00017 #define COH_COMPATIBILITY_HPP
00018 
00019 /// @cond EXCLUDE
00020 
00021 #include <typeinfo>
00022 
00023 // ----- identify operating system ------------------------------------------
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> // for _LP64 definition
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 // ----- identify compiler --------------------------------------------------
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 #   elif _MSC_VER == 1800
00103 #       define COH_CC msvc 2013
00104 #   else
00105 #       define COH_CC msvc
00106 #   endif
00107 #elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590
00108 #   define COH_CC_SUN // Forte Developer, or Oracle Solaris Studio
00109 #   if defined (STLPORT)
00110 #       define COH_CC sunpro stlport
00111 #   else
00112 #       define COH_CC sunpro
00113 #   endif
00114 #elif defined(__GNUG__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
00115 #   define COH_CC_GNU // GNU C++
00116 #   define COH_CC gcc
00117 #else
00118 #   error "Coherence for C++ does not support this compiler or compiler version."
00119 #endif
00120 
00121 
00122 // ----- disable select warnings --------------------------------------------
00123 
00124 /**
00125 * Macro for disabling select warnings on MSVC. The warnings are automatically
00126 * disabled upon opening a coherence namespace (using the COH_OPEN_NAMESPACE
00127 * macros), and re-enabled when the namespace is exited via
00128 * COH_CLOSE_NAMESPACE.
00129 */
00130 #if defined(COH_CC_MSVC)
00131     #define COH_PRAGMA_PUSH \
00132     __pragma(warning(push)) \
00133     /* Allow multiple interface inheritance (inheritance via dominance) */ \
00134     __pragma(warning(disable : 4250)) \
00135     /* Allow non-exported DLL templates */ \
00136     __pragma(warning(disable : 4251)) \
00137     /* Exported class inheritance from non-exported class, needed for specs */ \
00138     __pragma(warning(disable : 4275)) \
00139     /* TypedHandle/Holder: multiple copy constructors */ \
00140     __pragma(warning(disable : 4521)) \
00141     /* Member/WeakHandle: assignment operators for const/non-const type */ \
00142     __pragma(warning(disable : 4522)) \
00143     /* Lack of return statements are being promoted to errors, when control \
00144        path results in throw */ \
00145     __pragma(warning(disable : 4715; disable : 4716))
00146 
00147     #define COH_PRAGMA_POP __pragma(warning(pop))
00148 #else
00149     #define COH_PRAGMA_PUSH
00150     #define COH_PRAGMA_POP
00151 #endif
00152 
00153 /**
00154 * Macro for temporarily disabling above warnings for the duration of a
00155 * single statement.  This is only needed for code which is not enclosed in a
00156 * COH_OPEN/CLOSE_NAMESPACE block.
00157 */
00158 #define COH_NO_WARN(STMT) COH_PRAGMA_PUSH STMT COH_PRAGMA_POP
00159 
00160 /**
00161 * These macros are used to indicate that a function will not return normally.
00162 *
00163 * Usage example:
00164 * @code
00165 * COH_NO_RETURN_PRE void doSomething() COH_NO_RETURN_POST
00166 *     {
00167 *     COH_NO_RETURN_STMT(doSomething2());
00168 *     }
00169 * @endcode
00170 */
00171 #if defined(COH_CC_MSVC)
00172     #define COH_NO_RETURN_PRE __declspec(noreturn)
00173     #define COH_NO_RETURN_POST
00174     #define COH_NO_RETURN_STMT(expr) expr
00175 #elif defined(COH_CC_GNU)
00176     #define COH_NO_RETURN_PRE
00177     #define COH_NO_RETURN_POST __attribute__((noreturn))
00178     #define COH_NO_RETURN_STMT(expr) expr
00179 #elif defined(COH_CC_SUN)
00180     #define COH_NO_RETURN_PRE
00181     #define COH_NO_RETURN_POST
00182     #define COH_NO_RETURN_STMT(expr)\
00183         do { expr; throw std::exception(); } while (0)
00184 #else
00185     #define COH_NO_RETURN_PRE
00186     #define COH_NO_RETURN_POST
00187     #define COH_NO_RETURN_STMT(expr) expr
00188 #endif
00189 
00190 
00191 // ----- namespace macros ---------------------------------------------------
00192 
00193 /**
00194 * Define the existence of the coherence::lang namespace
00195 */
00196 namespace coherence { namespace lang {}}
00197 
00198 #define COH_OPEN_NAMESPACE(ns) namespace ns { \
00199     COH_PRAGMA_PUSH \
00200     using namespace coherence::lang;
00201 
00202 #define COH_INNER_NAMESPACE(ns) namespace ns {
00203 
00204 #define COH_OPEN_NAMESPACE2(ns1, ns2)\
00205     COH_OPEN_NAMESPACE (ns1) COH_INNER_NAMESPACE (ns2)
00206 
00207 #define COH_OPEN_NAMESPACE3(ns1, ns2, ns3)\
00208     COH_OPEN_NAMESPACE2 (ns1, ns2) COH_INNER_NAMESPACE (ns3)
00209 
00210 #define COH_OPEN_NAMESPACE4(ns1, ns2, ns3, ns4)\
00211     COH_OPEN_NAMESPACE3 (ns1, ns2, ns3) COH_INNER_NAMESPACE (ns4)
00212 
00213 #define COH_OPEN_NAMESPACE5(ns1, ns2, ns3, ns4, ns5)\
00214     COH_OPEN_NAMESPACE4 (ns1, ns2, ns3, ns4) COH_INNER_NAMESPACE (ns5)
00215 
00216 #define COH_OPEN_NAMESPACE6(ns1, ns2, ns3, ns4, ns5, ns6)\
00217     COH_OPEN_NAMESPACE5 (ns1, ns2, ns3, ns4, ns5) COH_INNER_NAMESPACE (ns6)
00218 
00219 #define COH_OPEN_NAMESPACE7(ns1, ns2, ns3, ns4, ns5, ns6, ns7)\
00220     COH_OPEN_NAMESPACE6 (ns1, ns2, ns3, ns4, ns5, ns6) COH_INNER_NAMESPACE (ns7)
00221 
00222 #define COH_CLOSE_NAMESPACE COH_PRAGMA_POP }
00223 
00224 #define COH_CLOSE_NAMESPACE2 COH_PRAGMA_POP } }
00225 
00226 #define COH_CLOSE_NAMESPACE3 COH_PRAGMA_POP } } }
00227 
00228 #define COH_CLOSE_NAMESPACE4 COH_PRAGMA_POP } } } }
00229 
00230 #define COH_CLOSE_NAMESPACE5 COH_PRAGMA_POP } } } } }
00231 
00232 #define COH_CLOSE_NAMESPACE6 COH_PRAGMA_POP } } } } } }
00233 
00234 #define COH_CLOSE_NAMESPACE7 COH_PRAGMA_POP } } } } } } }
00235 
00236 
00237 // ----- general utility macros ---------------------------------------------
00238 
00239 /**
00240 * This macro "mangles" the specified @a Name, producing an identifier which
00241 * is unique in the current file.
00242 *
00243 * Note. This implementation of COH_UNIQUE_IDENTIFIER (as well as macros that
00244 * use it) won't work in MSVC 6.0 when -ZI is on! See Q199057.
00245 *
00246 * @param Name the name to produce a new identifier on its basis
00247 */
00248 #define COH_JOIN(X, Y) COH_DO_JOIN(X, Y)
00249 #define COH_DO_JOIN(X, Y) COH_DO_JOIN2(X, Y)
00250 #define COH_DO_JOIN2(X, Y) X##Y
00251 #ifdef COH_CC_MSVC_NET // MSVC 2002 and later
00252 #   define COH_UNIQUE_IDENTIFIER(Name) COH_JOIN(Name, __COUNTER__)
00253 #else
00254 #   define COH_UNIQUE_IDENTIFIER(Name) COH_JOIN(Name, __LINE__)
00255 #endif
00256 
00257 /**
00258 * This macro will ensure initialization of function local statics at library
00259 * load time. This should be used to force the initialization of statics
00260 * in a thread safe way.  The general form is:
00261 *
00262 * SomeType::Handle staticAccessorFunction()
00263 *     {
00264 *     static FinalHandle<SomeType> hStatic = SomeType::create();
00265 *     return hStatic;
00266 *     }
00267 * COH_STATIC_INIT(staticAccessorFunction());
00268 *
00269 * @param FUNC  The static function and parameters to call that requires
00270 *             initialization.
00271 */
00272 #ifdef COH_EAGER_INIT
00273 #   define COH_STATIC_INIT_EX(N, FUNC) \
00274     static const bool COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_) = (FUNC, true)
00275 #else
00276 // some platforms (Windows) have serious restrictions about what can be safely
00277 // performed during static initialization and so this variant of initializer
00278 // records the initializers in the order they would be loaded to allow for
00279 // execution after the library has been loaded. The execution can be triggered
00280 // by running System::loadLibrary(NULL)
00281 #    define COH_STATIC_INIT_EX(N, FUNC) \
00282          static void COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_)() {FUNC;} \
00283          static coherence::lang::coh_initializer \
00284                  COH_UNIQUE_IDENTIFIER(coh_static_init_reg##N##_) \
00285          (&COH_UNIQUE_IDENTIFIER(coh_static_init_func##N##_))
00286 #endif
00287 
00288 #define COH_STATIC_INIT(FUNC) COH_STATIC_INIT_EX(0, FUNC)
00289 
00290 COH_OPEN_NAMESPACE2(coherence,lang)
00291     template <bool x> struct STATIC_ASSERTION_FAILURE;
00292     template<> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
00293 COH_CLOSE_NAMESPACE2
00294 
00295 /**
00296 * This macro generates a compile time error message if the integral constant
00297 * expression @a B is not true. In other words, it is the compile time
00298 * equivalent of the @c assert macro. Note that if the condition is true, then
00299 * the macro will generate neither code nor data - and the macro can also be
00300 * used at either namespace, class or function scope. When used in a template,
00301 * the static assertion will be evaluated at the time the template is
00302 * instantiated; this is particularly useful for validating template
00303 * parameters.
00304 *
00305 * #COH_STATIC_ASSERT can be used at any place where a declaration can be
00306 * placed, that is at class, function or namespace scope.
00307 *
00308 * @param B an integral constant expression to check its trueness during
00309 *          translation phase
00310 */
00311 #define COH_STATIC_ASSERT(B)                               \
00312     enum { COH_UNIQUE_IDENTIFIER(coh_static_assert_enum_) =\
00313         sizeof(coherence::lang::STATIC_ASSERTION_FAILURE<(bool)(B)>) }
00314 
00315 /**
00316 * DLL import/export macros.
00317 */
00318 #if defined(COH_CC_MSVC)
00319     #ifdef COH_BUILD
00320         #define COH_EXPORT  __declspec(dllexport)
00321     #else
00322         #define COH_EXPORT  __declspec(dllimport)
00323     #endif
00324     #define COH_EXPORT_SPEC  __declspec(dllexport)
00325     #define COH_EXPORT_SPEC_MEMBER(DECL)
00326 #else
00327     #define COH_EXPORT
00328     #define COH_EXPORT_SPEC
00329     #define COH_EXPORT_SPEC_MEMBER(DECL) DECL;
00330 #endif
00331 
00332 /**
00333 * This macro will strongly encourage/force inlining of a method.
00334 */
00335 #if defined(COH_CC_MSVC)
00336     #define COH_INLINE __forceinline
00337 #elif defined(COH_CC_GNU)
00338     #define COH_INLINE __attribute__((always_inline)) inline
00339 #else
00340     #define COH_INLINE inline
00341 #endif
00342 
00343 /**
00344 * This macro expands to the name and signature of the current function.
00345 */
00346 #if defined(__GNUC__)
00347     #define COH_CURRENT_FUNCTION __PRETTY_FUNCTION__
00348 #elif defined(__FUNCSIG__)
00349     #define COH_CURRENT_FUNCTION __FUNCSIG__
00350 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
00351     #define COH_CURRENT_FUNCTION __func__
00352 #else
00353     #define COH_CURRENT_FUNCTION "(unknown function)"
00354 #endif
00355 
00356 
00357 // ----- fixed size types ---------------------------------------------------
00358 
00359 // We need to include an std lib header here in order to detect which library
00360 // is in use (__GLIBC__ may not be defined without this including). Use
00361 // <utility> as it's about the smallest of the std lib headers.
00362 #include <utility>
00363 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 ||\
00364     defined(_POSIX_VERSION) && _POSIX_VERSION >= 200100 ||\
00365     defined(COH_OS_LINUX) &&\
00366         defined(__GLIBC__) &&\
00367         (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) &&\
00368         defined(__GNUC__) ||\
00369     defined(COH_OS_DARWIN) && __MACH__ && !defined(_MSL_USING_MSL_C)
00370 #       define COH_HAS_STDINT_H
00371 #endif
00372 
00373 #if defined(__GCCXML__) ||\
00374     defined(__GNUC__) ||\
00375     defined(_MSC_VER) && _MSC_VER >= 1310 && defined(_MSC_EXTENSIONS)
00376 #       define COH_HAS_LONG_LONG
00377 #endif
00378 
00379 #if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) &&\
00380         !defined(_GLIBCPP_USE_LONG_LONG) &&          \
00381         !defined(_GLIBCXX_USE_LONG_LONG) &&          \
00382         defined(COH_HAS_LONG_LONG)
00383     // Coming here indicates that the GNU compiler supports long long type,
00384     // but the GNU C++ runtime library does not. Particularly, no global
00385     // operator<<(std::ostream&, long long) implementation is provided. Let us
00386     // provide it, at least with minimum incomplete functionality.
00387 #   include <ostream>
00388     namespace std
00389         {
00390         template<class E, class T>
00391         inline basic_ostream<E, T>& operator<<
00392                 (basic_ostream<E, T>& out, long long l)
00393             {
00394             return out << static_cast<long>(l);
00395             }
00396         template<class E, class T>
00397         inline basic_ostream<E, T>& operator<<
00398                 (basic_ostream<E, T>& out, unsigned long long l)
00399             {
00400             return out << static_cast<unsigned long>(l);
00401             }
00402         }
00403 #   undef COH_HAS_LONG_LONG
00404 #endif
00405 
00406 #if !defined(COH_HAS_LONG_LONG) && !defined(COH_CC_MSVC)
00407 #   include <limits.h>
00408 #   if defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) ||\
00409             defined(ULONGLONG_MAX)
00410 #       define COH_HAS_LONG_LONG
00411 #   endif
00412 #endif
00413 
00414 #if defined(_MSC_VER) && _MSC_VER >= 1200
00415 #       define COH_HAS_MS_INT64
00416 #endif
00417 
00418 /**
00419 * Fixed width primitive types.
00420 */
00421 #if defined(COH_HAS_STDINT_H)
00422 #   include <stdint.h>
00423 #elif defined(COH_CC_SUN)
00424 #   include <inttypes.h>
00425 #else
00426 //  This platform does not support the C99 stdint.h types. This code block
00427 //  defines them in the global namespace, alternatively you may define
00428 //  COH_NAMESPACED_FIXED_INTS, in which case these definitions will be within
00429 //  the coherence::lang namespace.
00430 #   include <climits>
00431 #   ifdef COH_NAMESPACED_FIXED_INTS
00432       COH_OPEN_NAMESPACE2(coherence,lang)
00433 #   endif
00434     COH_STATIC_ASSERT(UCHAR_MAX == 0xFF);
00435     typedef signed char   int8_t;
00436     typedef unsigned char uint8_t;
00437     COH_STATIC_ASSERT(USHRT_MAX == 0xFFFF);
00438     typedef short          int16_t;
00439     typedef unsigned short uint16_t;
00440 #   if UINT_MAX == 0xFFFFFFFF
00441         typedef int          int32_t;
00442         typedef unsigned int uint32_t;
00443 #   elif ULONG_MAX == 0xFFFFFFFF
00444         typedef long          int32_t;
00445         typedef unsigned long uint32_t;
00446 #   else
00447 #       error int size not correct
00448 #   endif
00449 #   if defined(COH_HAS_LONG_LONG) &&\
00450         !defined(COH_CC_MSVC) &&\
00451         (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
00452         (defined(ULLONG_MAX) ||\
00453             defined(ULONG_LONG_MAX) ||\
00454             defined(ULONGLONG_MAX))
00455 #               if defined(ULLONG_MAX)
00456                     COH_STATIC_ASSERT(ULLONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00457 #               elif defined(ULONG_LONG_MAX)
00458                     COH_STATIC_ASSERT
00459                         (ULONG_LONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00460 #               elif defined(ULONGLONG_MAX)
00461                     COH_STATIC_ASSERT
00462                         (ULONGLONG_MAX == 0xFFFFFFFFFFFFFFFFULL));
00463 #               else
00464 #                   error long long size not correct
00465 #               endif
00466                 typedef long long          int64_t;
00467                 typedef unsigned long long uint64_t;
00468 #   elif ULONG_MAX != 0xFFFFFFFF
00469         COH_STATIC_ASSERT(ULONG_MAX == 0xFFFFFFFFFFFFFFFFULL);
00470         typedef long          int64_t;
00471         typedef unsigned long uint64_t;
00472 #   elif defined(__GNUC__) && defined(COH_HAS_LONG_LONG)
00473         __extension__ typedef long long          int64_t;
00474         __extension__ typedef unsigned long long uint64_t;
00475 #   elif defined(COH_HAS_MS_INT64)
00476         typedef __int64          int64_t;
00477         typedef unsigned __int64 uint64_t;
00478 #   else
00479 #       error no 64-bit integer support
00480 #   endif
00481 #   ifdef COH_NAMESPACED_FIXED_INTS
00482       COH_CLOSE_NAMESPACE2
00483 #   endif
00484 #endif
00485 
00486 /**
00487 * Non-standard primitive type definitions.
00488 */
00489 COH_OPEN_NAMESPACE2(coherence,lang)
00490     typedef unsigned char octet_t;
00491     typedef uint16_t      char16_t;
00492     typedef uint32_t      size32_t;
00493     typedef uint64_t      size64_t;
00494     typedef float         float32_t; COH_STATIC_ASSERT(sizeof(float32_t) >= sizeof(int32_t));
00495     typedef double        float64_t; COH_STATIC_ASSERT(sizeof(float64_t) >= sizeof(int64_t));
00496 COH_CLOSE_NAMESPACE2
00497 
00498 /**
00499 * Produce a 64b value from two 32b parts.
00500 *
00501 * This is a bit-wise construction, and the supplied values should be the
00502 * bitwise unsigned representations.  For example:
00503 * COH_INT64(0x7FFFFFFFU, 0xFFFFFFFFU) == 0x7FFFFFFFFFFFFFFFLL
00504 */
00505 #define COH_INT64(HIGH, LOW) int64_t(uint64_t(HIGH) << 32 | uint64_t(LOW))
00506 
00507 // macros for turning compiler supplied define into a string
00508 #define COH_SYMB_STRING(SYMB) #SYMB
00509 #define COH_SYMB_TO_STRING(SYMB) COH_SYMB_STRING(SYMB)
00510 
00511 
00512 // ----- helpers ------------------------------------------------------------
00513 
00514 #include <typeinfo>
00515 COH_OPEN_NAMESPACE2(coherence,lang)
00516     class Class;
00517 
00518     typedef void (*coh_static_initializer)();
00519 
00520     /**
00521     * Register an initialization function with the runtime.
00522     */
00523     extern COH_EXPORT void coh_register_initializer(
00524             coh_static_initializer pInit, bool fAdd);
00525 
00526     /**
00527      * Helper class for registering and unregistering static initializers.
00528      */
00529     class coh_initializer
00530         {
00531         public:
00532 
00533         coh_initializer(coh_static_initializer pInit)
00534             : m_pInit(pInit)
00535             {
00536             coh_register_initializer(pInit, true);
00537             }
00538 
00539         ~coh_initializer()
00540             {
00541             coh_register_initializer(m_pInit, false);
00542             }
00543 
00544         private:
00545         coh_static_initializer m_pInit;
00546         };
00547 
00548     /**
00549     * Helper functions for throwing exceptions.
00550     */
00551     extern COH_EXPORT void coh_throw_npe(const std::type_info&);
00552     extern COH_EXPORT void coh_throw_class_cast(const std::type_info&,
00553             const std::type_info&);
00554     extern COH_EXPORT void coh_throw_const_cast(const std::type_info&,
00555             const std::type_info&);
00556     extern COH_EXPORT void coh_throw_illegal_state(const char* achMsg);
00557     extern COH_EXPORT void coh_throw_illegal_argument(const char* achMsg);
00558     extern COH_EXPORT void coh_throw_unsupported_operation(const char* achMsg);
00559     extern COH_EXPORT const Class* coh_loadClassByType(const std::type_info& ti);
00560 
00561     /**
00562     * Helper class used to test for type assignment compatibility at
00563     * compile time.
00564     *
00565     * This implementation is based on the Conversion example from
00566     * Andrei Alexandrescu's Modern C++ Design.
00567     */
00568     template<class A, class B>
00569     class assignment
00570         {
00571         protected:
00572             typedef char  PathA;
00573             class   Other {char unused[2];}; // sizeof(Other) != sizeof(PathA)
00574             static  PathA route(A*); // PathA taken only for compatible types
00575             static  Other route(...); // incompatible types go this route
00576             static  B*    test(); // "generate" a test object
00577 
00578         public:
00579             /**
00580             * Convert a derived A to an A.
00581             */
00582             static A* safe(A* a)
00583                 {
00584                 return a;
00585                 }
00586 
00587             /**
00588             * Dummy conversion (should never be called)
00589             */
00590             static A* safe(...)
00591                 {
00592                 coh_throw_illegal_state("unsafe cast");
00593                 return 0;
00594                 }
00595 
00596         public:
00597             /**
00598             * True iff A = B is allowed.
00599             */
00600             enum {allowed = (sizeof(route(test())) == sizeof(PathA))};
00601         };
00602 
00603     /**
00604     * Helper class used to test if a type has been declared as const.
00605     */
00606     template<class A>
00607     class constness
00608         {
00609         public:
00610             enum {applied = assignment<A, const A>::allowed};
00611         };
00612 /**
00613  * Coherence Class and Interface ID helpers.
00614  */
00615 #if defined(COH_CC_MSVC)
00616     // MSVC utilizes identical code folding ICF, which makes the alternate
00617     // very cheap form of id generation unusable and effectively assigns
00618     // all classes the same id, thus on MSVC we fallback on standard and
00619     // slower typeid
00620 
00621     /**
00622      * Coherence class id type.
00623      */
00624     typedef const std::type_info& coh_class_id;
00625 
00626     /**
00627      * Return the class id for a given managed class.
00628      */
00629     #define COH_CLASS_ID(CLASS) CLASS::_classId()
00630 
00631     /**
00632      * @internal
00633      *
00634      * Hook for COH_CLASS_ID macro, not for direct use
00635      */
00636     #define COH_GENERATE_CLASS_ID(T) \
00637         static coh_class_id _classId() \
00638             { \
00639             return typeid(T); \
00640             }
00641 #else
00642     // For most compilers we can use the address of a class specific static
00643     // function as a unique class identifier. This is cheaper then using
00644     // the standard typeid operator, which on some platforms adds contention
00645 
00646     /**
00647      * Coherence class id type.
00648      */
00649     typedef void (*coh_class_id)();
00650 
00651     /**
00652      * Return the class id for a given managed class.
00653      */
00654     #define COH_CLASS_ID(CLASS) &CLASS::_classId
00655 
00656     /**
00657      * @internal
00658      *
00659      * Hook for COH_CLASS_ID macro, not for direct use
00660      */
00661     #define COH_GENERATE_CLASS_ID(T) static void _classId() {}
00662 #endif
00663 
00664 COH_CLOSE_NAMESPACE2
00665 
00666 /// @endcond
00667 
00668 #endif // COH_COMPATIBILITY_HPP
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.