CExtrusivePtr.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_common_CExtrusivePtr_h_
#define polybori_common_CExtrusivePtr_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include <algorithm> // std::swap
BEGIN_NAMESPACE_PBORI
template <class DataType, class ValueType>
class CExtrusivePtr {
typedef CExtrusivePtr self;
public:
typedef DataType data_type;
typedef ValueType value_type;
CExtrusivePtr(const data_type& data, value_type* ptr):
m_data(data), p_ptr(ptr) { lock(); }
CExtrusivePtr(const self& rhs):
m_data(rhs.m_data), p_ptr(rhs.p_ptr) { lock(); }
CExtrusivePtr():
m_data(), p_ptr(NULL) { }
~CExtrusivePtr() { release(); }
self& operator=(const self& rhs) {
self(rhs).swap(*this);
return *this;
}
const data_type& data() const { return m_data; }
value_type* get() const {
return p_ptr;
}
const value_type & operator*() const {
PBORI_ASSERT(p_ptr != NULL);
return *p_ptr;
}
value_type & operator*() {
PBORI_ASSERT(p_ptr != NULL);
return *p_ptr;
}
value_type* operator->() const {
PBORI_ASSERT(p_ptr != NULL);
return p_ptr;
}
void swap(self & rhs) {
std::swap(m_data, rhs.m_data);
std::swap(p_ptr, rhs.p_ptr);
}
protected:
void lock() {
extrusive_ptr_add_ref(data(), get());
}
void release() {
extrusive_ptr_release(data(), get());
}
data_type m_data;
value_type* p_ptr;
};
template <class Data1, class Type1, class Data2, class Type2>
inline bool
operator==(const CExtrusivePtr<Data1, Type1> & lhs,
const CExtrusivePtr<Data2, Type2> & rhs) {
return lhs.get() == rhs.get();
}
template <class Data1, class Type1, class Data2, class Type2>
inline bool
operator!=(const CExtrusivePtr<Data1, Type1> & lhs,
const CExtrusivePtr<Data2, Type2> & rhs) {
return lhs.get() != rhs.get();
}
template <class Data1, class Type1, class Type2>
inline bool
operator==(const CExtrusivePtr<Data1, Type1> & lhs, Type2 * rhs) {
return lhs.get() == rhs;
}
template <class Data1, class Type1, class Type2>
inline bool
operator!=(const CExtrusivePtr<Data1, Type1> & lhs, Type2* rhs) {
return lhs.get() != rhs;
}
template <class Type1, class Data2, class Type2>
inline bool
operator==(Type1* lhs, const CExtrusivePtr<Data2, Type2> & rhs) {
return lhs == rhs.get();
}
template <class Type1, class Data2, class Type2>
inline bool
operator!=(Type1* lhs, const CExtrusivePtr<Data2, Type2> & rhs) {
return lhs != rhs.get();
}
END_NAMESPACE_PBORI
#endif
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
polybori::CExtrusivePtr::~CExtrusivePtr
~CExtrusivePtr()
Destructor.
Definition: CExtrusivePtr.h:69
polybori::CExtrusivePtr::operator=
self & operator=(const self &rhs)
Assignment.
Definition: CExtrusivePtr.h:72
polybori::CExtrusivePtr::CExtrusivePtr
CExtrusivePtr(const data_type &data, value_type *ptr)
Construct managed pointer with additional data.
Definition: CExtrusivePtr.h:58
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
polybori::CExtrusivePtr::get
value_type * get() const
Get actual pointer.
Definition: CExtrusivePtr.h:81
polybori::CExtrusivePtr::operator*
const value_type & operator*() const
Constant dereferencing.
Definition: CExtrusivePtr.h:86
polybori::CExtrusivePtr::data
const data_type & data() const
Accessing helpter data.
Definition: CExtrusivePtr.h:78
polybori::CExtrusivePtr::CExtrusivePtr
CExtrusivePtr(const self &rhs)
Copy constructor.
Definition: CExtrusivePtr.h:62
polybori::operator==
bool operator==(Type1 *lhs, const CExtrusivePtr< Data2, Type2 > &rhs)
Equality check from a pointer.
Definition: CExtrusivePtr.h:157
polybori::extrusive_ptr_add_ref
void extrusive_ptr_add_ref(const DataType &, DdNode *ptr)
Incrememting reference counts to raw pointers to decision diagrams.
Definition: CCuddDDFacade.h:75
pbori_defs.h
polybori::CExtrusivePtr::p_ptr
value_type * p_ptr
Store actual pointer.
Definition: CExtrusivePtr.h:121
polybori::CExtrusivePtr::value_type
ValueType value_type
Value type.
Definition: CExtrusivePtr.h:55
polybori::CExtrusivePtr::data_type
DataType data_type
Type for additional data storange.
Definition: CExtrusivePtr.h:52
polybori::CExtrusivePtr::m_data
data_type m_data
Store helper data.
Definition: CExtrusivePtr.h:118
polybori::CExtrusivePtr::operator->
value_type * operator->() const
Pointer operator.
Definition: CExtrusivePtr.h:98
PBORI_ASSERT
#define PBORI_ASSERT(arg)
Definition: pbori_defs.h:118
polybori::CExtrusivePtr::swap
void swap(self &rhs)
Swap.
Definition: CExtrusivePtr.h:104
polybori::CExtrusivePtr::release
void release()
Definition: CExtrusivePtr.h:113
polybori::CExtrusivePtr
This template class defines a reimplementation of the interface from boost:intrusive_ptr, but with an additional data field.
Definition: CExtrusivePtr.h:44
polybori::CExtrusivePtr::CExtrusivePtr
CExtrusivePtr()
Definition: CExtrusivePtr.h:65
polybori::CExtrusivePtr::operator*
value_type & operator*()
Nonconstant dereference.
Definition: CExtrusivePtr.h:92
polybori::extrusive_ptr_release
void extrusive_ptr_release(const DataType &data, DdNode *ptr)
Releasing raw pointers to decision diagrams here.
Definition: CCuddDDFacade.h:66
polybori::operator!=
bool operator!=(Type1 *lhs, const CExtrusivePtr< Data2, Type2 > &rhs)
Nonequality check from a pointer.
Definition: CExtrusivePtr.h:164
polybori::CExtrusivePtr::lock
void lock()
Definition: CExtrusivePtr.h:110