/export/loot1/users/build/gfcppsancout/product/include/gfcpp/SharedPtrHelper.hpp

00001 #ifndef _GEMFIRE_SPEHELPER_HPP_
00002 #define _GEMFIRE_SPEHELPER_HPP_
00003 
00004 /*=========================================================================
00005  * (c) Copyright 2004-2007, GemStone Systems, Inc. All Rights Reserved.
00006  * 1260 NW Waterhouse Ave Suite 200, Beaverton OR 97006.
00007  *=========================================================================
00008  */
00009 
00010 #include "gfcpp_globals.hpp"
00011 #include "TypeHelper.hpp"
00012 #include <typeinfo>
00013 
00014 namespace gemfire {
00015 
00016   class SharedBase;
00017 
00020 class CPPCACHE_EXPORT SPEHelper
00021 {
00022   public:
00023 
00024   static void throwNullPointerException( const char* ename );
00025 
00026   static void throwClassCastException( const char* msg,
00027       const char* fromType, const char* toType );
00028 };
00029 
00030 /* Helper function template for type conversion.
00031  */
00032 template< class Target, class Src > Target* getTargetHelper( Src* ptr, gemfire::TypeHelper::yes_type yes )
00033 {
00034   return ptr;
00035 }
00036 
00037 /* Helper function template for type conversion.
00038  */
00039 template< class Target, class Src > Target* getTargetHelper( Src* ptr, gemfire::TypeHelper::no_type no )
00040 {
00041   Target* tptr = dynamic_cast< Target* >( ptr );
00042   if ( tptr ) {
00043     return tptr;
00044   }
00045   else {
00046     SPEHelper::throwClassCastException( "getTargetHelper: cast failed",
00047             typeid( ptr ).name( ), typeid( tptr ).name( ) );
00048     return NULL;
00049   }
00050 }
00051 
00052 /* Helper function template for type conversion.
00053  */
00054 template< class Target, class Src > Target* getTarget( Src* ptr )
00055 {
00056   return getTargetHelper< Target >( ptr, GF_SRC_IS_TARGET_TYPE( Target, Src ) );
00057 }
00058 
00059 /* Helper function template for type conversion.
00060  */
00061 template< class Src > SharedBase* getSB( Src* ptr )
00062 {
00063   return getTarget< SharedBase >( ptr );
00064 }
00065 }
00066 
00067 #endif
00068 

GemFire C++ Cache API Documentation