|
cgma
|
A vector of pointers to objects that are automatically deleted when the container itself is deleted. More...
#include <ManagedPtrVector.hpp>
Classes | |
| class | iterator |
Public Types | |
| typedef X | value_type |
| typedef X & | reference_type |
| typedef size_t | size_type |
| typedef std::vector< X * > | container_type |
Public Member Functions | |
| ManagedPtrVector () | |
| ~ManagedPtrVector () | |
| void | push_back (X *obj) |
| iterator | begin () |
| iterator | end () |
| reference_type | operator[] (size_type i) |
| Refer by index. | |
| std::auto_ptr< X > | release (iterator to_release) |
| Remove an item from the list without deleting it. | |
| std::auto_ptr< X > | replace (iterator to_replace, std::auto_ptr< X > new_val) |
| Replace one object with another. | |
| void | clear () |
| size_type | size () const |
Private Member Functions | |
| ManagedPtrVector (const ManagedPtrVector< X > &) | |
| ManagedPtrVector & | operator= (const ManagedPtrVector< X > &) |
Private Attributes | |
| container_type | mContainer |
A vector of pointers to objects that are automatically deleted when the container itself is deleted.
Loosely modeled after the boost ptr containers.
Definition at line 13 of file ManagedPtrVector.hpp.
| typedef std::vector<X*> ManagedPtrVector< X >::container_type |
Definition at line 19 of file ManagedPtrVector.hpp.
| typedef X& ManagedPtrVector< X >::reference_type |
Definition at line 17 of file ManagedPtrVector.hpp.
| typedef size_t ManagedPtrVector< X >::size_type |
Definition at line 18 of file ManagedPtrVector.hpp.
| typedef X ManagedPtrVector< X >::value_type |
Definition at line 16 of file ManagedPtrVector.hpp.
| ManagedPtrVector< X >::ManagedPtrVector | ( | ) | [inline] |
Definition at line 105 of file ManagedPtrVector.hpp.
{}
| ManagedPtrVector< X >::~ManagedPtrVector | ( | ) | [inline] |
Definition at line 107 of file ManagedPtrVector.hpp.
{ clear(); }
| ManagedPtrVector< X >::ManagedPtrVector | ( | const ManagedPtrVector< X > & | ) | [private] |
| iterator ManagedPtrVector< X >::begin | ( | ) | [inline] |
Definition at line 115 of file ManagedPtrVector.hpp.
{ return iterator(mContainer.begin()); }
| void ManagedPtrVector< X >::clear | ( | ) | [inline] |
Definition at line 169 of file ManagedPtrVector.hpp.
{
// delete all the pointers
for (typename container_type::iterator i = mContainer.begin();
i != mContainer.end();
i++)
{
delete *i;
}
mContainer.clear();
}
| iterator ManagedPtrVector< X >::end | ( | ) | [inline] |
Definition at line 117 of file ManagedPtrVector.hpp.
{ return iterator(mContainer.end()); }
| ManagedPtrVector& ManagedPtrVector< X >::operator= | ( | const ManagedPtrVector< X > & | ) | [private] |
| reference_type ManagedPtrVector< X >::operator[] | ( | size_type | i | ) | [inline] |
| void ManagedPtrVector< X >::push_back | ( | X * | obj | ) | [inline] |
Definition at line 112 of file ManagedPtrVector.hpp.
{ mContainer.push_back(obj); }
| std::auto_ptr<X> ManagedPtrVector< X >::release | ( | iterator | to_release | ) | [inline] |
Remove an item from the list without deleting it.
The returned auto_ptr now owns the pointer.
Definition at line 126 of file ManagedPtrVector.hpp.
{
// save a raw pointer.
X* rv = to_release.operator->();
// find the iterator in the container. We don't have access
// to the internal iterator, so we have to loop through to find it.
// This could probably be optimized.
typename container_type::iterator i = mContainer.begin();
for (;
i != mContainer.end() && iterator(i) != to_release;
++i)
{}
// we either found the iterator, or the end. erase it.
mContainer.erase(i);
return std::auto_ptr<X>(rv);
}
| std::auto_ptr<X> ManagedPtrVector< X >::replace | ( | iterator | to_replace, |
| std::auto_ptr< X > | new_val | ||
| ) | [inline] |
Replace one object with another.
The returned auto_ptr now owns the pointer removed from the container, and the container owns the object pointed to by new_val.
Definition at line 148 of file ManagedPtrVector.hpp.
{
// save a raw pointer.
X* rv = to_replace.operator->();
// find the iterator in the container. We don't have access
// to the internal iterator, so we have to loop through to find it.
// This could probably be optimized.
typename container_type::iterator i = mContainer.begin();
for (;
i != mContainer.end();
++i)
{
if (iterator(i) == to_replace)
{
*i = new_val;
}
}
return std::auto_ptr<X>(NULL);
}
| size_type ManagedPtrVector< X >::size | ( | ) | const [inline] |
Definition at line 181 of file ManagedPtrVector.hpp.
{ return mContainer.size(); }
container_type ManagedPtrVector< X >::mContainer [private] |
Definition at line 189 of file ManagedPtrVector.hpp.