00001 /* @HEADER@ */ 00002 // 00003 /* @HEADER@ */ 00004 00005 #ifndef PLAYA_HANDLEABLE_HPP 00006 #define PLAYA_HANDLEABLE_HPP 00007 00008 #include "PlayaDefs.hpp" 00009 #include "Teuchos_RefCountPtr.hpp" 00010 00011 #define GET_RCP(Base) \ 00012 /** Handleable<##Base> interface */ \ 00013 virtual Teuchos::RCP<Base > getRcp() {return rcp(this);} 00014 00015 namespace Playa 00016 { 00017 using namespace Teuchos; 00018 00019 /** 00020 * Class Handleable provides an abstract interface for polymorphic 00021 * conversion from raw pointers to smart pointers. Recall from the 00022 * Teuchos RefCountPtr documentation that one should never create 00023 * directly a smart pointer from a raw pointer; rather, smart pointers 00024 * should be created through a call to rcp(). The type of the argument 00025 * to rcp() must be known at compile time. This makes the syntax 00026 * \code 00027 * Handle h = new Derived(); 00028 * \endcode 00029 * impossible with the straightforward implementation in which Handle takes 00030 * a raw pointer to a Base. In order to preserve this clean syntax, we 00031 * require any handles supporting this syntax to take a raw 00032 * pointer to a Handleable<Base>, where Handleable<Base> provides a 00033 * getRcp() method which returns the result of a call to rcp() on this. 00034 */ 00035 template <class Base> 00036 class Handleable 00037 { 00038 public: 00039 /** Virtual dtor */ 00040 virtual ~Handleable(){;} 00041 00042 /** Return a safely-created RefCountPtr to the base type */ 00043 virtual RCP<Base> getRcp() = 0 ; 00044 00045 }; 00046 00047 } 00048 00049 00050 00051 00052 #endif