All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi::Range_< CONTAINER > Class Template Reference

Useful class for representation of "sequence" of the objects through the range of valid iterators. More...

#include <GaudiUtils/Range.h>

Inheritance diagram for Gaudi::Range_< CONTAINER >:
Collaboration diagram for Gaudi::Range_< CONTAINER >:

Public Types

typedef std::pair< typename
CONTAINER::const_iterator,
typename
CONTAINER::const_iterator > 
Base
 
typedef CONTAINER Container
 type for actual contained iterator More...
 
typedef Container::value_type value_type
 
typedef Container::const_iterator iterator
 
typedef Container::const_iterator const_iterator
 
typedef
Container::const_reverse_iterator 
reverse_iterator
 
typedef
Container::const_reverse_iterator 
const_reverse_iterator
 
typedef Container::const_reference reference
 
typedef Container::const_reference const_reference
 
typedef std::pair< iterator,
iterator
_Base
 internal types More...
 
typedef Range_< Container_Self
 

Public Member Functions

 Range_ ()
 default constructor More...
 
 Range_ (iterator ibegin, iterator iend)
 Constructor. More...
 
 Range_ (const Base &base)
 constructor from the pair of iterators More...
 
 Range_ (const Container &cont)
 constructor from the container More...
 
 Range_ (iterator ibegin)
 
 ~Range_ ()
 destructor More...
 
bool empty () const
 empty sequence ? More...
 
size_t size () const
 size of the sequence (number of elements) More...
 
iterator begin () const
 access to begin of the sequence (const version ) More...
 
iterator end () const
 access to end of the sequence (const version) More...
 
reverse_iterator rbegin () const
 access to begin of the reversed sequence (const) More...
 
reverse_iterator rend () const
 access to begin of the reversed sequence (const) More...
 
const_reference front () const
 access for the first element (only for non-empty ranges!) More...
 
const_reference back () const
 access for the back element (only for non-empty ranges!) More...
 
Range_ slice (long index1, long index2) const
 get a "slice" of a range, in Python style More...
 
const_reference operator() (const size_t index) const
 non-checked access to the elements by index (valid only for non-empty sequences) More...
 
const_reference operator[] (const long index) const
 non-checked access to the elements by index (valid only for non-empty sequences) More...
 
const_reference at (const long index) const
 Checked access to the elements by index (valid for all sequences)

Exceptions
GaudiExceptionfor out-of-range access.
More...
 
bool operator< (const Range_ &right) const
 compare with another range More...
 
bool operator< (const Container &right) const
 compare with the base container More...
 
bool operator== (const Range_ &right) const
 equality with another range More...
 
bool operator== (const Container &right) const
 equality with the base container More...
 
bool operator! () const
 empty sequence? More...
 
 operator const Base & () const
 conversion operator to the std::pair More...
 
const Basebase () const
 conversion operator to the std::pair More...
 

Private Attributes

Base m_base
 the base itself More...
 

Detailed Description

template<class CONTAINER>
class Gaudi::Range_< CONTAINER >

Useful class for representation of "sequence" of the objects through the range of valid iterators.

The range could be created over ALL container types which supports at least bidirectional iterators.

The minimum requirements from the container type:

  • support the concept of "CONTAINER::value_type"
  • support the concept of "CONTAINER::const_iterator"
  • support the concept of "CONTAINER::const_reference"
  • support the concept of "CONTAINER::const_reverse_iterator"
  • the iterator should be ok for "std::distance" and "std::advance"
  • support for "const_iterator CONTAINER::begin () const"
  • support for "const_iterator CONTAINER::end () const"
  • support for "const_reverse_iterator CONTAINER::rbegin () const"
  • support for "const_reverse_iterator CONTAINER::rend () const"
Author
Vanya Belyaev Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
2002-07-12

Definition at line 77 of file Range.h.

Member Typedef Documentation

template<class CONTAINER>
typedef std::pair<iterator,iterator> Gaudi::Range_< CONTAINER >::_Base

internal types

Definition at line 96 of file Range.h.

template<class CONTAINER>
typedef Range_<Container> Gaudi::Range_< CONTAINER >::_Self

Definition at line 97 of file Range.h.

template<class CONTAINER>
typedef std::pair<typename CONTAINER::const_iterator, typename CONTAINER::const_iterator> Gaudi::Range_< CONTAINER >::Base

Definition at line 82 of file Range.h.

template<class CONTAINER>
typedef Container::const_iterator Gaudi::Range_< CONTAINER >::const_iterator

Definition at line 90 of file Range.h.

template<class CONTAINER>
typedef Container::const_reference Gaudi::Range_< CONTAINER >::const_reference

