| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 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 76 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 81 of file Range.h.

template<class CONTAINER>

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

type for actual contained iterator

Definition at line 86 of file Range.h.

template<class CONTAINER>

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

Definition at line 87 of file Range.h.

template<class CONTAINER>

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

Definition at line 88 of file Range.h.

template<class CONTAINER>

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

Definition at line 89 of file Range.h.

template<class CONTAINER>

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

Definition at line 90 of file Range.h.

template<class CONTAINER>

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

Definition at line 91 of file Range.h.

template<class CONTAINER>

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

Definition at line 92 of file Range.h.

template<class CONTAINER>

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

Definition at line 93 of file Range.h.

template<class CONTAINER>

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

internal types

Definition at line 95 of file Range.h.

template<class CONTAINER>

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

Definition at line 96 of file Range.h.

## Constructor & Destructor Documentation

template<class CONTAINER>

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

default constructor

Definition at line 101 of file Range.h.

    00101 : 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 106 of file Range.h.

    00106 : 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 110 of file Range.h.

    00110 : 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 114 of file Range.h.

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

template<class CONTAINER>

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

Definition at line 118 of file Range.h.

    00118 : m_base( ibegin , ibegin ) {};

template<class CONTAINER>

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

destructor

Definition at line 120 of file Range.h.

    00120 {};

## Member Function Documentation

template<class CONTAINER>

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

empty sequence ?

Definition at line 123 of file Range.h.

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

template<class CONTAINER>

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

size of the sequence (number of elements)

Definition at line 125 of file Range.h.

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

template<class CONTAINER>

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

access to begin of the sequence (const version )

Definition at line 128 of file Range.h.

    00128 { return m_base.first  ; }

template<class CONTAINER>

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

access to end of the sequence (const version)

Definition at line 130 of file Range.h.

    00130 { return m_base.second ; }

template<class CONTAINER>

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

access to begin of the reversed sequence (const)

Definition at line 132 of file Range.h.

    00132 { return reverse_iterator ( end   () ) ; }

template<class CONTAINER>

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

access to begin of the reversed sequence (const)

Definition at line 134 of file Range.h.

    00134 { return reverse_iterator ( begin () ) ; }

template<class CONTAINER>

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

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

Definition at line 136 of file Range.h.

    00136 { return *( begin ()     ) ; }

template<class CONTAINER>

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

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

Definition at line 138 of file Range.h.

    00139     {
    00140       const_iterator i = end() ;
    00141       std::advance ( i , -1 ) ;
    00142       return *i ;
    00143     }

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

    00147     {
    00148       // trivial cases
    00149       if ( empty() || index1 == index2 ) { return Range_() ; } // RETURN
    00150       // adjust indices
    00151       if ( index1 < 0      ) { index1 += size () ; }
    00152       if ( index2 < 0      ) { index2 += size () ; }
    00153       // check
    00154       if ( index1 < 0      ) { return  Range_ () ; }            // RETURN
    00155       if ( index2 < index1 ) { return  Range_ () ; }            // RETURN
    00156
    00157       if ( index1 > (long) size () ) { return  Range_() ; }     // RETURN
    00158       if ( index2 > (long) size () ) { index2  = size() ; }
    00159
    00160       const_iterator i1 = begin()  ;
    00161       std::advance ( i1 , index1 ) ;
    00162       const_iterator i2 = begin()  ;
    00163       std::advance ( i2 , index2 ) ;
    00164       // construct the slice
    00165       return Range_( i1 , i2 ) ;                                 // RETURN
    00166     }

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

    00173     {
    00174       const_iterator i = begin() ;
    00175       std::advance ( i , index ) ;
    00176       return *i ;
    00177     }

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

    00183     { 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 189 of file Range.h.

    00190     {
    00191       if ( index < 0 || index >= (long) size () )
    00192       { Gaudi::details::rangeException( index , size() ) ; }
    00193       return (*this) ( index );
    00194     }

template<class CONTAINER>

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

compare with another range

Definition at line 199 of file Range.h.

    00200     {
    00201       return std::lexicographical_compare
    00202         ( begin () , end () , right.begin () , right.end () ) ;
    00203     }

template<class CONTAINER>

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

compare with the base container

Definition at line 205 of file Range.h.

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

template<class CONTAINER>

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

equality with another range

Definition at line 214 of file Range.h.

    00215     {
    00216       if ( &right        == this    ) { return true  ; } // RETURN
    00217       if ( right.size () != size () ) { return false ; } // RETURN
    00218       return std::equal ( begin () , end () , right.begin() ) ;
    00219     }

template<class CONTAINER>

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

equality with the base container

Definition at line 221 of file Range.h.

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

template<class CONTAINER>

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

empty sequence?

Definition at line 230 of file Range.h.

    00230 { return  empty () ; }

template<class CONTAINER>

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

conversion operator to the std::pair

Definition at line 235 of file Range.h.

    00235 { return   base () ; }

template<class CONTAINER>

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

conversion operator to the std::pair

Definition at line 237 of file Range.h.

    00237 { return m_base    ; }

## Member Data Documentation

template<class CONTAINER>

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

the base itself

Definition at line 242 of file Range.h.

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

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