cafe::Collection< T > Class Template Reference
[CAF Environment (Cafe)]

#include <Collection.hpp>

List of all members.


Detailed Description

template<class T>
class cafe::Collection< T >

Wrap a TObjArray or TClonesArray in a 'STL like' container class.

By default the Collection<T> does not own the TObjArray that is passed to it and will not delete it.

The exception is an empty collection or an assignment to it. In this case it implements copy-on-write semantics.

The TObjArray is deleted using a "delete" statement, so unless you set the kOwned bit, it shouldn't delete its contents.

Definition at line 25 of file Collection.hpp.

Public Types

typedef T value_type
typedef size_t size_type
typedef T * pointer_type
typedef T & reference_type
typedef const T * const_pointer_type
typedef const T & const_reference_type
typedef iterator cafe_collection_iterator
 Remove ambiguity with the two iterators below.


Public Member Functions

 Collection (TObjArray *data)
 Pass in array.

 Collection (const Collection< T > &other)
 Copy constructor.

 Collection (void)
 Default constructor.

virtual ~Collection ()
 Delete the collection if there are no more elemements in it.

Collection< T > & operator= (const Collection< T > &other)
 Assign other collection to this one.

void push_back (const T &item)
 Add an item to the array.

void push_back (T *item)
 Add an item to the array.

const T & operator[] (size_t index) const
 Easy [] access.

size_t size () const
 Return size of collection.

template<typename compare> void sort (iterator from, iterator to, compare CompFun)
 Sort a cafe::Collection<T>.

 ClassDef (Collection, 0)
Iterator access
iterator begin ()
 Iterators to first element in collection.

const_iterator begin () const
iterator end ()
 Iterator to one past the last element in collection.

const_iterator end () const
iterator erase (iterator it)
 Erase entry at iterator position. Return 'next' position.

iterator erase (iterator first, iterator last)
 Erase entries between iterator positions first and last.


Private Member Functions

void make_us_owner_of_data (void)
 If we don't own the data array, make a copy and assume ownership.

template<typename compare> void insert_sort (TObjArray &array, int const from, int const to, compare CompFun)
template<typename compare> void partial_quicksort (TObjArray &array, int indLow, int indHigh, compare CompFun)
template<typename compare> void full_sort (TObjArray &array, int const from, int const to, compare CompFun)
void swap (TObjArray &array, int i, int j)

Private Attributes

array_holder_data
 Holds pointer to the TObjArray and a reference count.


Member Typedef Documentation

template<class T>
typedef iterator cafe::Collection< T >::cafe_collection_iterator
 

Remove ambiguity with the two iterators below.

I'm not sure what the C++ standard has to say here -- need to investigate which compiler is doing the right thing. But it certianly is confusing anyway. ;-)

Definition at line 205 of file Collection.hpp.

Referenced by cafe::Collection< T >::const_iterator::const_iterator().

template<class T>
typedef const T* cafe::Collection< T >::const_pointer_type
 

Definition at line 31 of file Collection.hpp.

Referenced by cafe::Collection< T >::const_iterator::operator->().

template<class T>
typedef const T& cafe::Collection< T >::const_reference_type
 

Definition at line 32 of file Collection.hpp.

Referenced by cafe::Collection< T >::const_iterator::operator *().

template<class T>
typedef T* cafe::Collection< T >::pointer_type
 

Definition at line 29 of file Collection.hpp.

Referenced by cafe::Collection< T >::iterator::operator->().

template<class T>
typedef T& cafe::Collection< T >::reference_type
 

Definition at line 30 of file Collection.hpp.

Referenced by cafe::Collection< T >::iterator::operator *().

template<class T>
typedef size_t cafe::Collection< T >::size_type
 

Definition at line 28 of file Collection.hpp.

template<class T>
typedef T cafe::Collection< T >::value_type
 

Definition at line 27 of file Collection.hpp.


Constructor & Destructor Documentation

