The Gaudi Framework  master (29688f1e)
Loading...
Searching...
No Matches
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

using Container = typename Gaudi::details::container<CONTAINER>::Container
 type for actual contained iterator
using const_iterator = typename CONTAINER::const_iterator
using iterator = const_iterator
using Base = std::pair<iterator, iterator>
typedef iter_traits::value_type value_type
typedef iter_traits::reference reference
typedef iter_traits::reference const_reference
typedef std::reverse_iterator< iteratorreverse_iterator
typedef std::reverse_iterator< iteratorconst_reverse_iterator

Public Member Functions

 Range_ ()=default
 default constructor
template<typename InputIterator>
 Range_ (InputIterator first, InputIterator last)
 Constructor.
 Range_ (const Base &base)
 constructor from the pair of iterators
 Range_ (const Container &cont)
 constructor from the container
 Range_ (iterator ibegin)
 ~Range_ ()=default
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)
iterator cbegin () const
 access to begin of the sequence (const version )
iterator cend () 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).
template<class C>
bool operator< (const Range_< C > &right) const
 compare with another range
template<class ANOTHERCONTAINER>
bool operator< (const ANOTHERCONTAINER &right) const
 compare with another container
bool operator== (const Range_ &right) const
 equality with another range
template<class ANOTHERCONTAINER>
bool operator== (const ANOTHERCONTAINER &right) const
 compare with another container
bool operator! () const
 empty sequence?
 operator bool () const
 non-empty sequence?
 operator const Base & () const
 conversion operator to the std::pair
const Basebase () const
 conversion operator to the std::pair

Private Types

typedef std::iterator_traits< iteratoriter_traits

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..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
2002-07-12

Definition at line 81 of file Range.h.

Member Typedef Documentation

◆ Base

template<class CONTAINER>
using Gaudi::Range_< CONTAINER >::Base = std::pair<iterator, iterator>

Definition at line 88 of file Range.h.

◆ const_iterator

template<class CONTAINER>
using Gaudi::Range_< CONTAINER >::const_iterator = typename CONTAINER::const_iterator

Definition at line 86 of file Range.h.

◆ const_reference

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

Definition at line 96 of file Range.h.

◆ const_reverse_iterator

template<class CONTAINER>
typedef std::reverse_iterator<iterator> Gaudi::Range_< CONTAINER >::const_reverse_iterator

Definition at line 99 of file Range.h.

◆ Container

template<class CONTAINER>
using Gaudi::Range_< CONTAINER >::Container = typename Gaudi::details::container<CONTAINER>::Container

type for actual contained iterator

Definition at line 85 of file Range.h.

◆ iter_traits

template<class CONTAINER>
typedef std::iterator_traits<iterator> Gaudi::Range_< CONTAINER >::iter_traits
private

Definition at line 91 of file Range.h.

◆ iterator

template<class CONTAINER>
using Gaudi::Range_< CONTAINER >::iterator = const_iterator

Definition at line 87 of file Range.h.

◆ reference

template<class CONTAINER>
typedef iter_traits::reference Gaudi::Range_< CONTAINER >::reference

Definition at line 95 of file Range.h.

◆ reverse_iterator

template<class CONTAINER>
typedef std::reverse_iterator<iterator> Gaudi::Range_< CONTAINER >::reverse_iterator

Definition at line 98 of file Range.h.

◆ value_type

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

Definition at line 94 of file Range.h.

Constructor & Destructor Documentation

◆ Range_() [1/5]

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

default constructor

◆ Range_() [2/5]

template<class CONTAINER>
template<typename InputIterator>
Gaudi::Range_< CONTAINER >::Range_ ( InputIterator first,
InputIterator last )
inline

Constructor.

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

Definition at line 108 of file Range.h.

108: m_base( first, last ) {}
Useful class for representation of "sequence" of the objects through the range of valid iterators.
Definition Range.h:81
Base m_base
the base itself
Definition Range.h:216

◆ Range_() [3/5]

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

112: m_base( base ) {}
const Base & base() const
conversion operator to the std::pair
Definition Range.h:213

◆ Range_() [4/5]

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

constructor from the container

Parameters
contreference to the container

Definition at line 116 of file Range.h.

116: m_base( cont.begin(), cont.end() ) {}
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

◆ Range_() [5/5]

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

Definition at line 120 of file Range.h.

120: m_base( ibegin, ibegin ) {}

◆ ~Range_()

