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

MangoPtr::Owned< CntrType &, OShared > Class Template Reference

#include <OwnedCntrShared.hh>

Inheritance diagram for MangoPtr::Owned< CntrType &, OShared >:

Inheritance graph
[legend]
Collaboration diagram for MangoPtr::Owned< CntrType &, OShared >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename CntrType>
class MangoPtr::Owned< CntrType &, OShared >

Shared owned container of pointers.

The container instance must live somewhere else, therefore this class must be used with care:

When the last owner of the container goes out of scope, all the elements in the container are delete'd and the container emptied. All iterators that were pointing into the container become invalid. Copy is allowed, leading to shallow copying of course.

The only "good" places to use Owned<Container &> seem to be:

All these are rather contrived and suggest that such usage would stem from a bad design to start with, and due to the caveats mentioned earlier, we discourage the use of this class. It is included just in case it is needed for idioms we haven't thought of but which may be popular with other software developers.

See the general documentation for Owned<T> to get more usage information.

Definition at line 70 of file OwnedCntrShared.hh.

Public Types

typedef CntrType ObjectType
 Class of object held, a la auto_ptr.


Public Methods

Constructors
 Owned (CntrType &)
 Take ownership of a container of pointers.

 Owned (const Owned &)
 Take ownership of a container of pointers, but by copy.

 ~Owned ()
 Use the method pointer to do the clean up.

Utility methods
void cloneObjNew (CntrType &) const
 Convenience method to create a deep-copied copy of the owned container, using new() (if you have defined a specialization of CntrCloner for your container element type and it is visible at the time of copy, that one will be used by the compiler instead of new()), into dest.

void reset ()
 Reset the container owned to empty pointers.

CntrType & cntr ()
 Use this method to get ref to container.

const CntrType & cntr () const
 Use this method to get ref to const container.

CntrType * operator() ()
 Use this method to get a pointer to container, never NULL.

const CntrType * operator() () const
 Use this method to get a const pointer to container, never NULL.


Constructor & Destructor Documentation

template<typename CntrType>
MangoPtr::Owned< CntrType &, OShared >::~Owned   [inline]
 

Use the method pointer to do the clean up.

This supports default destructors of classes that want to use only a forward declaration of the container's element type.

Definition at line 146 of file OwnedCntrShared.hh.

References MangoPtr::Owned< CntrType, oshiptype >::reset().


Member Function Documentation

template<typename CntrType>
MangoPtr::Owned< CntrType &, OShared >::Owned CntrType &    cntr [inline, explicit]
 

Take ownership of a container of pointers.

The cntr is transfered to Owned, meaning that after creation, the original container is empty. This requires a exception-safe, performant std::swap to be defined CntrType.

Definition at line 123 of file OwnedCntrShared.hh.

template<typename CntrType>
MangoPtr::Owned< CntrType &, OShared >::Owned const Owned< CntrType &, OShared > &    rhs [inline]
 

Take ownership of a container of pointers, but by copy.

The cntr is shallow-copied to Owned. This uses more memory than the transfering constructor, but allows the user to keep working with the original, confident that the memory will be freed when the Owned goes out of scope. Ie., user must make sure that original list elements are not used *after* the Owned has gone out of scope

Definition at line 136 of file OwnedCntrShared.hh.

template<typename CntrType>
void MangoPtr::Owned< CntrType &, OShared >::cloneObjNew CntrType &    dest const [inline]
 

Convenience method to create a deep-copied copy of the owned container, using new() (if you have defined a specialization of CntrCloner for your container element type and it is visible at the time of copy, that one will be used by the compiler instead of new()), into dest.

To clone into another owned container, use cloneObjNew(owned.cntr()).

Precondition:
dest must be empty
Parameters:
dest  the destination container

Definition at line 179 of file OwnedCntrShared.hh.

template<typename CntrType>
void MangoPtr::Owned< CntrType &, OShared >::reset   [inline]
 

Reset the container owned to empty pointers.

Remember that this affects the original container, as well as all the other owners sharing this container. The result is that the original container is empty and every element has had delete called on it.

Definition at line 159 of file OwnedCntrShared.hh.


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