4 #define GAUDI_RANGE_H 1
13 #include "GaudiKernel/Kernel.h"
52 struct RangeBase_ {} ;
76 template <
class CONTAINER>
77 class Range_ :
public RangeBase_
81 typedef std::pair<
typename CONTAINER::const_iterator,
82 typename CONTAINER::const_iterator>
Base ;
88 typedef typename Container::value_type
value_type ;
89 typedef typename Container::const_iterator
iterator ;
93 typedef typename Container::const_reference
reference ;
96 typedef std::pair<iterator,iterator>
_Base ;
97 typedef Range_<Container>
_Self ;
107 Range_( iterator ibegin , iterator iend ) :
m_base ( ibegin , iend ) {}
119 Range_( iterator ibegin ) :
m_base( ibegin , ibegin ) {}
126 inline size_t size ()
const
127 {
return std::distance (
m_base.first ,
m_base.second ) ; }
129 inline iterator
begin ()
const {
return m_base.first ; }
131 inline iterator
end ()
const {
return m_base.second ; }
137 inline const_reference
front ()
const {
return *(
begin () ) ; }
139 inline const_reference
back ()
const
141 const_iterator
i =
end() ;
142 std::advance ( i , -1 ) ;
147 inline Range_ slice(
long index1 ,
long index2 )
const
150 if (
empty() || index1 == index2 ) {
return Range_() ; }
152 if ( index1 < 0 ) { index1 +=
size () ; }
153 if ( index2 < 0 ) { index2 +=
size () ; }
155 if ( index1 < 0 ) {
return Range_ () ; }
156 if ( index2 < index1 ) {
return Range_ () ; }
158 if ( index1 > (
long)
size () ) {
return Range_() ; }
159 if ( index2 > (
long)
size () ) { index2 =
size() ; }
161 const_iterator i1 =
begin() ;
162 std::advance ( i1 , index1 ) ;
163 const_iterator i2 =
begin() ;
164 std::advance ( i2 , index2 ) ;
166 return Range_( i1 , i2 ) ;
173 inline const_reference
operator () (
const size_t index )
const
175 const_iterator
i =
begin() ;
176 std::advance ( i , index ) ;
183 inline const_reference
operator [] (
const long index )
const
184 {
return (*
this)( index ) ; }
190 inline const_reference
at (
const long index )
const
192 if ( index < 0 || index >= (
long)
size () )
194 return (*
this) ( index );
202 return std::lexicographical_compare
203 (
begin () ,
end () , right.begin () , right.end () ) ;
206 bool operator< (
const Container& right )
const
208 return std::lexicographical_compare
209 (
begin () ,
end () , right.begin () , right.end () ) ;
217 if ( &right ==
this ) {
return true ; }
218 if ( right.size () !=
size () ) {
return false ; }
219 return std::equal (
begin () ,
end () , right.begin() ) ;
222 bool operator==(
const Container& right )
const
224 if ( right.size () !=
size () ) {
return false ; }
225 return std::equal (
begin () ,
end () , right.begin() ) ;
236 operator const Base& ()
const {
return base () ; }
238 inline const Base&
base ()
const {
return m_base ; }
274 template <
class CONTAINER>
277 range (
const CONTAINER& cnt )
278 {
return Range_<CONTAINER>( cnt.begin() , cnt.end() ) ; }
284 #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
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
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
Range_()
default constructor
iterator end() const
access to end of the sequence (const version)
NamedRange_< CONTAINER > range(const CONTAINER &cnt, const std::string &name)
simple function to create the named range form arbitrary container
reverse_iterator rbegin() const
access to begin of the reversed sequence (const)
Container::const_reference reference
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?