Gaudi Framework, version v22r4

Home   Generated: Fri Sep 2 2011
Public Types | Public Member Functions | Private Member Functions | Private Attributes

TransientFastContainer< T, CLEANER > Class Template Reference

Container providing internal memory management. More...

#include <GaudiKernel/TransientFastContainer.h>

Inheritance diagram for TransientFastContainer< T, CLEANER >:
Inheritance graph
[legend]
Collaboration diagram for TransientFastContainer< T, CLEANER >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T contained_type
typedef contained_typevalue_type
typedef value_type pointer
typedef const value_type const_pointer
typedef value_type reference
typedef const value_type const_reference
typedef std::vector< value_typestorage_type
typedef storage_type::size_type size_type
typedef storage_type::iterator iterator
typedef
storage_type::const_iterator 
const_iterator
typedef CLEANER cleaner_type

Public Member Functions

 TransientFastContainer (size_type n=0)
 Standard constructor. If the argument n is not zero, n objects are instantiated.
virtual ~TransientFastContainer ()
 Delete all the recorded objects.
virtual void clear ()
 Set the internal counter to 0 without actually deleting the objects.
virtual void free ()
 Delete all the contained objects to free memory.
virtual const std::type_infocontainedType () const
 Return type information on the contained objects.
pointer New ()
 Add a new object to the container or reuse one of the already available objects (after cleaning), and return a pointer to it.
pointer Add (const T &rhs)
 Add a new object to the container or reuse one of the already available objects (after cleaning), and return a pointer to it.
pointer NewPointer ()
 Get a pointer to a non-initialized chunk of memory either destructing an already existing object or creating a new one and destructing it.
iterator begin ()
 Iterator pointing to the first object of the container.
const_iterator begin () const
 Const iterator pointing to the first object of the container.
iterator end ()
 Iterator pointing after the last used object in the container.
const_iterator end () const
 Const iterator pointing after the last used object in the container.
size_type size () const
 Returns the number of used objects in the container.
pointer operator[] (size_type index)
 Accessor to the object at the given index. Throws std::out_of_range if index is greater than size().
const contained_typeoperator[] (size_type index) const
 Const accessor to the object at the given index. Throws std::out_of_range if index is greater than size().
pointer at (size_type index)
 Same as operator[]().
const contained_typeat (size_type index) const
 Same as operator[]() const.

Private Member Functions

pointer i_new ()
 Implementation function that instantiate a new object.
pointer i_new (const T &rhs)
 Implementation function that instantiate a new object using the copy constructor.

Private Attributes

size_type m_counter
 Internal counter.
size_type m_current_size
 Number of already allocated objects.
storage_type m_storage
 Repository of allocated objects.
iterator m_end
 Iterator that is returned by end().
cleaner_type m_cleaner
 Instance of the class that cleans new objects.

Detailed Description

template<class T, class CLEANER = DefaultObjectCleaner<T>>
class TransientFastContainer< T, CLEANER >

Container providing internal memory management.

New objects are added to the container using the member function New(). Those are not deleted until destruction of the container. When the method clear() is called, the internal of the container is set to 0 and it behaves as if it is, but it still has memory of all the created object. When the New() is invoked on a "cleared" container, it returns the pointer of the first non-used of the known objects after calling an instance of CLEANER on it, or a new object if all the know objects are already in use.

Author:
Marco Clemencic
Date:
2006-05-02

Definition at line 83 of file TransientFastContainer.h.


Member Typedef Documentation

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef CLEANER TransientFastContainer< T, CLEANER >::cleaner_type

Definition at line 102 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef storage_type::const_iterator TransientFastContainer< T, CLEANER >::const_iterator

Definition at line 100 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef const value_type TransientFastContainer< T, CLEANER >::const_pointer

Definition at line 90 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef const value_type TransientFastContainer< T, CLEANER >::const_reference

Definition at line 93 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef T TransientFastContainer< T, CLEANER >::contained_type

