STXXL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::external_shared_ptr< P > Class Template Reference

Detailed Description

template<class P>
class stxxl::external_shared_ptr< P >

This class takes a shared pointer, increments its reference count and wraps it in a way that the resulting object can be copied, dumped to disk, and destroyed without affecting the refcount.

When the object is retrieved from disk and recreated on internal memory, it will still hold a reference to the same memory block and can be used right away by calling the "get" method or unwrapped with the "unwrap" method to decrement the refcount.

In the context of this template, a shared pointer is an object of a class P that fulfills the following requirements:

  • Can be copy-constructed
  • Has an assignment operator (so that the get method can be used)
  • Contains a pointer to a reference count stored outside the class
  • Increments the reference count on copy-construction
  • Decrements the reference count on destruction

Both the Boost and c++0x implementations of shared_ptr fulfill these requirements. At the moment of writing the author is not aware of any implementations of shared pointers that can't be used with this wrapper.

Definition at line 46 of file external_shared_ptr.h.

Public Member Functions

 external_shared_ptr ()
 This constructor needs to be defined so that the [] operator in maps and hash tables works. More...
 
 external_shared_ptr (P ptr)
 Copy the pointer to internal storage and increment the refcount (the destructor never gets called). More...
 
get () const
 If this is called after unwrap() the behaviour is undefined. More...
 
bool operator== (const external_shared_ptr &x) const
 
void unwrap ()
 Call the destructor to decrement the refcount. More...
 

Private Attributes

char data [sizeof(P)]
 We store the pointer like this so that the refcount does not get incremented when the wrapper is copy-constructed, or decremented when the wrapper is destroyed. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const external_shared_ptr &p)
 Output contained data items. More...
 

Constructor & Destructor Documentation

template<class P >
stxxl::external_shared_ptr< P >::external_shared_ptr ( )
inline

This constructor needs to be defined so that the [] operator in maps and hash tables works.

If unwrap() or get() are called for an object constructed this way the behavior is undefined.

Definition at line 68 of file external_shared_ptr.h.

template<class P >
stxxl::external_shared_ptr< P >::external_shared_ptr ( ptr)
inline

Copy the pointer to internal storage and increment the refcount (the destructor never gets called).

Definition at line 75 of file external_shared_ptr.h.

Member Function Documentation

template<class P >
P stxxl::external_shared_ptr< P >::get ( ) const
inline

If this is called after unwrap() the behaviour is undefined.

Definition at line 93 of file external_shared_ptr.h.

template<class P >
bool stxxl::external_shared_ptr< P >::operator== ( const external_shared_ptr< P > &  x) const
inline

Definition at line 99 of file external_shared_ptr.h.

References stxxl::external_shared_ptr< P >::data.

template<class P >
void stxxl::external_shared_ptr< P >::unwrap ( )
inline

Call the destructor to decrement the refcount.

If this is called more than once the results are undefined.

Definition at line 84 of file external_shared_ptr.h.

Friends And Related Function Documentation

template<class P >
std::ostream& operator<< ( std::ostream &  os,
const external_shared_ptr< P > &  p 
)
friend

Output contained data items.

Definition at line 109 of file external_shared_ptr.h.

Member Data Documentation

template<class P >
char stxxl::external_shared_ptr< P >::data[sizeof(P)]
private

We store the pointer like this so that the refcount does not get incremented when the wrapper is copy-constructed, or decremented when the wrapper is destroyed.

The whole external_shared_ptr object will be aligned by the compiler to a multiple of its size. The size of the object is sizeof(P) as the buffer is its only member. The buffer is placed in the class at offset 0 so the alignment of the stored P should be alright without any additional hints.

Definition at line 60 of file external_shared_ptr.h.

Referenced by stxxl::external_shared_ptr< P >::operator==().


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