/export/rook2/users/build/gfcppsancout64/product/include/gfcpp/TypeHelper.hpp

00001 #ifndef _GEMFIRE_TYPEHELPER_HPP_
00002 #define _GEMFIRE_TYPEHELPER_HPP_
00003 
00004 /*=========================================================================
00005  * (c) Copyright 2002-2007, GemStone Systems, Inc. All Rights Reserved.
00006  * 1260 NW Waterhouse Ave., Suite 200,  Beaverton, OR 97006
00007  *=========================================================================
00008  */
00009 
00014 #include "gfcpp_globals.hpp"
00015 
00016 
00017 namespace gemfire
00018 {
00019   // Forward declaration of SharedPtr<T>
00020   template<typename Target> class SharedPtr;
00021 
00022   // Forward declaration of SharedArrayPtr<T, ID>
00023   template<typename Target, int8_t TYPEID> class SharedArrayPtr;
00024 
00025   // Forward declaration of CacheableArrayType<T, ID>
00026   template<typename Target, int8_t TYPEID> class CacheableArrayType;
00027 
00033   namespace TypeHelper
00034   {
00035     typedef uint8_t yes_type;
00036     typedef uint32_t no_type;
00037 
00038     template <typename TBase, typename TDerived> struct BDHelper
00039     {
00040       template <typename T>
00041         static yes_type check_sig( TDerived const volatile *, T );
00042       static no_type check_sig( TBase const volatile *, int );
00043     };
00044 
00052     template <typename TBase, typename TDerived> struct SuperSubclass
00053     {
00054       private:
00055 
00056         struct Host
00057         {
00058           operator TBase const volatile* ( ) const;
00059           operator TDerived const volatile* ( );
00060         };
00061 
00062 
00063       public:
00064 
00065         static const bool result = sizeof( BDHelper<TBase, TDerived>::
00066             check_sig( Host( ), 0 ) ) == sizeof( yes_type );
00067     };
00068 
00073     template <typename TBase> struct SuperSubclass<TBase, TBase>
00074     {
00075       static const bool result = true;
00076     };
00077 
00082     template <bool getType=true> struct YesNoType
00083     {
00084       static const yes_type value = 0;
00085     };
00086 
00090     template <> struct YesNoType<false>
00091     {
00092       static const no_type value = 0;
00093     };
00094 
00096     template <class T> struct UnwrapSharedPtr
00097     {
00098     };
00099 
00101     template <class T> struct UnwrapSharedPtr< SharedPtr<T> >
00102     {
00103       typedef T type;
00104     };
00105 
00107     template <class T, int8_t ID> struct UnwrapSharedPtr< SharedArrayPtr<T, ID> >
00108     {
00109       typedef CacheableArrayType<T, ID> type;
00110     };
00111 
00112   }
00113 }
00114 
00116 #define GF_UNWRAP_SP( T ) typename gemfire::TypeHelper::UnwrapSharedPtr<T>::type
00117 
00122 #define GF_TYPE_IS_SERIALIZABLE( T ) \
00123   gemfire::TypeHelper::SuperSubclass<gemfire::Serializable, T>::result
00124 
00130 #define GF_TYPE_IS_SERIALIZABLE_TYPE( T ) \
00131   gemfire::TypeHelper::YesNoType<GF_TYPE_IS_SERIALIZABLE( T )>::value
00132 
00133 #define GF_SRC_IS_TARGET_TYPE( TARGET, SRC ) \
00134   gemfire::TypeHelper::YesNoType< gemfire::TypeHelper::SuperSubclass< TARGET, SRC >::result >::value
00135 
00136 
00137 #endif // _GEMFIRE_TYPEHELPER_HPP_

GemFire C++ Cache API Documentation