| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# 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 >:

[legend]
Collaboration diagram for Gaudi::Range_< CONTAINER >:

[legend]

List of all members.

## Public Types
typedef std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator > | Base
typedef CONTAINER | Container
| type for actual contained iterator
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
typedef Range_< Container > | _Self
## Public Member Functions
| Range_ ()
| default constructor
| Range_ (iterator ibegin, iterator iend)
| Constructor.
| Range_ (const Base &base)
| constructor from the pair of iterators
| Range_ (const Container &cont)
| constructor from the container
| Range_ (iterator ibegin)
| ~Range_ ()
| destructor
bool | empty () const
| empty sequence ?
size_t | size () const
| size of the sequence (number of elements)
iterator | begin () const
| access to begin of the sequence (const version )
iterator | end () const
| access to end of the sequence (const version)
reverse_iterator | rbegin () const
| access to begin of the reversed sequence (const)
reverse_iterator | rend () const
| access to begin of the reversed sequence (const)
const_reference | front () const
| access for the first element (only for non-empty ranges!)
const_reference | back () const
| access for the back element (only for non-empty ranges!)
Range_ | slice (long index1, long index2) const
| get a "slice" of a range, in Python style
const_reference | operator() (const size_t index) const
| non-checked access to the elements by index (valid only for non-empty sequences)
const_reference | operator[] (const long index) const
| non-checked access to the elements by index (valid only for non-empty sequences)
const_reference | at (const long index) const
  | Checked access to the elements by index (valid for all sequences) Exceptions:
  | GaudiException | for out-of-range access.
bool | operator< (const Range_ &right) const
| compare with another range
bool | operator< (const Container &right) const
| compare with the base container
bool | operator== (const Range_ &right) const
| equality with another range
bool | operator== (const Container &right) const
| equality with the base container
bool | operator! () const
| empty sequence?
| operator const Base & () const
| conversion operator to the std::pair
const Base & | base () const
| conversion operator to the std::pair
## Private Attributes
Base | m_base
| the base itself

## 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.Belyaev@itep.ru

Date:
  2002-07-12

Definition at line 84 of file Range.h.

## Member Typedef Documentation

template<class CONTAINER>

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

Definition at line 89 of file Range.h.

template<class CONTAINER>

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

type for actual contained iterator

Definition at line 94 of file Range.h.

template<class CONTAINER>

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

Definition at line 95 of file Range.h.

template<class CONTAINER>

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

Definition at line 96 of file Range.h.

template<class CONTAINER>

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

Definition at line 97 of file Range.h.

template<class CONTAINER>

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

Definition at line 98 of file Range.h.

template<class CONTAINER>

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

Definition at line 99 of file Range.h.

template<class CONTAINER>

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

Definition at line 100 of file Range.h.

template<class CONTAINER>

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

Definition at line 101 of file Range.h.

template<class CONTAINER>

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

internal types

Definition at line 103 of file Range.h.

template<class CONTAINER>

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

Definition at line 104 of file Range.h.

## Constructor & Destructor Documentation

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( |  | ) | `[inline]`

default constructor

Definition at line 109 of file Range.h.

    00109 : m_base( iterator() , iterator() ) {};

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( | iterator | ibegin,
|  | iterator | iend |
| ) |  |  | `[inline]`

Constructor.

Parameters:

  | ibegin | iterator to begin of the sequence
  | iend | iterator to end of the sequence

Definition at line 114 of file Range.h.

    00114 : m_base ( ibegin , iend ) {} ;

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( | const Base & | base | ) | `[inline]`

constructor from the pair of iterators

Parameters:

  | base | pair of the iterators

Definition at line 118 of file Range.h.

    00118 : m_base( base ) {};

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( | const Container & | cont | ) | `[inline]`

constructor from the container

Parameters:

  | cont | reference to the container

Definition at line 122 of file Range.h.

    00122 : m_base( cont.begin() , cont.end() ) {} ;

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( | iterator | ibegin | ) | `[inline]`

Definition at line 126 of file Range.h.

    00126 : m_base( ibegin , ibegin ) {};

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::~Range_ | ( |  | ) | `[inline]`

destructor

Definition at line 128 of file Range.h.

    00128 {};

## Member Function Documentation

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::empty | ( | void |  | ) | const`[inline]`

empty sequence ?

Definition at line 131 of file Range.h.

    00131 { return m_base.second == m_base.first  ; }

template<class CONTAINER>

size_t Gaudi::Range_< CONTAINER >::size | ( | void |  | ) | const`[inline]`

size of the sequence (number of elements)

Definition at line 133 of file Range.h.

    00134     { return std::distance ( m_base.first  , m_base.second  ) ; }

template<class CONTAINER>

iterator Gaudi::Range_< CONTAINER >::begin | ( | void |  | ) | const`[inline]`

access to begin of the sequence (const version )

Definition at line 136 of file Range.h.

    00136 { return m_base.first  ; }

template<class CONTAINER>

iterator Gaudi::Range_< CONTAINER >::end | ( | void |  | ) | const`[inline]`

