build-artifacts/win/product/include/gfcpp/TypeHelper.hpp

00001 #ifndef _GEMFIRE_TYPEHELPER_HPP_
00002 #define _GEMFIRE_TYPEHELPER_HPP_
00003 
00004 /*=========================================================================
00005  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
00006  * This product is protected by U.S. and international copyright
00007  * and intellectual property laws. Pivotal products are covered by
00008  * more patents listed at http://www.pivotal.io/patents.
00009  *=========================================================================
00010  */
00011 
00016 #include "gfcpp_globals.hpp"
00017 
00018 
00019 namespace gemfire
00020 {
00021   // Forward declaration of SharedPtr<T>
00022   template<typename Target> class SharedPtr;
00023 
00024   // Forward declaration of SharedArrayPtr<T, ID>
00025   template<typename Target, int8_t TYPEID> class SharedArrayPtr;
00026 
00027   // Forward declaration of CacheableArrayType<T, ID>
00028   template<typename Target, int8_t TYPEID> class CacheableArrayType;
00029 
00035   namespace TypeHelper
00036   {
00037     typedef uint8_t yes_type;
00038     typedef uint32_t no_type;
00039 
00040     template <typename TBase, typename TDerived> struct BDHelper
00041     {
00042       template <typename T>
00043         static yes_type check_sig( TDerived const volatile *, T );
00044       static no_type check_sig( TBase const volatile *, int );
00045     };
00046 
00054     template <typename TBase, typename TDerived> struct SuperSubclass
00055     {
00056       private:
00057 
00058         struct Host
00059         {
00060           operator TBase const volatile* ( ) const;
00061           operator TDerived const volatile* ( );
00062         };
00063 
00064 
00065       public:
00066 
00067         static const bool result = sizeof( BDHelper<TBase, TDerived>::
00068             check_sig( Host( ), 0 ) ) == sizeof( yes_type );
00069     };
00070 
00075     template <typename TBase> struct SuperSubclass<TBase, TBase>
00076     {
00077       static const bool result = true;
00078     };
00079 
00084     template <bool getType=true> struct YesNoType
00085     {
00086       static const yes_type value = 0;
00087     };
00088 
00092     template <> struct YesNoType<false>
00093     {
00094       static const no_type value = 0;
00095     };
00096 
00098     template <class T> struct UnwrapSharedPtr
00099     {
00100     };
00101 
00103     template <class T> struct UnwrapSharedPtr< SharedPtr<T> >
00104     {
00105       typedef T type;
00106     };
00107 
00109     template <class T, int8_t ID> struct UnwrapSharedPtr< SharedArrayPtr<T, ID> >
00110     {
00111       typedef CacheableArrayType<T, ID> type;
00112     };
00113 
00114   }
00115 }
00116 
00118 #define GF_UNWRAP_SP( T ) typename gemfire::TypeHelper::UnwrapSharedPtr<T>::type
00119 
00124 #define GF_TYPE_IS_SERIALIZABLE( T ) \
00125   gemfire::TypeHelper::SuperSubclass<gemfire::Serializable, T>::result
00126 
00132 #define GF_TYPE_IS_SERIALIZABLE_TYPE( T ) \
00133   gemfire::TypeHelper::YesNoType<GF_TYPE_IS_SERIALIZABLE( T )>::value
00134 
00135 #define GF_SRC_IS_TARGET_TYPE( TARGET, SRC ) \
00136   gemfire::TypeHelper::YesNoType< gemfire::TypeHelper::SuperSubclass< TARGET, SRC >::result >::value
00137 
00138 
00139 #endif // _GEMFIRE_TYPEHELPER_HPP_

GemFire C++ Cache API Documentation