Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (e199b415)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Gaudi::Range_< CONTAINER, ITERATOR > Class Template Reference

#include <GaudiUtils/Range.h>

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

Public Types

using Container = typename Gaudi::details::container< CONTAINER >::Container
 type for actual contained iterator More...
 
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
 internal types More...
 
template<typename InputIterator >
 Range_ (InputIterator first, InputIterator last)
 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...
 
iterator cbegin () const
 access to begin of the sequence (const version ) More...
 
iterator cend () 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) More...
 
template<class C , class I >
bool operator< (const Range_< C, I > &right) const
 compare with another range More...
 
template<class ANOTHERCONTAINER >
bool operator< (const ANOTHERCONTAINER &right) const
 compare with another container More...
 
bool operator== (const Range_ &right) const
 equality with another range More...
 
template<class ANOTHERCONTAINER >
bool operator== (const ANOTHERCONTAINER &right) const
 compare with another container More...
 
bool operator! () const
 empty sequence? More...
 
 operator bool () const
 non-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 Types

typedef std::iterator_traits< iteratoriter_traits
 

Private Attributes

Base m_base
 the base itself More...
 

Detailed Description

template<class CONTAINER, class ITERATOR = typename CONTAINER::const_iterator>
class Gaudi::Range_< CONTAINER, ITERATOR >

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

Member Typedef Documentation

◆ Base

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

Definition at line 103 of file Range.h.

◆ const_iterator

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

Definition at line 101 of file Range.h.

◆ const_reference

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef iter_traits::reference Gaudi::Range_< CONTAINER, ITERATOR >::const_reference

Definition at line 113 of file Range.h.

◆ const_reverse_iterator

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef std::reverse_iterator<iterator> Gaudi::Range_< CONTAINER, ITERATOR >::const_reverse_iterator

Definition at line 116 of file Range.h.

◆ Container

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

type for actual contained iterator

Definition at line 100 of file Range.h.

◆ iter_traits

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef std::iterator_traits<iterator> Gaudi::Range_< CONTAINER, ITERATOR >::iter_traits
private

Definition at line 107 of file Range.h.

◆ iterator

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

Definition at line 102 of file Range.h.

◆ reference

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef iter_traits::reference Gaudi::Range_< CONTAINER, ITERATOR >::reference

Definition at line 112 of file Range.h.

◆ reverse_iterator

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef std::reverse_iterator<iterator> Gaudi::Range_< CONTAINER, ITERATOR >::reverse_iterator

Definition at line 115 of file Range.h.

◆ value_type

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
typedef iter_traits::value_type Gaudi::Range_< CONTAINER, ITERATOR >::value_type

Definition at line 111 of file Range.h.

Constructor & Destructor Documentation

◆ Range_() [1/5]

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::Range_ ( )
default

internal types

default constructor

◆ Range_() [2/5]

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

Constructor.

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

Definition at line 128 of file Range.h.

128 : m_base( first, last ) {}

◆ Range_() [3/5]

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::Range_ ( const Base base)
inline

constructor from the pair of iterators

Parameters
basepair of the iterators

Definition at line 132 of file Range.h.

132 : m_base( base ) {}

◆ Range_() [4/5]

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::Range_ ( const Container cont)
inline

constructor from the container

Parameters
contreference to the container

Definition at line 136 of file Range.h.

136 : m_base( cont.begin(), cont.end() ) {}

◆ Range_() [5/5]

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::Range_ ( iterator  ibegin)
inline

Definition at line 140 of file Range.h.

140 : m_base( ibegin, ibegin ) {}

◆ ~Range_()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::~Range_ ( )
default

destructor

Member Function Documentation

◆ at()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const_reference Gaudi::Range_< CONTAINER, ITERATOR >::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 198 of file Range.h.

198  {
199  if ( index < 0 || index >= (long)size() ) { Gaudi::details::rangeException( index, size() ); }
200  return ( *this )( index );
201  }

◆ back()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const_reference Gaudi::Range_< CONTAINER, ITERATOR >::back ( ) const
inline

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

Definition at line 163 of file Range.h.

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

◆ base()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const Base& Gaudi::Range_< CONTAINER, ITERATOR >::base ( ) const
inline

conversion operator to the std::pair

Definition at line 241 of file Range.h.

241 { return m_base; }

◆ begin()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
iterator Gaudi::Range_< CONTAINER, ITERATOR >::begin ( ) const
inline

access to begin of the sequence (const version )

Definition at line 149 of file Range.h.

149 { return m_base.first; }

◆ cbegin()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
iterator Gaudi::Range_< CONTAINER, ITERATOR >::cbegin ( ) const
inline

access to begin of the sequence (const version )

Definition at line 153 of file Range.h.

153 { return m_base.first; }

◆ cend()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
iterator Gaudi::Range_< CONTAINER, ITERATOR >::cend ( ) const
inline

access to end of the sequence (const version)

Definition at line 155 of file Range.h.

155 { return m_base.second; }

◆ empty()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
bool Gaudi::Range_< CONTAINER, ITERATOR >::empty ( ) const
inline

empty sequence ?

Definition at line 145 of file Range.h.

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