template<class T>
cafe::Collection< T >::Collection TObjArray *  data  )  [inline]
 

Pass in array.

The TObjArray will not be deleted when Collection goes out of scope.

Definition at line 36 of file Collection.hpp.

References cafe::Collection< T >::_data.

template<class T>
cafe::Collection< T >::Collection const Collection< T > &  other  )  [inline]
 

Copy constructor.

TObjArray won't be deleted unless it is owned and the last one.

Definition at line 47 of file Collection.hpp.

References cafe::Collection< T >::_data, and cafe::Collection< T >::array_holder::inc().

template<class T>
cafe::Collection< T >::Collection void   )  [inline]
 

Default constructor.

New tobj array. Will be deleted when it does out of scope.

Definition at line 54 of file Collection.hpp.

References cafe::Collection< T >::_data.

template<class T>
virtual cafe::Collection< T >::~Collection  )  [inline, virtual]
 

Delete the collection if there are no more elemements in it.

Definition at line 59 of file Collection.hpp.

References cafe::Collection< T >::_data, and cafe::Collection< T >::array_holder::decAndDeleteIf().


Member Function Documentation

template<class T>
const_iterator cafe::Collection< T >::begin  )  const [inline]
 

Definition at line 102 of file Collection.hpp.

References cafe::Collection< T >::_data.

template<class T>
iterator cafe::Collection< T >::begin  )  [inline]
 

Iterators to first element in collection.

Definition at line 101 of file Collection.hpp.

References cafe::Collection< T >::_data.

Referenced by cafe::Event::isMC(), cafe::Event::isRun2b(), cafe::Trigger::processEvent(), cafe::SelectUserObjects< T >::processEvent(), cafe::RandomSelectUserObjects< T >::processEvent(), and cafe::AssociatedTracks::processEvent().

template<class T>
cafe::Collection< T >::ClassDef Collection< T >  ,
 

template<class T>
const_iterator cafe::Collection< T >::end  )  const [inline]
 

Definition at line 106 of file Collection.hpp.

References cafe::Collection< T >::_data.

template<class T>
iterator cafe::Collection< T >::end  )  [inline]
 

Iterator to one past the last element in collection.

Definition at line 105 of file Collection.hpp.

References cafe::Collection< T >::_data.

Referenced by cafe::Event::isMC(), cafe::Event::isRun2b(), cafe::Trigger::processEvent(), cafe::SelectUserObjects< T >::processEvent(), cafe::RandomSelectUserObjects< T >::processEvent(), and cafe::AssociatedTracks::processEvent().

template<class T>
iterator cafe::Collection< T >::erase iterator  first,
iterator  last
[inline]
 

Erase entries between iterator positions first and last.

Definition at line 119 of file Collection.hpp.

References cafe::Collection< T >::_data, cafe::Collection< T >::iterator::_index, and cafe::Collection< T >::make_us_owner_of_data().

template<class T>
iterator cafe::Collection< T >::erase iterator  it  )  [inline]
 

Erase entry at iterator position. Return 'next' position.

Definition at line 109 of file Collection.hpp.

References cafe::Collection< T >::_data, cafe::Collection< T >::iterator::_index, and cafe::Collection< T >::make_us_owner_of_data().

template<class T>
template<typename compare>
void cafe::Collection< T >::full_sort TObjArray &  array,
int const   from,
int const   to,
compare  CompFun
[inline, private]
 

Definition at line 383 of file Collection.hpp.

References cafe::Collection< T >::insert_sort(), and cafe::Collection< T >::partial_quicksort().

Referenced by cafe::Collection< T >::sort().

template<class T>
template<typename compare>
void cafe::Collection< T >::insert_sort TObjArray &  array,
int const   from,
int const   to,
compare  CompFun
[inline, private]
 

Definition at line 316 of file Collection.hpp.

Referenced by cafe::Collection< T >::full_sort().

