CWeakPtr.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_CWeakPtr_h_
#define polybori_CWeakPtr_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include "CWeakPtrFacade.h"
BEGIN_NAMESPACE_PBORI
template <class ValueType>
class CWeakPtr {
typedef CWeakPtr self;
public:
typedef ValueType value_type;
typedef value_type* data_type;
typedef boost::shared_ptr<data_type> ptr_type;
explicit CWeakPtr(const CWeakPtrFacade<ValueType>& val):
m_data(val.m_data) { PBORI_ASSERT(m_data);}
CWeakPtr(const self& rhs): m_data(rhs.m_data) {}
~CWeakPtr() {}
const value_type& operator*() const {
return *(operator->());
}
value_type* operator->() const {
if (!*m_data)
throw std::runtime_error("Outdated weak pointer dereferenced.");
return (*m_data);
}
operator bool() const { return *m_data; }
private:
ptr_type m_data;
};
END_NAMESPACE_PBORI
#endif /* polybori_CWeakPtr_h_ */