00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_CWeakPtr_h_ 00017 #define polybori_CWeakPtr_h_ 00018 00019 // include basic definitions 00020 #include <polybori/pbori_defs.h> 00021 #include "CWeakPtrFacade.h" 00022 00023 BEGIN_NAMESPACE_PBORI 00024 00030 template <class ValueType> 00031 class CWeakPtr { 00032 00033 typedef CWeakPtr self; 00034 00035 public: 00036 typedef ValueType value_type; 00037 00038 typedef value_type* data_type; 00039 typedef boost::shared_ptr<data_type> ptr_type; 00040 00041 00043 explicit CWeakPtr(const CWeakPtrFacade<ValueType>& val): 00044 m_data(val.m_data) { PBORI_ASSERT(m_data);} 00045 00047 CWeakPtr(const self& rhs): m_data(rhs.m_data) {} 00048 00050 ~CWeakPtr() {} 00051 00053 const value_type& operator*() const { 00054 return *(operator->()); 00055 } 00056 00058 value_type* operator->() const { 00059 if (!*m_data) 00060 throw std::runtime_error("Outdated weak pointer dereferenced."); 00061 00062 return (*m_data); 00063 } 00065 operator bool() const { return *m_data; } 00066 00067 private: 00068 ptr_type m_data; 00069 }; 00070 00071 END_NAMESPACE_PBORI 00072 00073 #endif /* polybori_CWeakPtr_h_ */