template<class CONTAINER>
Gaudi::Range_< CONTAINER >::~Range_ ( )
default

Member Function Documentation

◆ at()

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

178 {
180 return ( *this )( index );
181 }
size_t size() const
size of the sequence (number of elements)
Definition Range.h:127
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:30

◆ back()

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

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

Definition at line 143 of file Range.h.

143{ return *std::prev( end() ); }

◆ base()

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

conversion operator to the std::pair

Definition at line 213 of file Range.h.

213{ return m_base; }

◆ begin()

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; }

◆ cbegin()

template<class CONTAINER>
iterator Gaudi::Range_< CONTAINER >::cbegin ( ) const
inline

access to begin of the sequence (const version )

Definition at line 133 of file Range.h.

133{ return m_base.first; }

◆ cend()

template<class CONTAINER>
iterator Gaudi::Range_< CONTAINER >::cend ( ) const
inline

access to end of the sequence (const version)

Definition at line 135 of file Range.h.

135{ return m_base.second; }

◆ empty()

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

empty sequence ?

Definition at line 125 of file Range.h.

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

◆ end()

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; }

◆ front()

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

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

Definition at line 141 of file Range.h.

141{ return *begin(); }

◆ operator bool()

template<class CONTAINER>
Gaudi::Range_< CONTAINER >::operator bool ( ) const
inlineexplicit

non-empty sequence?

Definition at line 208 of file Range.h.

208{ return !empty(); }
bool empty() const
empty sequence ?
Definition Range.h:125

◆ operator const Base &()

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

conversion operator to the std::pair

Definition at line 211 of file Range.h.

211{ return base(); }

◆ operator!()

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

empty sequence?

Definition at line 206 of file Range.h.

206{ return empty(); }

◆ operator()()

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

167{ return *std::next( begin(), index ); }

◆ operator<() [1/2]

template<class CONTAINER>
template<class ANOTHERCONTAINER>
bool Gaudi::Range_< CONTAINER >::operator< ( const ANOTHERCONTAINER & right) const
inline

compare with another container

Definition at line 190 of file Range.h.

190 {
192 }

◆ operator<() [2/2]

template<class CONTAINER>
template<class C>
bool Gaudi::Range_< CONTAINER >::operator< ( const Range_< C > & right) const
inline

compare with another range

Definition at line 185 of file Range.h.

185 {
187 }

◆ operator==() [1/2]

template<class CONTAINER>
template<class ANOTHERCONTAINER>
bool Gaudi::Range_< CONTAINER >::operator== ( const ANOTHERCONTAINER & right) const
inline

compare with another container

Definition at line 201 of file Range.h.

201 {
202 return right.size() == size() && std::equal( begin(), end(), right.begin() );
203 }

◆ operator==() [2/2]

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

equality with another range

Definition at line 195 of file Range.h.

195 {
196 if ( &right == this ) { return true; }
197 return right.size() == size() && std::equal( begin(), end(), right.begin() );
198 }

◆ operator[]()

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

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

◆ rbegin()

template<class CONTAINER>
reverse_iterator Gaudi::Range_< CONTAINER >::rbegin ( ) const
inline

access to begin of the reversed sequence (const)

Definition at line 137 of file Range.h.

137{ return reverse_iterator( end() ); }
std::reverse_iterator< iterator > reverse_iterator
Definition Range.h:98

◆ rend()

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

access to begin of the reversed sequence (const)

Definition at line 139 of file Range.h.

139{ return reverse_iterator( begin() ); }

◆ size()

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

size of the sequence (number of elements)

Definition at line 127 of file Range.h.

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

◆ slice()

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.

146 {
147 // trivial cases
148 if ( empty() || index1 == index2 ) { return Range_(); }
149 // adjust indices
150 if ( index1 < 0 ) { index1 += size(); }
151 if ( index2 < 0 ) { index2 += size(); }
152 // check
153 if ( index1 < 0 ) { return Range_(); }
154 if ( index2 < index1 ) { return Range_(); }
155
156 if ( index1 > (long)size() ) { return Range_(); }
157 if ( index2 > (long)size() ) { index2 = size(); }
158
159 // construct the slice
160 return Range_( std::next( begin(), index1 ), std::next( begin(), index2 ) );
161 }
Range_()=default
default constructor

Member Data Documentation

◆ m_base

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

the base itself

Definition at line 216 of file Range.h.


The documentation for this class was generated from the following file:
  • GaudiKernel/include/GaudiKernel/Range.h