PolyBoRi
CWeakPtr.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_CWeakPtr_h_
17 #define polybori_CWeakPtr_h_
18 
19 // include basic definitions
20 #include <polybori/pbori_defs.h>
21 #include "CWeakPtrFacade.h"
22 
24 
30 template <class ValueType>
31 class CWeakPtr {
32 
33  typedef CWeakPtr self;
34 
35 public:
36  typedef ValueType value_type;
37 
39  typedef boost::shared_ptr<data_type> ptr_type;
40 
41 
43  explicit CWeakPtr(const CWeakPtrFacade<ValueType>& val):
44  m_data(val.m_data) { PBORI_ASSERT(m_data);}
45 
47  CWeakPtr(const self& rhs): m_data(rhs.m_data) {}
48 
50  ~CWeakPtr() {}
51 
53  const value_type& operator*() const {
54  return *(operator->());
55  }
56 
59  if (!*m_data)
60  throw std::runtime_error("Outdated weak pointer dereferenced.");
61 
62  return (*m_data);
63  }
65  operator bool() const { return *m_data; }
66 
67 private:
68  ptr_type m_data;
69 };
70 
72 
73 #endif /* polybori_CWeakPtr_h_ */