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 #ifndef TEUCHOS_HANDLE_HPP
00030 #define TEUCHOS_HANDLE_HPP
00031
00032 #include "Teuchos_ConfigDefs.hpp"
00033 #include "Teuchos_RefCountPtr.hpp"
00034 #include "Teuchos_Describable.hpp"
00035 #include "Teuchos_Handleable.hpp"
00036
00037 namespace Teuchos
00038 {
00039
00065 template <typename PointerType>
00066 class ConstHandle : public virtual Describable
00067 {
00068 public:
00070 ConstHandle(const RefCountPtr<const PointerType>& ptr) : ptr_(ptr) {;}
00073 explicit ConstHandle(const ConstHandleable<PointerType>* ptr) : ptr_(ptr->getConstRcp()) {;}
00075 const RefCountPtr<const PointerType>& constPtr() const {return ptr_;}
00077 const PointerType * const rawPtr() {return this->constPtr().get();}
00078 protected:
00080 explicit ConstHandle() : ptr_() {;}
00085 void setRcp(const RefCountPtr<PointerType>& ptr)
00086 {ptr_=rcp_const_cast<const PointerType>(ptr);}
00091 RefCountPtr<PointerType> nonConstPtr() const
00092 {return rcp_const_cast<PointerType>(ptr_);}
00093 private:
00095 RefCountPtr<const PointerType> ptr_;
00096 };
00097
00121 template <typename PointerType>
00122 class Handle : public virtual ConstHandle<PointerType>
00123 {
00124 public:
00126 Handle()
00127 : ConstHandle<PointerType>() {}
00129 Handle(const RefCountPtr<PointerType>& smartPtr)
00130 : ConstHandle<PointerType>()
00131 {
00132
00133 setRcp(smartPtr);
00134 }
00140 explicit Handle(Handleable<PointerType>* rawPtr)
00141 : ConstHandle<PointerType>()
00142 {
00143
00144 setRcp(rawPtr->getRcp());
00145 }
00148 RefCountPtr<PointerType> ptr() const {return this->nonConstPtr();}
00150 PointerType* rawPtr() const {return this->nonConstPtr().get();}
00151 };
00152
00153 }
00154
00166 #define TEUCHOS_HANDLE_CTORS(handle, contents) \
00167 handle() : Teuchos::Handle<contents >() {;} \
00168 handle(Teuchos::Handleable<contents >* rawPtr) : Teuchos::Handle<contents >(rawPtr) {;} \
00169 handle(const Teuchos::RefCountPtr<contents >& smartPtr) : Teuchos::Handle<contents >(smartPtr){;}
00170
00182 #define TEUCHOS_CONST_HANDLE_CTORS(handle, contents) \
00183 handle() : Teuchos::ConstHandle<contents >() {;} \
00184 handle(const Teuchos::ConstHandleable<contents >* rawPtr) : Teuchos::ConstHandle<contents >(rawPtr) {;} \
00185 handle(const Teuchos::RefCountPtr<const contents >& smartPtr) : Teuchos::ConstHandle<contents >(smartPtr){;}
00186
00187 #endif // TEUCHOS_CONSTHANDLE_HPP