Definition at line 94 of file Range.h.

template<class CONTAINER>
typedef Container::const_reverse_iterator Gaudi::Range_< CONTAINER >::const_reverse_iterator

Definition at line 92 of file Range.h.

template<class CONTAINER>
typedef CONTAINER Gaudi::Range_< CONTAINER >::Container

type for actual contained iterator

Definition at line 87 of file Range.h.

template<class CONTAINER>
typedef Container::const_iterator Gaudi::Range_< CONTAINER >::iterator

Definition at line 89 of file Range.h.

template<class CONTAINER>
typedef Container::const_reference Gaudi::Range_< CONTAINER >::reference

Definition at line 93 of file Range.h.

template<class CONTAINER>
typedef Container::const_reverse_iterator Gaudi::Range_< CONTAINER >::reverse_iterator

Definition at line 91 of file Range.h.

template<class CONTAINER>
typedef Container::value_type Gaudi::Range_< CONTAINER >::value_type

Definition at line 88 of file Range.h.

Constructor & Destructor Documentation

template<class CONTAINER>
Gaudi::Range_< CONTAINER >::Range_ ( )
inline

default constructor

Definition at line 102 of file Range.h.

102 : m_base( iterator() , iterator() ) {}
Base m_base
the base itself
Definition: Range.h:243
Container::const_iterator iterator
Definition: Range.h:89
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::Range_ ( iterator  ibegin,
iterator  iend 
)
inline

Constructor.

Parameters
ibeginiterator to begin of the sequence
ienditerator to end of the sequence

Definition at line 107 of file Range.h.

107 : m_base ( ibegin , iend ) {}
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::Range_ ( const Base base)
inline

constructor from the pair of iterators

Parameters
basepair of the iterators

Definition at line 111 of file Range.h.

111 : m_base( base ) {}
Base m_base
the base itself
Definition: Range.h:243
const Base & base() const
conversion operator to the std::pair
Definition: Range.h:238
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::Range_ ( const Container cont)
inline

constructor from the container

Parameters
contreference to the container

Definition at line 115 of file Range.h.

115 : m_base( cont.begin() , cont.end() ) {}
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::Range_ ( iterator  ibegin)
inline

Definition at line 119 of file Range.h.

119 : m_base( ibegin , ibegin ) {}
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::~Range_ ( )
inline

destructor

Definition at line 121 of file Range.h.

121 {}

Member Function Documentation

template<class CONTAINER>
const_reference Gaudi::Range_< CONTAINER >::at ( const long  index) const
inline

Checked access to the elements by index (valid for all sequences)

Exceptions
GaudiExceptionfor out-of-range access.

Parameters
indexthe index of the element to be accessed

Definition at line 190 of file Range.h.

191  {
192  if ( index < 0 || index >= (long) size () )
193  { Gaudi::details::rangeException( index , size() ) ; }
194  return (*this) ( index );
195  }
GAUDI_API void rangeException(const long index, const size_t size)
Helpful function to throw an "out-of-range exception" for class Range_.
Definition: Range.cpp:31
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:126
template<class CONTAINER>
const_reference Gaudi::Range_< CONTAINER >::back ( ) const
inline

access for the back element (only for non-empty ranges!)

Definition at line 139 of file Range.h.

140  {
141  const_iterator i = end() ;
142  std::advance ( i , -1 ) ;
143  return *i ;
144  }
Container::const_iterator const_iterator
Definition: Range.h:90
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
list i
Definition: ana.py:128
template<class CONTAINER>
const Base& Gaudi::Range_< CONTAINER >::base ( ) const
inline

conversion operator to the std::pair

Definition at line 238 of file Range.h.

238 { return m_base ; }
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
iterator Gaudi::Range_< CONTAINER >::begin ( ) const
inline

access to begin of the sequence (const version )

Definition at line 129 of file Range.h.

129 { return m_base.first ; }
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::empty ( ) const
inline

empty sequence ?

Definition at line 124 of file Range.h.

124 { return m_base.second == m_base.first ; }
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
iterator Gaudi::Range_< CONTAINER >::end ( ) const
inline

access to end of the sequence (const version)

Definition at line 131 of file Range.h.

131 { return m_base.second ; }
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
const_reference Gaudi::Range_< CONTAINER >::front ( ) const
inline

access for the first element (only for non-empty ranges!)

Definition at line 137 of file Range.h.

137 { return *( begin () ) ; }
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
template<class CONTAINER>
Gaudi::Range_< CONTAINER >::operator const Base & ( ) const
inline

conversion operator to the std::pair

Definition at line 236 of file Range.h.