template<class T>
void cafe::Collection< T >::make_us_owner_of_data void   )  [inline, private]
 

If we don't own the data array, make a copy and assume ownership.

This is so we can add to a static item.

Definition at line 302 of file Collection.hpp.

References cafe::Collection< T >::_data, cafe::Collection< T >::array_holder::decAndDeleteIf(), and cafe::Collection< T >::array_holder::isOwned().

Referenced by cafe::Collection< T >::erase(), cafe::Collection< T >::push_back(), and cafe::Collection< T >::sort().

template<class T>
Collection<T>& cafe::Collection< T >::operator= const Collection< T > &  other  )  [inline]
 

Assign other collection to this one.

Definition at line 64 of file Collection.hpp.

References cafe::Collection< T >::_data, cafe::Collection< T >::array_holder::decAndDeleteIf(), and cafe::Collection< T >::array_holder::inc().

template<class T>
const T& cafe::Collection< T >::operator[] size_t  index  )  const [inline]
 

Easy [] access.

Definition at line 93 of file Collection.hpp.

template<class T>
template<typename compare>
void cafe::Collection< T >::partial_quicksort TObjArray &  array,
int  indLow,
int  indHigh,
compare  CompFun
[inline, private]
 

Definition at line 337 of file Collection.hpp.

References cafe::Collection< T >::swap().

Referenced by cafe::Collection< T >::full_sort().

template<class T>
void cafe::Collection< T >::push_back T *  item  )  [inline]
 

Add an item to the array.

The collection will delete this item when it is done.

Definition at line 86 of file Collection.hpp.

References cafe::Collection< T >::make_us_owner_of_data().

template<class T>
void cafe::Collection< T >::push_back const T &  item  )  [inline]
 

Add an item to the array.

This item must be have been dynamically allocated and not on the stack. The Collection does not take ownership of the item.

Definition at line 77 of file Collection.hpp.

References cafe::Collection< T >::make_us_owner_of_data().

Referenced by cafe::StatSample::ListEventWeights().

template<class T>
size_t cafe::Collection< T >::size  )  const [inline]
 

Return size of collection.

Definition at line 134 of file Collection.hpp.

References cafe::Collection< T >::_data.

Referenced by cafe::Event::getTMBLeBob(), cafe::Trigger::processEvent(), and cafe::AssociatedTracks::processEvent().

template<class T>
template<typename compare>
void cafe::Collection< T >::sort iterator  from,
iterator  to,
compare  CompFun
[inline]
 

Sort a cafe::Collection<T>.

The predicate CompFun should be a function or a class that provides a boolean result. This predicate should be callable like

bool lessThan(T const& a, T const& b);

and should return true if a belongs before b in the sorted collection.

Definition at line 147 of file Collection.hpp.

References cafe::Collection< T >::_data, cafe::Collection< T >::iterator::_index, cafe::Collection< T >::full_sort(), and cafe::Collection< T >::make_us_owner_of_data().

template<class T>
void cafe::Collection< T >::swap TObjArray &  array,
int  i,
int  j
[inline, private]
 

Definition at line 394 of file Collection.hpp.

Referenced by cafe::Collection< T >::partial_quicksort().


Member Data Documentation

template<class T>
array_holder* cafe::Collection< T >::_data [private]
 

Holds pointer to the TObjArray and a reference count.

Prevent root from trying to save it for now.

Definition at line 298 of file Collection.hpp.

Referenced by cafe::Collection< T >::begin(), cafe::Collection< T >::Collection(), cafe::Collection< T >::end(), cafe::Collection< T >::erase(), cafe::Collection< T >::make_us_owner_of_data(), cafe::Collection< T >::operator=(), cafe::Collection< T >::size(), cafe::Collection< T >::sort(), and cafe::Collection< T >::~Collection().


The documentation for this class was generated from the following file:
Generated on Thu Apr 3 04:14:27 2008 for CAF by doxygen 1.3.4