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_ */
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
pbori_defs.h
polybori::CWeakPtr::operator->
value_type * operator->() const
Dereferencing generates strong-referenced instance.
Definition: CWeakPtr.h:58
PBORI_ASSERT
#define PBORI_ASSERT(arg)
Definition: pbori_defs.h:118
polybori::CWeakPtr::data_type
value_type * data_type
Definition: CWeakPtr.h:38
polybori::CWeakPtr::~CWeakPtr
~CWeakPtr()
Destructor.
Definition: CWeakPtr.h:50
CWeakPtrFacade.h
polybori::CWeakPtr::value_type
ValueType value_type
Definition: CWeakPtr.h:36
polybori::CWeakPtrFacade
This class defines CWeakPtrFacade.
Definition: CWeakPtrFacade.h:36
polybori::CWeakPtr
Forward declaration of friend.
Definition: CWeakPtr.h:31
polybori::CWeakPtr::ptr_type
boost::shared_ptr< data_type > ptr_type
Definition: CWeakPtr.h:39
polybori::CWeakPtr::CWeakPtr
CWeakPtr(const self &rhs)
Copy constructor.
Definition: CWeakPtr.h:47
polybori::CWeakPtr::CWeakPtr
CWeakPtr(const CWeakPtrFacade< ValueType > &val)
Construct from something, which supports weak pointers.
Definition: CWeakPtr.h:43
polybori::CWeakPtr::operator*
const value_type & operator*() const
Dereferencing generates strong-referenced instance.
Definition: CWeakPtr.h:53