CYCLUS
Protected Member Functions | Friends | List of all members
cyclus::IntrusiveBase< Derived > Class Template Reference

Detailed Description

template<class Derived>
class cyclus::IntrusiveBase< Derived >

IntrusiveBase provides a base class that fulfulls basic requirements for a (sub) class to be used in a boost::intrusive_ptr.

Allows subclasses to track their reference count via the onboard "counter_" member variable. To use a class as a boost::intrusive_ptr, it should inherit from IntrusiveBase with default access (NOT public). All destructors of subclasses (and subsub, etc.) should be virtual to ensure memory deallocation occurs properly for objects that have been up-casted:

class Resource: IntrusiveBase<Resource> {
...
virtual ~Resource();
...
}
int main(...) {
boost::intrusive_ptr<Resource> Resource(new Resource());
boost::intrusive_ptr<Resource> resource2(new Resource());
// use resource as if it were a regular pointer, e.g.
double quantity = resource->quantity();
// equals operator compares raw pointer values:
// always true
if (resource == resource) {}
// always false
if (resource == resource2) {}
// don't worry about deallocation - it will be automatic.
}

Definition at line 45 of file intrusive_base.h.

#include <intrusive_base.h>

Protected Member Functions

 IntrusiveBase ()
 
 IntrusiveBase (const IntrusiveBase &)
 
IntrusiveBaseoperator= (const IntrusiveBase &)
 
 ~IntrusiveBase ()
 

Friends

void intrusive_ptr_add_ref (const Derived *p)
 
void intrusive_ptr_release (const Derived *p)
 

Constructor & Destructor Documentation

◆ IntrusiveBase() [1/2]

template<class Derived >
cyclus::IntrusiveBase< Derived >::IntrusiveBase ( )
inlineprotected

protected because we don't want direct instantiations of

Definition at line 63 of file intrusive_base.h.

◆ ~IntrusiveBase()

template<class Derived >
cyclus::IntrusiveBase< Derived >::~IntrusiveBase ( )
inlineprotected

Definition at line 65 of file intrusive_base.h.

◆ IntrusiveBase() [2/2]

template<class Derived >
cyclus::IntrusiveBase< Derived >::IntrusiveBase ( const IntrusiveBase< Derived > &  )
inlineprotected

the copy constructor must zero out the ref count

Definition at line 68 of file intrusive_base.h.

Member Function Documentation

◆ operator=()

template<class Derived >
IntrusiveBase& cyclus::IntrusiveBase< Derived >::operator= ( const IntrusiveBase< Derived > &  )
inlineprotected

Definition at line 70 of file intrusive_base.h.

Friends And Related Function Documentation

◆ intrusive_ptr_add_ref

template<class Derived >
void intrusive_ptr_add_ref ( const Derived *  p)
friend

used by boost::intrusive_ptr to increase object's reference count

Definition at line 47 of file intrusive_base.h.

◆ intrusive_ptr_release

template<class Derived >
void intrusive_ptr_release ( const Derived *  p)
friend

used by boost::intrusive_ptr to decrease object's reference count and deallocate the object if the ref count is zero.

Definition at line 54 of file intrusive_base.h.


The documentation for this class was generated from the following file: