|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 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 00030 #ifndef TEUCHOS_PTR_HPP 00031 #define TEUCHOS_PTR_HPP 00032 00033 00034 #include "Teuchos_PtrDecl.hpp" 00035 #include "Teuchos_RCP.hpp" 00036 00037 00038 namespace Teuchos { 00039 00040 00041 namespace PtrPrivateUtilityPack { 00042 void throw_null( const std::string &type_name ); 00043 } // namespace PtrPrivateUtilityPack 00044 00045 00046 template<class T> inline 00047 Ptr<T>::Ptr( ENull /*null_in*/ ) 00048 : ptr_(0) 00049 {} 00050 00051 00052 template<class T> inline 00053 Ptr<T>::Ptr( T *ptr_in ) 00054 : ptr_(ptr_in) 00055 {} 00056 00057 00058 template<class T> inline 00059 Ptr<T>::Ptr(const Ptr<T>& ptr_in) 00060 :ptr_(ptr_in.ptr_) 00061 {} 00062 00063 00064 template<class T> 00065 template<class T2> inline 00066 Ptr<T>::Ptr(const Ptr<T2>& ptr_in) 00067 :ptr_(ptr_in.get()) 00068 {} 00069 00070 00071 template<class T> inline 00072 Ptr<T>& Ptr<T>::operator=(const Ptr<T>& ptr_in) 00073 { 00074 ptr_ = ptr_in.get(); 00075 return *this; 00076 } 00077 00078 00079 template<class T> inline 00080 T* Ptr<T>::operator->() const 00081 { 00082 debug_assert_not_null(); 00083 debug_assert_valid_ptr(); 00084 return ptr_; 00085 } 00086 00087 00088 template<class T> inline 00089 T& Ptr<T>::operator*() const 00090 { 00091 debug_assert_not_null(); 00092 debug_assert_valid_ptr(); 00093 return *ptr_; 00094 } 00095 00096 00097 template<class T> inline 00098 T* Ptr<T>::get() const 00099 { 00100 debug_assert_valid_ptr(); 00101 return ptr_; 00102 } 00103 00104 00105 template<class T> inline 00106 T* Ptr<T>::getRawPtr() const 00107 { 00108 return get(); 00109 } 00110 00111 00112 template<class T> inline 00113 const Ptr<T>& Ptr<T>::assert_not_null() const 00114 { 00115 if(!ptr_) 00116 PtrPrivateUtilityPack::throw_null(TypeNameTraits<T>::name()); 00117 return *this; 00118 } 00119 00120 00121 template<class T> inline 00122 const Ptr<T> Ptr<T>::ptr() const 00123 { 00124 return *this; 00125 } 00126 00127 00128 template<class T> inline 00129 Ptr<const T> Ptr<T>::getConst() const 00130 { 00131 return ptr_implicit_cast<const T>(*this); 00132 } 00133 00134 00135 template<class T> inline 00136 void Ptr<T>::debug_assert_valid_ptr() const 00137 { 00138 #ifdef TEUCHOS_DEBUG 00139 rcp_.access_private_node().assert_valid_ptr(*this); 00140 #endif 00141 } 00142 00143 00144 #ifdef TEUCHOS_DEBUG 00145 00146 00147 template<class T> inline 00148 Ptr<T>::Ptr( const RCP<T> &p ) 00149 : ptr_(p.getRawPtr()), rcp_(p) 00150 {} 00151 00152 00153 #endif // TEUCHOS_DEBUG 00154 00155 00156 } // namespace Teuchos 00157 00158 00159 template<class T> 00160 std::ostream& Teuchos::operator<<( std::ostream& out, const Ptr<T>& p ) 00161 { 00162 out 00163 << TypeNameTraits<RCP<T> >::name() << "{" 00164 << "ptr="<<(const void*)(p.get()) // I can't find any alternative to this C cast :-( 00165 <<"}"; 00166 return out; 00167 } 00168 00169 00170 #endif // TEUCHOS_PTR_HPP
1.7.4