| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Private Attributes | List of all members
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]

## 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
| 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_ ()=default
| 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
  GaudiException | for 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 Base & | base () 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 75 of file Range.h.

## Member Typedef Documentation

template<class CONTAINER>

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

internal types

Definition at line 94 of file Range.h.

template<class CONTAINER>

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

Definition at line 95 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 80 of file Range.h.

template<class CONTAINER>

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

Definition at line 88 of file Range.h.

template<class CONTAINER>

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

Definition at line 92 of file Range.h.

template<class CONTAINER>

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

Definition at line 90 of file Range.h.

template<class CONTAINER>

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

type for actual contained iterator

Definition at line 85 of file Range.h.

template<class CONTAINER>

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

Definition at line 87 of file Range.h.

template<class CONTAINER>

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

Definition at line 91 of file Range.h.

template<class CONTAINER>

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

Definition at line 89 of file Range.h.

template<class CONTAINER>

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

Definition at line 86 of file Range.h.

## Constructor & Destructor Documentation

template<class CONTAINER>

Gaudi::Range_< CONTAINER >::Range_ | ( |  | ) |
| default

default constructor

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

105 : m_base ( ibegin , iend ) {}
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
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 109 of file Range.h.

109 : m_base( base ) {}
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
Gaudi::Range_::base
const Base & base() const
conversion operator to the std::pair
Definition: Range.h:226
template<class CONTAINER>

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

constructor from the container

Parameters

  cont | reference to the container

Definition at line 113 of file Range.h.

113 : m_base( cont.begin() , cont.end() ) {}
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

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

Definition at line 117 of file Range.h.

117 : m_base( ibegin , ibegin ) {}
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

Gaudi::Range_< CONTAINER >::~Range_ | ( |  | ) |
| default

destructor

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

  GaudiException | for out-of-range access.

Parameters

  index | the index of the element to be accessed

Definition at line 178 of file Range.h.

179 {
180 if ( index < 0 || index >= (long) size () )
181 { Gaudi::details::rangeException( index , size() ) ; }
182 return (*this) ( index );
183 }
Gaudi::details::rangeException
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
Gaudi::Range_::size
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:124
template<class CONTAINER>

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

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

Definition at line 137 of file Range.h.

137 { return *std::prev( end() ); }
std::prev
T prev(T...args)
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:129
template<class CONTAINER>

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

conversion operator to the std::pair

Definition at line 226 of file Range.h.

226 { return m_base ; }
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

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

access to begin of the sequence (const version )

Definition at line 127 of file Range.h.

127 { return m_base.first ; }
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

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

empty sequence ?

Definition at line 122 of file Range.h.

122 { return m_base.second == m_base.first ; }
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

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

access to end of the sequence (const version)

Definition at line 129 of file Range.h.

129 { return m_base.second ; }
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
template<class CONTAINER>

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

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

Definition at line 135 of file Range.h.

135 { return *begin() ; }
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
template<class CONTAINER>

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

conversion operator to the std::pair

Definition at line 224 of file Range.h.

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

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

empty sequence?

Definition at line 219 of file Range.h.

219 { return empty () ; }
Gaudi::Range_::empty
bool empty() const
empty sequence ?
Definition: Range.h:122
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 163 of file Range.h.

164 {
165 return *std::next ( begin() , index ) ;
166 }
std::next
T next(T...args)
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
template<class CONTAINER>

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

compare with another range

Definition at line 188 of file Range.h.

189 {
190 return std::lexicographical_compare
191 ( begin () , end () , right.begin () , right.end () ) ;
192 }
std::right
T right(T...args)
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
std::lexicographical_compare
T lexicographical_compare(T...args)
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:129
template<class CONTAINER>

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

compare with the base container

Definition at line 194 of file Range.h.

195 {
196 return std::lexicographical_compare
197 ( begin () , end () , right.begin () , right.end () ) ;
198 }
std::right
T right(T...args)
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
std::lexicographical_compare
T lexicographical_compare(T...args)
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:129
template<class CONTAINER>

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

equality with another range

Definition at line 203 of file Range.h.

204 {
205 if ( &right == this ) { return true ; } // RETURN
206 return right.size() == size() &&
207 std::equal ( begin () , end () , right.begin() ) ;
208 }
std::right
T right(T...args)
Gaudi::Range_::size
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:124
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:129
std::equal
T equal(T...args)
template<class CONTAINER>

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

equality with the base container

Definition at line 210 of file Range.h.

211 {
212 return right.size() == size() &&
213 std::equal ( begin () , end () , right.begin() ) ;
214 }
std::right
T right(T...args)
Gaudi::Range_::size
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:124
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:129
std::equal
T equal(T...args)
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 171 of file Range.h.

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

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

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

access to begin of the reversed sequence (const)

Definition at line 133 of file Range.h.

133 { return reverse_iterator ( begin () ) ; }
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
Gaudi::Range_::reverse_iterator
Container::const_reverse_iterator reverse_iterator
Definition: Range.h:89
template<class CONTAINER>

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

size of the sequence (number of elements)

Definition at line 124 of file Range.h.

125 { return std::distance ( m_base.first , m_base.second ) ; }
std::distance
T distance(T...args)
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:231
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 140 of file Range.h.

141 {
142 // trivial cases
143 if ( empty() || index1 == index2 ) { return Range_() ; } // RETURN
144 // adjust indices
145 if ( index1 < 0 ) { index1 += size () ; }
146 if ( index2 < 0 ) { index2 += size () ; }
147 // check
148 if ( index1 < 0 ) { return Range_ () ; } // RETURN
149 if ( index2 < index1 ) { return Range_ () ; } // RETURN
150
151 if ( index1 > (long) size () ) { return Range_() ; } // RETURN
152 if ( index2 > (long) size () ) { index2 = size() ; }
153
154 // construct the slice
155 return Range_( std::next ( begin() , index1 ) ,
156 std::next ( begin() , index2 ) ) ; // RETURN
157 }
Gaudi::Range_::empty
bool empty() const
empty sequence ?
Definition: Range.h:122
Gaudi::Range_::size
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:124
std::next
T next(T...args)
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:127
Gaudi::Range_::Range_
Range_()=default
default constructor

## Member Data Documentation

template<class CONTAINER>

Base Gaudi::Range_< CONTAINER >::m_base
| private

the base itself

Definition at line 231 of file Range.h.

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

- GaudiKernel/GaudiKernel/Range.h