Definition at line 86 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef storage_type::iterator TransientFastContainer< T, CLEANER >::iterator

Definition at line 99 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef value_type TransientFastContainer< T, CLEANER >::pointer

Definition at line 89 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef value_type TransientFastContainer< T, CLEANER >::reference

Definition at line 92 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef storage_type::size_type TransientFastContainer< T, CLEANER >::size_type

Definition at line 97 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef std::vector<value_type> TransientFastContainer< T, CLEANER >::storage_type

Definition at line 95 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
typedef contained_type* TransientFastContainer< T, CLEANER >::value_type

Definition at line 87 of file TransientFastContainer.h.


Constructor & Destructor Documentation

template<class T , class CLEANER >
TransientFastContainer< T, CLEANER >::TransientFastContainer ( size_type  n = 0 )

Standard constructor. If the argument n is not zero, n objects are instantiated.

Definition at line 186 of file TransientFastContainer.h.

template<class T , class CLEANER >
TransientFastContainer< T, CLEANER >::~TransientFastContainer (  ) [virtual]

Delete all the recorded objects.

Definition at line 202 of file TransientFastContainer.h.

{
  free();
}

Member Function Documentation

template<class T, class CLEANER = DefaultObjectCleaner<T>>
pointer TransientFastContainer< T, CLEANER >::Add ( const T &  rhs ) [inline]

Add a new object to the container or reuse one of the already available objects (after cleaning), and return a pointer to it.

Definition at line 129 of file TransientFastContainer.h.