access to end of the sequence (const version)

Definition at line 138 of file Range.h.

    00138 { return m_base.second ; }

template<class CONTAINER>

reverse_iterator Gaudi::Range_< CONTAINER >::rbegin | ( | void |  | ) | const`[inline]`

access to begin of the reversed sequence (const)

Definition at line 140 of file Range.h.

    00140 { return reverse_iterator ( end   () ) ; }

template<class CONTAINER>

reverse_iterator Gaudi::Range_< CONTAINER >::rend | ( | void |  | ) | const`[inline]`

access to begin of the reversed sequence (const)

Definition at line 142 of file Range.h.

    00142 { return reverse_iterator ( begin () ) ; }

template<class CONTAINER>

const_reference Gaudi::Range_< CONTAINER >::front | ( | void |  | ) | const`[inline]`

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

Definition at line 144 of file Range.h.

    00144 { return *( begin ()     ) ; }

template<class CONTAINER>

const_reference Gaudi::Range_< CONTAINER >::back | ( | void |  | ) | const`[inline]`

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

Definition at line 146 of file Range.h.

    00147     {
    00148       const_iterator i = end() ;
    00149       std::advance ( i , -1 ) ;
    00150       return *i ;
    00151     }

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 154 of file Range.h.

    00155     {
    00156       // trivial cases
    00157       if ( empty() || index1 == index2 ) { return Range_() ; } // RETURN
    00158       // adjust indices
    00159       if ( index1 < 0      ) { index1 += size () ; }
    00160       if ( index2 < 0      ) { index2 += size () ; }
    00161       // check
    00162       if ( index1 < 0      ) { return  Range_ () ; }            // RETURN
    00163       if ( index2 < index1 ) { return  Range_ () ; }            // RETURN
    00164
    00165       if ( index1 > (long) size () ) { return  Range_() ; }     // RETURN
    00166       if ( index2 > (long) size () ) { index2  = size() ; }
    00167
    00168       const_iterator i1 = begin()  ;
    00169       std::advance ( i1 , index1 ) ;
    00170       const_iterator i2 = begin()  ;
    00171       std::advance ( i2 , index2 ) ;
    00172       // construct the slice
    00173       return Range_( i1 , i2 ) ;                                 // RETURN
    00174     }

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:

  | index | the index of the lement to be accessed

Definition at line 180 of file Range.h.

    00181     {
    00182       const_iterator i = begin() ;
    00183       std::advance ( i , index ) ;
    00184       return *i ;
    00185     }

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:

  | index | the index of the lement to be accessed

Definition at line 190 of file Range.h.

    00191     { return (*this)( index ) ; }

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:

  | GaudiException | for out-of-range access.

Parameters:

  | index | the index of the element to be accessed

Definition at line 197 of file Range.h.

    00198     {
    00199       if ( index < 0 || index >= (long) size () )
    00200       { Gaudi::details::rangeException( index , size() ) ; }
    00201       return (*this) ( index );
    00202     }

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::operator< | ( | const Range_< CONTAINER > & | right | ) | const`[inline]`

compare with another range

Definition at line 207 of file Range.h.

    00208     {
    00209       return std::lexicographical_compare
    00210         ( begin () , end () , right.begin () , right.end () ) ;
    00211     }

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::operator< | ( | const Container & | right | ) | const`[inline]`

compare with the base container

Definition at line 213 of file Range.h.

    00214     {
    00215       return std::lexicographical_compare
    00216         ( begin () , end () , right.begin () , right.end () ) ;
    00217     }

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::operator== | ( | const Range_< CONTAINER > & | right | ) | const`[inline]`

equality with another range

Definition at line 222 of file Range.h.

    00223     {
    00224       if ( &right        == this    ) { return true  ; } // RETURN
    00225       if ( right.size () != size () ) { return false ; } // RETURN
    00226       return std::equal ( begin () , end () , right.begin() ) ;
    00227     }

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::operator== | ( | const Container & | right | ) | const`[inline]`

equality with the base container

Definition at line 229 of file Range.h.

    00230     {
    00231       if ( right.size () != size () ) { return false ; } // RETURN
    00232       return std::equal ( begin () , end () , right.begin() ) ;
    00233     }

template<class CONTAINER>

bool Gaudi::Range_< CONTAINER >::operator! | ( |  | ) | const`[inline]`

empty sequence?

Definition at line 238 of file Range.h.

    00238 { return  empty () ; }

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::operator const Base & | ( |  | ) | const`[inline]`

conversion operator to the std::pair

Definition at line 243 of file Range.h.

    00243 { return   base () ; }

template<class CONTAINER>

const Base& Gaudi::Range_< CONTAINER >::base | ( |  | ) | const`[inline]`

conversion operator to the std::pair

Definition at line 245 of file Range.h.

    00245 { return m_base    ; }

## Member Data Documentation

template<class CONTAINER>

Base Gaudi::Range_< CONTAINER >::m_base`[private]`

the base itself

Definition at line 250 of file Range.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r8/GaudiKernel/GaudiKernel/Range.h