PArray< T > Class Template Reference

: An Array of Pointers to Objects of Type T More...

#include <PArray.H>

Inheritance diagram for PArray< T >:

Inheritance graph
[legend]
Collaboration diagram for PArray< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 PArray (PArrayPolicy _managed=PArrayNoManage)
 Constructs a PArray<T> with no elements.
 PArray (int len, PArrayPolicy _managed=PArrayNoManage)
 Constructs a PArray<T> of length len of null pointers.
 ~PArray ()
 The destructor.
bool defined (int i) const
 Returns true if the i'th element is not the null pointer.
const T & operator[] (int i) const
 Returns a constant reference to the object pointed to by the i'th element in this PArray<T>.
T & operator[] (int i)
 Returns a reference to the object pointed to by the i'th element in this PArray<T>.
const T & get (int i) const
 Returns a constant reference to the object pointed to by the i'th element in the PArray.
T & get (int i)
 Returns a reference to the object pointed to by the i'th element in the PArray.
void set (int i, T *elem)
 Defines the i'th element of this PArray<T> to the pointer value elem.
int size () const
 Returns the number of elements.
void clear ()
 This function sets each pointer in this PArray<T> to null.
void clear (int i)
 The i'th element in this PArray<T> is set to null.
void resize (int newsize)
 This function changes the size of the array to newsize while preserving the value of as many array elements as possible.
void resize (int newsize, PArrayPolicy newmanagedpolicy)
 This function does a resize and changes the PArrayPolicy.
T * remove (int i)
 Removes the i'th element from the PArray and returns the pointer to the calling function.
 PArray (const PArray< T > &)

Protected Attributes

Array< void * > vp
PArrayPolicy managed


Detailed Description

template<class T>
class PArray< T >

: An Array of Pointers to Objects of Type T

The PArray<T> class is similar to the Array<T> class except that it implements an array of pointers to objects of type T rather than an array of the objects themselves. As with Array<T> objects, PArray<T> objects know about their length, can be dynamically resized and have built-in automatic bounds checking.

When a PArray<T> object is destructed, should only the pointers be destructed or should the objects to which they point also be deleted? The PArray<T> class allows for both scenarios. By default, it will only remove the pointers. If the array is constructed with the PArrayManage argument it will also delete all the objects pointed to in the array.

This is a concrete class, not a polymorphic one.

PArray<T>s do NOT provide a copy constructor or an assignment operator.


Constructor & Destructor Documentation

template<class T>
PArray< T >::PArray ( PArrayPolicy  _managed = PArrayNoManage  )  [inline, explicit]

Constructs a PArray<T> with no elements.

The default memory management policy is not to delete the underlying objects upon destruction.

template<class T>
PArray< T >::PArray ( int  len,
PArrayPolicy  _managed = PArrayNoManage 
) [inline, explicit]

Constructs a PArray<T> of length len of null pointers.

The default memory management policy is not to delete the underlying objects upon destruction.

References PArray< T >::size(), and PArray< T >::vp.

template<class T>
PArray< T >::~PArray (  )  [inline]

The destructor.

If the memory management policy was set to Manage upon construction, this destructor will also delete all objects referenced by the pointers in this array.

References PArray< T >::clear().

template<class T>
PArray< T >::PArray ( const PArray< T > &  c  )  [inline]

References BL_ASSERT, and PArray< T >::size().


Member Function Documentation

template<class T>
bool PArray< T >::defined ( int  i  )  const [inline]

Returns true if the i'th element is not the null pointer.

References PArray< T >::vp.

Referenced by FabArray< FAB >::ok(), and FabArray< FAB >::setFab().

template<class T>
const T & PArray< T >::operator[] ( int  i  )  const [inline]

Returns a constant reference to the object pointed to by the i'th element in this PArray<T>.

Performs bounds checking when the library is compiled in debug mode.

References BL_ASSERT, and PArray< T >::vp.

template<class T>
T & PArray< T >::operator[] ( int  i  )  [inline]

Returns a reference to the object pointed to by the i'th element in this PArray<T>.

Performs bounds checking when the library is compiled in debug mode.

References BL_ASSERT, and PArray< T >::vp.

template<class T>
const T & PArray< T >::get ( int  i  )  const [inline]

Returns a constant reference to the object pointed to by the i'th element in the PArray.

It is an error if the i'th element is the null pointer.

References BL_ASSERT, and PArray< T >::vp.

template<class T>
T & PArray< T >::get ( int  i  )  [inline]

Returns a reference to the object pointed to by the i'th element in the PArray.

It is an error if the i'th element is the null pointer.

References BL_ASSERT, and PArray< T >::vp.

template<class T>
void PArray< T >::set ( int  i,
T *  elem 
) [inline]

Defines the i'th element of this PArray<T> to the pointer value elem.

It is an error if the i'th element previously had a value.

References BL_ASSERT, and PArray< T >::vp.

Referenced by FabArray< FAB >::setFab().

template<class T>
int PArray< T >::size (  )  const [inline]

Returns the number of elements.

References Array< T >::size(), and PArray< T >::vp.

Referenced by PArray< T >::clear(), and PArray< T >::PArray().

template<class T>
void PArray< T >::clear (  )  [inline]

This function sets each pointer in this PArray<T> to null.

If the memory management policy was set to Manage upon construction, this function will also delete all objects referenced by the pointers in this array.

References PArray< T >::managed, PArray< T >::size(), and PArray< T >::vp.

Referenced by FabArray< FAB >::clear(), PArray< T >::resize(), and PArray< T >::~PArray().

template<class T>
void PArray< T >::clear ( int  i  )  [inline]

The i'th element in this PArray<T> is set to null.

If the memory management policy was set to Manage upon construction, this function will also delete the object referenced by that pointer.

References PArray< T >::managed, and PArray< T >::vp.

template<class T>
void PArray< T >::resize ( int  newsize  )  [inline]

This function changes the size of the array to newsize while preserving the value of as many array elements as possible.

If newsize is greater than the current length, the array is grown and the new elements are null pointers. If newsize is less than the current length the array is cropped with the remaining elements retaining their original pointer values. If the memory management policy was set to Manage, any cropped pointers are deleted.

References PArray< T >::managed, Array< T >::size(), and PArray< T >::vp.

Referenced by FabArray< FAB >::define(), and PArray< T >::resize().

template<class T>
void PArray< T >::resize ( int  newsize,
PArrayPolicy  newmanagedpolicy 
) [inline]

This function does a resize and changes the PArrayPolicy.

(Especially for arrays of PArray where the user wants the default policy to be managed--the default constructor makes the default unmanaged). If the new managed policy is different from the old one, none of the elements of the original are retained.

References PArray< T >::clear(), PArray< T >::managed, and PArray< T >::resize().

template<class T>
T * PArray< T >::remove ( int  i  )  [inline]

Removes the i'th element from the PArray and returns the pointer to the calling function.

Nulls out the pointer in the PArray<T>.

References BL_ASSERT, and PArray< T >::vp.


Member Data Documentation

template<class T>
Array<void*> PArray< T >::vp [protected]

template<class T>
PArrayPolicy PArray< T >::managed [protected]


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

Generated on Fri Nov 21 10:11:03 2008 for AMRParticlePaths by  doxygen 1.5.5