00001 /* @HEADER@ */ 00002 /* *********************************************************************** 00003 // 00004 // TSFExtended: Trilinos Solver Framework Extended 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // **********************************************************************/ 00027 /* @HEADER@ */ 00028 00029 #ifndef SUNDANCE_HANDLEABLE_HPP 00030 #define SUNDANCE_HANDLEABLE_HPP 00031 00032 #include "SundanceDefs.hpp" 00033 #include "Teuchos_RefCountPtr.hpp" 00034 00035 #define GET_RCP(Base) \ 00036 /** Handleable<##Base> interface */ \ 00037 virtual Teuchos::RCP<Base > getRcp() {return rcp(this);} 00038 00039 namespace Sundance 00040 { 00041 using namespace Teuchos; 00042 00043 /** 00044 * Class Handleable provides an abstract interface for polymorphic 00045 * conversion from raw pointers to smart pointers. Recall from the 00046 * Teuchos RefCountPtr documentation that one should never create 00047 * directly a smart pointer from a raw pointer; rather, smart pointers 00048 * should be created through a call to rcp(). The type of the argument 00049 * to rcp() must be known at compile time. This makes the syntax 00050 * \code 00051 * Handle h = new Derived(); 00052 * \endcode 00053 * impossible with the straightforward implementation in which Handle takes 00054 * a raw pointer to a Base. In order to preserve this clean syntax, we 00055 * require any handles supporting this syntax to take a raw 00056 * pointer to a Handleable<Base>, where Handleable<Base> provides a 00057 * getRcp() method which returns the result of a call to rcp() on this. 00058 */ 00059 template <class Base> 00060 class Handleable 00061 { 00062 public: 00063 /** Virtual dtor */ 00064 virtual ~Handleable(){;} 00065 00066 /** Return a safely-created RefCountPtr to the base type */ 00067 virtual RCP<Base> getRcp() = 0 ; 00068 00069 }; 00070 00071 } 00072 00073 00074 00075 00076 #endif