{ return ( m_counter++ < m_current_size ) ? m_cleaner(*(m_end++),rhs) : i_new(rhs); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
pointer TransientFastContainer< T, CLEANER >::at ( size_type  index ) [inline]

Same as operator[]().

Definition at line 157 of file TransientFastContainer.h.

{ return operator[] (index); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
const contained_type* TransientFastContainer< T, CLEANER >::at ( size_type  index ) const [inline]

Same as operator[]() const.

Definition at line 159 of file TransientFastContainer.h.

{ return operator[] (index); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
const_iterator TransientFastContainer< T, CLEANER >::begin ( void   ) const [inline]

Const iterator pointing to the first object of the container.

Definition at line 139 of file TransientFastContainer.h.

{ return m_storage.begin(); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
iterator TransientFastContainer< T, CLEANER >::begin ( void   ) [inline]

Iterator pointing to the first object of the container.

Definition at line 137 of file TransientFastContainer.h.

{ return m_storage.begin(); }
template<class T , class CLEANER >
void TransientFastContainer< T, CLEANER >::clear ( void   ) [virtual]

Set the internal counter to 0 without actually deleting the objects.

Implements TransientFastContainerBase.

Definition at line 209 of file TransientFastContainer.h.

                                              {
  m_counter = 0;
  m_end = m_storage.begin();
}
template<class T, class CLEANER = DefaultObjectCleaner<T>>
virtual const std::type_info& TransientFastContainer< T, CLEANER >::containedType (  ) const [inline, virtual]

Return type information on the contained objects.

Implements TransientFastContainerBase.

Definition at line 119 of file TransientFastContainer.h.

{ return typeid(contained_type); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
iterator TransientFastContainer< T, CLEANER >::end ( void   ) [inline]

Iterator pointing after the last used object in the container.

Definition at line 142 of file TransientFastContainer.h.

{ return m_end; }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
const_iterator TransientFastContainer< T, CLEANER >::end ( void   ) const [inline]

Const iterator pointing after the last used object in the container.

Definition at line 144 of file TransientFastContainer.h.

{ return m_end; }
template<class T , class CLEANER >
void TransientFastContainer< T, CLEANER >::free (  ) [virtual]

Delete all the contained objects to free memory.

Implements TransientFastContainerBase.

Definition at line 215 of file TransientFastContainer.h.

                                             {
  for( typename storage_type::iterator i = m_storage.begin();
       i != m_storage.end();
       ++i ) {
    delete *i;
  }
  m_storage.clear();
  m_counter = m_current_size = 0;
  m_end = m_storage.begin();
}
template<class T , class CLEANER >
TransientFastContainer< T, CLEANER >::pointer TransientFastContainer< T, CLEANER >::i_new ( const T &  rhs ) [private]

Implementation function that instantiate a new object using the copy constructor.

Definition at line 237 of file TransientFastContainer.h.

                                                                                                       {
  //++m_counter; // already incremented in New()
  ++m_current_size;
  pointer ptr = new T(rhs);
  m_storage.push_back(ptr);
  m_end = m_storage.end();
  return ptr;
}
template<class T , class CLEANER >
TransientFastContainer< T, CLEANER >::pointer TransientFastContainer< T, CLEANER >::i_new (  ) [private]

Implementation function that instantiate a new object.

Definition at line 227 of file TransientFastContainer.h.

                                                                                           {
  //++m_counter; // already incremented in New()
  ++m_current_size;
  pointer ptr = new T();
  m_storage.push_back(ptr);
  m_end = m_storage.end();
  return ptr;
}
template<class T, class CLEANER = DefaultObjectCleaner<T>>
pointer TransientFastContainer< T, CLEANER >::New (  ) [inline]

Add a new object to the container or reuse one of the already available objects (after cleaning), and return a pointer to it.

Definition at line 125 of file TransientFastContainer.h.

{ return ( m_counter++ < m_current_size ) ? m_cleaner(*(m_end++)) : i_new(); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
pointer TransientFastContainer< T, CLEANER >::NewPointer (  ) [inline]

Get a pointer to a non-initialized chunk of memory either destructing an already existing object or creating a new one and destructing it.

Definition at line 133 of file TransientFastContainer.h.

  { return ( m_counter++ < m_current_size ) ?  m_cleaner.destruct(*(m_end++)) : m_cleaner.destruct(i_new()); }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
const contained_type* TransientFastContainer< T, CLEANER >::operator[] ( size_type  index ) const [inline]

Const accessor to the object at the given index. Throws std::out_of_range if index is greater than size().

Definition at line 153 of file TransientFastContainer.h.

  { return (index < size()) ? m_storage[index] : throw std::out_of_range("index out of range"), (const_pointer)NULL; }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
pointer TransientFastContainer< T, CLEANER >::operator[] ( size_type  index ) [inline]

Accessor to the object at the given index. Throws std::out_of_range if index is greater than size().

Definition at line 150 of file TransientFastContainer.h.

  { return (index < size()) ? m_storage[index] : throw std::out_of_range("index out of range"), (pointer)NULL; }
template<class T, class CLEANER = DefaultObjectCleaner<T>>
size_type TransientFastContainer< T, CLEANER >::size ( void   ) const [inline]

Returns the number of used objects in the container.

Definition at line 147 of file TransientFastContainer.h.

{ return m_counter; }

Member Data Documentation

template<class T, class CLEANER = DefaultObjectCleaner<T>>
cleaner_type TransientFastContainer< T, CLEANER >::m_cleaner [private]

Instance of the class that cleans new objects.

Definition at line 182 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
size_type TransientFastContainer< T, CLEANER >::m_counter [private]

Internal counter.

Definition at line 170 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
size_type TransientFastContainer< T, CLEANER >::m_current_size [private]

Number of already allocated objects.

Definition at line 173 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
iterator TransientFastContainer< T, CLEANER >::m_end [private]

Iterator that is returned by end().

Definition at line 179 of file TransientFastContainer.h.

template<class T, class CLEANER = DefaultObjectCleaner<T>>
storage_type TransientFastContainer< T, CLEANER >::m_storage [private]

Repository of allocated objects.

Definition at line 176 of file TransientFastContainer.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Fri Sep 2 2011 16:25:50 for Gaudi Framework, version v22r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004