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

00001 #ifndef _GEMFIRE_SPEHELPER_HPP_
00002 #define _GEMFIRE_SPEHELPER_HPP_
00003 
00004 /*=========================================================================
00005  * Copyright (c) 2004-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 
00012 #include "gfcpp_globals.hpp"
00013 #include "TypeHelper.hpp"
00014 #include <typeinfo>
00015 
00016 namespace gemfire {
00017 
00018   class SharedBase;
00019 
00022 class CPPCACHE_EXPORT SPEHelper
00023 {
00024   public:
00025 
00026   static void throwNullPointerException( const char* ename );
00027 
00028   static void throwClassCastException( const char* msg,
00029       const char* fromType, const char* toType );
00030 };
00031 
00032 /* Helper function template for type conversion.
00033  */
00034 template< class Target, class Src > Target* getTargetHelper( Src* ptr, gemfire::TypeHelper::yes_type yes )
00035 {
00036   return ptr;
00037 }
00038 
00039 /* Helper function template for type conversion.
00040  */
00041 template< class Target, class Src > Target* getTargetHelper( Src* ptr, gemfire::TypeHelper::no_type no )
00042 {
00043   Target* tptr = dynamic_cast< Target* >( ptr );
00044   if ( tptr ) {
00045     return tptr;
00046   }
00047   else {
00048     SPEHelper::throwClassCastException( "getTargetHelper: cast failed",
00049             typeid( ptr ).name( ), typeid( tptr ).name( ) );
00050     return NULL;
00051   }
00052 }
00053 
00054 /* Helper function template for type conversion.
00055  */
00056 template< class Target, class Src > Target* getTarget( Src* ptr )
00057 {
00058   return getTargetHelper< Target >( ptr, GF_SRC_IS_TARGET_TYPE( Target, Src ) );
00059 }
00060 
00061 /* Helper function template for type conversion.
00062  */
00063 template< class Src > SharedBase* getSB( Src* ptr )
00064 {
00065   return getTarget< SharedBase >( ptr );
00066 }
00067 }
00068 
00069 #endif
00070 

GemFire C++ Cache API Documentation