MADNESS  0.10.1
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
madness::detail::RemoteCounter Class Reference

Remote reference counter. More...

#include <worldref.h>

Collaboration diagram for madness::detail::RemoteCounter:
Collaboration graph
[legend]

Public Member Functions

 RemoteCounter ()
 
 RemoteCounter (const RemoteCounter &other)
 
template<typename T >
 RemoteCounter (World &w, const std::shared_ptr< T > &p)
 
 ~RemoteCounter ()
 
bool empty () const
 
template<typename T >
const std::shared_ptr< T > & get_shared () const
 
Worldget_world () const
 
WorldPtr< implT >::worldidT get_worldid () const
 
bool has_owner () const
 
bool is_local () const
 
RemoteCounteroperator= (const RemoteCounter &other)
 
ProcessID owner () const
 
void swap (RemoteCounter &other)
 
bool unique () const
 
long use_count () const
 Counter accessor. More...
 

Private Types

typedef RemoteCounterBase implT
 
typedef ConcurrentHashMap< void *, WorldPtr< implT > > pimpl_mapT
 

Private Member Functions

 RemoteCounter (const WorldPtr< implT > &p)
 
void destroy ()
 Clean-up the implementation object. More...
 
template<typename Archive >
void load_ (const Archive &ar)
 
template<typename Archive >
void store_ (const Archive &ar) const
 

Static Private Member Functions

template<typename T >
static WorldPtr< implTregister_ptr_ (World &w, const std::shared_ptr< T > &p)
 Register a local shared pointer. More...
 
static void unregister_ptr_ (void *key)
 Unregister a local shared pointer reference. More...
 

Private Attributes

WorldPtr< implTpimpl_
 Pointer to the shared counter implementation object. More...
 

Static Private Attributes

static pimpl_mapT pimpl_map_
 

Friends

template<typename , typename , typename >
struct archive::ArchiveLoadImpl
 
template<typename , typename , typename >
struct archive::ArchiveStoreImpl
 

Detailed Description

Remote reference counter.

Automatically counts local and remote references to an object. The reference count is incremented when the object is copied locally or serialized as part of communication.

Member Typedef Documentation

◆ implT

◆ pimpl_mapT

Constructor & Destructor Documentation

◆ RemoteCounter() [1/4]

madness::detail::RemoteCounter::RemoteCounter ( const WorldPtr< implT > &  p)
inlineprivate

◆ RemoteCounter() [2/4]

madness::detail::RemoteCounter::RemoteCounter ( )
inline

Referenced by load_().

◆ RemoteCounter() [3/4]

madness::detail::RemoteCounter::RemoteCounter ( const RemoteCounter other)
inline

References pimpl_.

◆ RemoteCounter() [4/4]

template<typename T >
madness::detail::RemoteCounter::RemoteCounter ( World w,
const std::shared_ptr< T > &  p 
)
inlineexplicit

◆ ~RemoteCounter()

madness::detail::RemoteCounter::~RemoteCounter ( )
inline

References destroy().

Member Function Documentation

◆ destroy()

void madness::detail::RemoteCounter::destroy ( )
inlineprivate

Clean-up the implementation object.

Here we check that the pimpl has been initialized, and if so, we release the current reference. If the count drops to zero, then this is the last reference to the pimpl and it should be deleted.

References pimpl_, madness::print(), and unregister_ptr_().

Referenced by ~RemoteCounter(), and operator=().

◆ empty()

bool madness::detail::RemoteCounter::empty ( ) const
inline

◆ get_shared()

template<typename T >
const std::shared_ptr<T>& madness::detail::RemoteCounter::get_shared ( ) const
inline

References pimpl_, and T().

Referenced by madness::RemoteReference< T >::get_shared().

◆ get_world()

World& madness::detail::RemoteCounter::get_world ( ) const
inline

◆ get_worldid()

WorldPtr<implT>::worldidT madness::detail::RemoteCounter::get_worldid ( ) const
inline

References pimpl_.

Referenced by madness::detail::operator<<().

◆ has_owner()

bool madness::detail::RemoteCounter::has_owner ( ) const
inline

References pimpl_.

Referenced by madness::RemoteReference< T >::reset().

◆ is_local()

bool madness::detail::RemoteCounter::is_local ( ) const
inline

◆ load_()

template<typename Archive >
void madness::detail::RemoteCounter::load_ ( const Archive &  ar)
inlineprivate

◆ operator=()

RemoteCounter& madness::detail::RemoteCounter::operator= ( const RemoteCounter other)
inline

References destroy(), and pimpl_.

◆ owner()

ProcessID madness::detail::RemoteCounter::owner ( ) const
inline

◆ register_ptr_()

template<typename T >
static WorldPtr<implT> madness::detail::RemoteCounter::register_ptr_ ( World w,
const std::shared_ptr< T > &  p 
)
inlinestaticprivate

Register a local shared pointer.

This function will first search the local pointer register for the shared pointer p. If found the pimpl for that pointer will be returned. Otherwise a new pimpl will be created and returned.

Template Parameters
TThe shared pointer type to register
Parameters
wThe world where the pointer lives
pThe shared pointer to register
Returns
A world pointer to the pimpl
Exceptions
std::bad_allocIf pimpl allocation fails.
madness::MadnessExceptionIf pointer cannot be inserted into the pointer registration map.

References madness::ConcurrentHashMap< keyT, valueT, hashfunT >::insert(), p(), pimpl_map_, madness::print(), and w().

◆ store_()

template<typename Archive >
void madness::detail::RemoteCounter::store_ ( const Archive &  ar) const
inlineprivate

References pimpl_, and madness::print().

◆ swap()

void madness::detail::RemoteCounter::swap ( RemoteCounter other)
inline

References pimpl_, and madness::detail::swap().

Referenced by madness::detail::swap().

◆ unique()

bool madness::detail::RemoteCounter::unique ( ) const
inline

◆ unregister_ptr_()

static void madness::detail::RemoteCounter::unregister_ptr_ ( void *  key)
inlinestaticprivate

Unregister a local shared pointer reference.

Parameters
keyThe key of the RemoteReference object to be unregistered.
Exceptions
MadnessExceptionIf key is not found in the pointer map.

References MADNESS_EXCEPTION, pimpl_map_, and madness::ConcurrentHashMap< keyT, valueT, hashfunT >::try_erase().

Referenced by destroy().

◆ use_count()

long madness::detail::RemoteCounter::use_count ( ) const
inline

Counter accessor.

Returns
The number of local and remote references
Exceptions
none

References pimpl_.

Referenced by madness::detail::operator<<(), unique(), and madness::RemoteReference< T >::use_count().

Friends And Related Function Documentation

◆ archive::ArchiveLoadImpl

template<typename , typename , typename >
friend struct archive::ArchiveLoadImpl
friend

◆ archive::ArchiveStoreImpl

template<typename , typename , typename >
friend struct archive::ArchiveStoreImpl
friend

Member Data Documentation

◆ pimpl_

WorldPtr<implT> madness::detail::RemoteCounter::pimpl_
mutableprivate

Pointer to the shared counter implementation object.

Referenced by RemoteCounter(), destroy(), empty(), get_shared(), get_world(), get_worldid(), has_owner(), is_local(), load_(), operator=(), owner(), store_(), swap(), and use_count().

◆ pimpl_map_

RemoteCounter::pimpl_mapT madness::detail::RemoteCounter::pimpl_map_
staticprivate

A map of currently registered implementation objects. The key is it's referenced pointer.

Referenced by register_ptr_(), and unregister_ptr_().


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