◆ end()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
iterator Gaudi::Range_< CONTAINER, ITERATOR >::end ( ) const
inline

access to end of the sequence (const version)

Definition at line 151 of file Range.h.

151 { return m_base.second; }

◆ front()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const_reference Gaudi::Range_< CONTAINER, ITERATOR >::front ( ) const
inline

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

Definition at line 161 of file Range.h.

161 { return *begin(); }

◆ operator bool()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::operator bool ( ) const
inlineexplicit

non-empty sequence?

Definition at line 234 of file Range.h.

234 { return !empty(); }

◆ operator const Base &()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Gaudi::Range_< CONTAINER, ITERATOR >::operator const Base & ( ) const
inline

conversion operator to the std::pair

Definition at line 239 of file Range.h.

239 { return base(); }

◆ operator!()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
bool Gaudi::Range_< CONTAINER, ITERATOR >::operator! ( ) const
inline

empty sequence?

Definition at line 232 of file Range.h.

232 { return empty(); }

◆ operator()()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const_reference Gaudi::Range_< CONTAINER, ITERATOR >::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 187 of file Range.h.

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

◆ operator<() [1/2]

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

compare with another container

Definition at line 212 of file Range.h.

212  {
213  return std::lexicographical_compare( begin(), end(), right.begin(), right.end() );
214  }

◆ operator<() [2/2]

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
template<class C , class I >
bool Gaudi::Range_< CONTAINER, ITERATOR >::operator< ( const Range_< C, I > &  right) const
inline

compare with another range

Definition at line 207 of file Range.h.

207  {
208  return std::lexicographical_compare( begin(), end(), right.begin(), right.end() );
209  }

◆ operator==() [1/2]

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

compare with another container

Definition at line 225 of file Range.h.

225  {
226  return right.size() == size() && std::equal( begin(), end(), right.begin() );
227  }

◆ operator==() [2/2]

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

equality with another range

Definition at line 219 of file Range.h.

219  {
220  if ( &right == this ) { return true; } // RETURN
221  return right.size() == size() && std::equal( begin(), end(), right.begin() );
222  }

◆ operator[]()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
const_reference Gaudi::Range_< CONTAINER, ITERATOR >::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 192 of file Range.h.

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

◆ rbegin()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
reverse_iterator Gaudi::Range_< CONTAINER, ITERATOR >::rbegin ( ) const
inline

access to begin of the reversed sequence (const)

Definition at line 157 of file Range.h.

157 { return reverse_iterator( end() ); }

◆ rend()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
reverse_iterator Gaudi::Range_< CONTAINER, ITERATOR >::rend ( ) const
inline

access to begin of the reversed sequence (const)

Definition at line 159 of file Range.h.

159 { return reverse_iterator( begin() ); }

◆ size()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
size_t Gaudi::Range_< CONTAINER, ITERATOR >::size ( ) const
inline

size of the sequence (number of elements)

Definition at line 147 of file Range.h.

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

◆ slice()

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Range_ Gaudi::Range_< CONTAINER, ITERATOR >::slice ( long  index1,
long  index2 
) const
inline

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

Definition at line 166 of file Range.h.

166  {
167  // trivial cases
168  if ( empty() || index1 == index2 ) { return Range_(); } // RETURN
169  // adjust indices
170  if ( index1 < 0 ) { index1 += size(); }
171  if ( index2 < 0 ) { index2 += size(); }
172  // check
173  if ( index1 < 0 ) { return Range_(); } // RETURN
174  if ( index2 < index1 ) { return Range_(); } // RETURN
175 
176  if ( index1 > (long)size() ) { return Range_(); } // RETURN
177  if ( index2 > (long)size() ) { index2 = size(); }
178 
179  // construct the slice
180  return Range_( std::next( begin(), index1 ), std::next( begin(), index2 ) ); // RETURN
181  }

Member Data Documentation

◆ m_base

template<class CONTAINER , class ITERATOR = typename CONTAINER::const_iterator>
Base Gaudi::Range_< CONTAINER, ITERATOR >::m_base
private

the base itself

Definition at line 246 of file Range.h.


The documentation for this class was generated from the following file:
std::equal
T equal(T... args)
Gaudi::Range_::empty
bool empty() const
empty sequence ?
Definition: Range.h:145
Gaudi::Range_::base
const Base & base() const
conversion operator to the std::pair
Definition: Range.h:241
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:40
std::distance
T distance(T... args)
Gaudi::Range_::begin
iterator begin() const
access to begin of the sequence (const version )
Definition: Range.h:149
Gaudi::Range_::size
size_t size() const
size of the sequence (number of elements)
Definition: Range.h:147
std::lexicographical_compare
T lexicographical_compare(T... args)
Gaudi::Range_::m_base
Base m_base
the base itself
Definition: Range.h:246
Gaudi::Range_::Range_
Range_()=default
internal types
Gaudi::Range_::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition: Range.h:115
std::right
T right(T... args)
std::prev
T prev(T... args)
Gaudi::Range_::end
iterator end() const
access to end of the sequence (const version)
Definition: Range.h:151
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39
std::next
T next(T... args)