00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 }
00044
00045
00046 template<class T> inline
00047 Ptr<T>::Ptr( ENull )
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 }
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())
00165 <<"}";
00166 return out;
00167 }
00168
00169
00170 #endif // TEUCHOS_PTR_HPP