236 { return base () ; }
const Base & base() const
conversion operator to the std::pair
Definition: Range.h:238
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::operator! ( ) const
inline

empty sequence?

Definition at line 231 of file Range.h.

231 { return empty () ; }
bool empty() const
empty sequence ?
Definition: Range.h:124
template<class CONTAINER>
const_reference Gaudi::Range_< CONTAINER >::operator() ( const size_t  index) const
inline

non-checked access to the elements by index (valid only for non-empty sequences)

Parameters
indexthe index of the lement to be accessed

Definition at line 173 of file Range.h.

174  {
175  const_iterator i = begin() ;
176  std::advance ( i , index ) ;
177  return *i ;
178  }
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
Container::const_iterator const_iterator
Definition: Range.h:90
list i
Definition: ana.py:128
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::operator< ( const Range_< CONTAINER > &  right) const
inline

compare with another range

Definition at line 200 of file Range.h.

201  {
202  return std::lexicographical_compare
203  ( begin () , end () , right.begin () , right.end () ) ;
204  }
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::operator< ( const Container right) const
inline

compare with the base container

Definition at line 206 of file Range.h.

207  {
208  return std::lexicographical_compare
209  ( begin () , end () , right.begin () , right.end () ) ;
210  }
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::operator== ( const Range_< CONTAINER > &  right) const
inline

equality with another range

Definition at line 215 of file Range.h.

216  {
217  if ( &right == this ) { return true ; } // RETURN
218  if ( right.size () != size () ) { return false ; } // RETURN
219  return std::equal ( begin () , end () , right.begin() ) ;
220  }
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:126
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
template<class CONTAINER>
bool Gaudi::Range_< CONTAINER >::operator== ( const Container right) const
inline

equality with the base container

Definition at line 222 of file Range.h.

223  {
224  if ( right.size () != size () ) { return false ; } // RETURN
225  return std::equal ( begin () , end () , right.begin() ) ;
226  }
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:126
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
template<class CONTAINER>
const_reference Gaudi::Range_< CONTAINER >::operator[] ( const long  index) const
inline

non-checked access to the elements by index (valid only for non-empty sequences)

Parameters
indexthe index of the lement to be accessed

Definition at line 183 of file Range.h.

184  { return (*this)( index ) ; }
template<class CONTAINER>
reverse_iterator Gaudi::Range_< CONTAINER >::rbegin ( ) const
inline

access to begin of the reversed sequence (const)

Definition at line 133 of file Range.h.

133 { return reverse_iterator ( end () ) ; }
Container::const_reverse_iterator reverse_iterator
Definition: Range.h:91
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:131
template<class CONTAINER>
reverse_iterator Gaudi::Range_< CONTAINER >::rend ( ) const
inline

access to begin of the reversed sequence (const)

Definition at line 135 of file Range.h.

135 { return reverse_iterator ( begin () ) ; }
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
Container::const_reverse_iterator reverse_iterator
Definition: Range.h:91
template<class CONTAINER>
size_t Gaudi::Range_< CONTAINER >::size ( ) const
inline

size of the sequence (number of elements)

Definition at line 126 of file Range.h.

127  { return std::distance ( m_base.first , m_base.second ) ; }
Base m_base
the base itself
Definition: Range.h:243
template<class CONTAINER>
Range_ Gaudi::Range_< CONTAINER >::slice ( long  index1,
long  index2 
) const
inline

get a "slice" of a range, in Python style

Definition at line 147 of file Range.h.

148  {
149  // trivial cases
150  if ( empty() || index1 == index2 ) { return Range_() ; } // RETURN
151  // adjust indices
152  if ( index1 < 0 ) { index1 += size () ; }
153  if ( index2 < 0 ) { index2 += size () ; }
154  // check
155  if ( index1 < 0 ) { return Range_ () ; } // RETURN
156  if ( index2 < index1 ) { return Range_ () ; } // RETURN
157 
158  if ( index1 > (long) size () ) { return Range_() ; } // RETURN
159  if ( index2 > (long) size () ) { index2 = size() ; }
160 
161  const_iterator i1 = begin() ;
162  std::advance ( i1 , index1 ) ;
163  const_iterator i2 = begin() ;
164  std::advance ( i2 , index2 ) ;
165  // construct the slice
166  return Range_( i1 , i2 ) ; // RETURN
167  }
bool empty() const
empty sequence ?
Definition: Range.h:124
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:126
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:129
Container::const_iterator const_iterator
Definition: Range.h:90
Range_()
default constructor
Definition: Range.h:102

Member Data Documentation

template<class CONTAINER>
Base Gaudi::Range_< CONTAINER >::m_base
private

the base itself

Definition at line 243 of file Range.h.


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