Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

MangoPtr::ObjSharing< OShared > Class Template Reference

#include <ObjSharing.hh>

Inheritance diagram for MangoPtr::ObjSharing< OShared >:

Inheritance graph
[legend]
Collaboration diagram for MangoPtr::ObjSharing< OShared >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<>
class MangoPtr::ObjSharing< OShared >

Policy implementor for shared ownership and shared usage.

Shared ownership is more complicated than strict ownership. Strict ownership means there is only one owner. Regardless of how many BLink objects are sharing usage with the owner, the owner controls the life of the pointee. With shared ownership, the life of the pointee is governed by the owners sharing it: the pointee will be destroyed if the program does a release() or reset() on one of the owners, or when the last of the owners gets destroyed. Such operations will invalidate the usage of the pointee in all owners, but sets the pointer to null only in the owner who executes the release() or reset().

This requires that we track whether the ownership has been shared at least once: if it has never been shared, then the validity of the pointee is simply whether or not it is null; if it has, the validity is tracked via the usage validator. ObjSharing<OShared> takes care of this. The other thing is to track whether the ownership is currently shared, which determines whether, upon destruction of the owner containing ObjSharing<OShared>, the pointee should be deleted.

The only tricky aspect of using ObjSharing is to make sure that operator() is called before the first copy is done. It can safely be called everytime a copy is done. In debug mode, if this call hasn't been done, an assertion will fail because the validators must have been initialized before the first copy/assign, and operator() is the method that takes care of initialization.

Definition at line 98 of file ObjSharing.hh.

Public Methods

 ObjSharing ()
 Default construction.

 ObjSharing (const ObjSharing &rhs)
 Copy constructor.

void operator= (const ObjSharing &rhs)
 assignment to rhs

void swap (ObjSharing &rhs)
 swap with another ObjSharing<OShared>

ObjSharingoperator() (void *optr)
 Set the validity from the value of optr, if appropriate.

void unlinkNew ()
 Reset sharing to default construction state.

bool isValid (void *optr) const
 Testing for validity depends on whether ownership has yet been shared or not.

bool destructNeedsDelete (void *optr) const
 Pointer needs delete only if valid and not shared.

size_t getCountOwned () const
 get how many owners are sharing ownership

size_t getCountUser () const
 get how many users are sharing usage


Member Function Documentation

ObjSharing& MangoPtr::ObjSharing< OShared >::operator() void *    optr [inline]
 

Set the validity from the value of optr, if appropriate.

This must be called at least once before the first copy/assign of this ObjSharing instance is done.

Definition at line 135 of file ObjSharing.hh.

References MangoPtrPrivateNamespace::PtrUsageSharing::setFrom().

bool MangoPtr::ObjSharing< OShared >::isValid void *    optr const [inline]
 

Testing for validity depends on whether ownership has yet been shared or not.

See class docs for details.

Definition at line 152 of file ObjSharing.hh.


The documentation for this class was generated from the following file:
Generated on Tue Nov 12 20:44:02 2002 for Mango-ptr Library by doxygen1.2.18