2 #define GAUDI_RANGE_H 1
11 #include "GaudiKernel/Kernel.h"
50 struct RangeBase_ {} ;
74 template <
class CONTAINER>
75 class Range_ :
public RangeBase_
79 typedef std::pair<
typename CONTAINER::const_iterator,
80 typename CONTAINER::const_iterator>
Base ;
86 typedef typename Container::value_type
value_type ;
87 typedef typename Container::const_iterator
iterator ;
91 typedef typename Container::const_reference
reference ;
94 typedef std::pair<iterator,iterator>
_Base ;
95 typedef Range_<Container>
_Self ;
105 Range_( iterator ibegin , iterator iend ) :
m_base ( ibegin , iend ) {}
117 Range_( iterator ibegin ) :
m_base( ibegin , ibegin ) {}
124 inline size_t size ()
const
125 {
return std::distance (
m_base.first ,
m_base.second ) ; }
127 inline iterator
begin ()
const {
return m_base.first ; }
129 inline iterator
end ()
const {
return m_base.second ; }
135 inline const_reference
front ()
const {
return *
begin() ; }
137 inline const_reference
back ()
const {
return *std::prev(
end() ); }
140 inline Range_ slice(
long index1 ,
long index2 )
const
143 if (
empty() || index1 == index2 ) {
return Range_() ; }
145 if ( index1 < 0 ) { index1 +=
size () ; }
146 if ( index2 < 0 ) { index2 +=
size () ; }
148 if ( index1 < 0 ) {
return Range_ () ; }
149 if ( index2 < index1 ) {
return Range_ () ; }
151 if ( index1 > (
long)
size () ) {
return Range_() ; }
152 if ( index2 > (
long)
size () ) { index2 =
size() ; }
156 std::next (
begin() , index2 ) ) ;
163 inline const_reference
operator () (
const size_t index )
const
165 return *std::next (
begin() , index ) ;
171 inline const_reference
operator [] (
const long index )
const
172 {
return (*
this)( index ) ; }
178 inline const_reference
at (
const long index )
const
180 if ( index < 0 || index >= (
long)
size () )
182 return (*
this) ( index );
190 return std::lexicographical_compare
191 (
begin () ,
end () , right.begin () , right.end () ) ;
194 bool operator< (
const Container& right )
const
196 return std::lexicographical_compare
197 (
begin () ,
end () , right.begin () , right.end () ) ;
205 if ( &right ==
this ) {
return true ; }
206 return right.size() ==
size() &&
207 std::equal (
begin () ,
end () , right.begin() ) ;
210 bool operator==(
const Container& right )
const
212 return right.size() ==
size() &&
213 std::equal (
begin () ,
end () , right.begin() ) ;
224 operator const Base& ()
const {
return base () ; }
226 inline const Base&
base ()
const {
return m_base ; }
262 template <
class CONTAINER>
265 range (
const CONTAINER& cnt )
266 {
return Range_<CONTAINER>( cnt.begin() , cnt.end() ) ; }
272 #endif // GAUDI_RANGE_H
bool empty() const
empty sequence ?
bool operator==(const Range_ &right) const
equality with another range
std::pair< iterator, iterator > _Base
internal types
const_reference operator[](const long index) const
non-checked access to the elements by index (valid only for non-empty sequences)
std::pair< typename CONTAINER::const_iterator, typename CONTAINER::const_iterator > Base
GAUDI_API void rangeException(const long index, const size_t size)
Helpful function to throw an "out-of-range exception" for class Range_.
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)
Base m_base
the base itself
~Range_()=default
destructor
const_reference back() const
access for the back element (only for non-empty ranges!)
const_reference front() const
access for the first element (only for non-empty ranges!)
const_reference at(const long index) const
Checked access to the elements by index (valid for all sequences) for out-of-range access...
size_t size() const
size of the sequence (number of elements)
Range_< Container > _Self
bool operator<(const Range_ &right) const
compare with another range
Container::const_reverse_iterator const_reverse_iterator
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
CONTAINER Container
type for actual contained iterator
Container::value_type value_type
iterator begin() const
access to begin of the sequence (const version )
Container::const_iterator const_iterator
Container::const_iterator iterator
Container::const_reverse_iterator reverse_iterator
const Base & base() const
conversion operator to the std::pair
iterator end() const
access to end of the sequence (const version)
reverse_iterator rbegin() const
access to begin of the reversed sequence (const)
Container::const_reference reference
Range_()=default
default constructor
Helper functions to set/get the application return code.
Container::const_reference const_reference
reverse_iterator rend() const
access to begin of the reversed sequence (const)
bool operator!() const
empty sequence?