Teuchos_Ptr.hpp

Go to the documentation of this file.
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 void Ptr<T>::debug_assert_valid_ptr() const
00130 {
00131 #ifdef TEUCHOS_DEBUG
00132   rcp_.access_private_node().assert_valid_ptr(*this);
00133 #endif
00134 }
00135 
00136 
00137 #ifdef TEUCHOS_DEBUG
00138 
00139 
00140 template<class T> inline
00141 Ptr<T>::Ptr( const RCP<T> &p )
00142   : ptr_(p.getRawPtr()), rcp_(p)
00143 {}
00144 
00145 
00146 #endif // TEUCHOS_DEBUG
00147 
00148 
00149 } // namespace Teuchos
00150 
00151 
00152 template<class T>
00153 std::ostream& Teuchos::operator<<( std::ostream& out, const Ptr<T>& p )
00154 {
00155   out
00156     << TypeNameTraits<RCP<T> >::name() << "{"
00157     << "ptr="<<(const void*)(p.get()) // I can't find any alternative to this C cast :-(
00158     <<"}";
00159   return out;
00160 }
00161 
00162 
00163 #endif // TEUCHOS_PTR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:14:00 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1