All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
lar::sparse_vector< T >::const_iterator Class Reference

Iterator to the sparse vector values. More...

#include <sparse_vector.h>

Inheritance diagram for lar::sparse_vector< T >::const_iterator:
lar::sparse_vector< T >::iterator

Classes

struct  special
 Namespace for special initialization. More...
 

Public Types

typedef std::forward_iterator_tag iterator_category
 
typedef container_t::value_type value_type
 
typedef
container_t::difference_type 
difference_type
 
typedef container_t::pointer pointer
 
typedef container_t::reference reference
 
typedef vector_t::const_reference const_reference
 

Public Member Functions

 const_iterator ()
 Default constructor, does not iterate anywhere. More...
 
 const_iterator (const container_t &c, size_type offset)
 Constructor from a container and a offset. More...
 
 const_iterator (const container_t &c, const typename special::begin)
 Special constructor: initializes at the beginning of the container. More...
 
 const_iterator (const container_t &c, const typename special::end)
 Special constructor: initializes at the end of the container. More...
 
const_reference operator[] (size_type offset) const
 Random access. More...
 
const_reference operator* () const
 Constant dereferenciation operator. More...
 
difference_type operator- (const const_iterator &iter) const
 Distance operator. More...
 
range_const_iterator get_current_range () const
 Returns the current range internal value; use it at your own risk!! More...
 
const_iteratoroperator++ ()
 Increment and decrement operators. More...
 
const_iterator operator++ (int)
 
const_iteratoroperator+= (difference_type delta)
 Increment and decrement operators. More...
 
const_iteratoroperator-= (difference_type delta)
 
const_iterator operator+ (difference_type delta) const
 
const_iterator operator- (difference_type delta) const
 
bool operator== (const const_iterator &as) const
 Iterator comparisons. More...
 
bool operator!= (const const_iterator &as) const
 
bool operator< (const const_iterator &than) const
 
bool operator> (const const_iterator &than) const
 
bool operator<= (const const_iterator &than) const
 
bool operator>= (const const_iterator &than) const
 

Protected Types

typedef sparse_vector< T > container_t
 
typedef container_t::size_type size_type
 
typedef
container_t::range_list_t::const_iterator 
ranges_const_iterator
 

Protected Member Functions

void refresh_state ()
 Reassigns the internal state according to the index. More...
 

Protected Attributes

const container_tcont
 pointer to the container More...
 
size_type index
 pointer to the current value, as absolute index More...
 
ranges_const_iterator currentRange
 pointer to the current (or next) range More...
 

Friends

class container_t
 

Detailed Description

template<typename T>
class lar::sparse_vector< T >::const_iterator

Iterator to the sparse vector values.

Definition at line 1431 of file sparse_vector.h.

Member Typedef Documentation

template<typename T>
typedef vector_t::const_reference lar::sparse_vector< T >::const_iterator::const_reference

Definition at line 1462 of file sparse_vector.h.

template<typename T>
typedef sparse_vector<T> lar::sparse_vector< T >::const_iterator::container_t
protected

Definition at line 1439 of file sparse_vector.h.

Definition at line 1457 of file sparse_vector.h.

template<typename T>
typedef std::forward_iterator_tag lar::sparse_vector< T >::const_iterator::iterator_category

Definition at line 1447 of file sparse_vector.h.

Definition at line 1458 of file sparse_vector.h.

Definition at line 1441 of file sparse_vector.h.

Definition at line 1459 of file sparse_vector.h.

template<typename T>
typedef container_t::size_type lar::sparse_vector< T >::const_iterator::size_type
protected

Definition at line 1440 of file sparse_vector.h.

Definition at line 1456 of file sparse_vector.h.

Constructor & Destructor Documentation

template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( )
inline

Default constructor, does not iterate anywhere.

Definition at line 1466 of file sparse_vector.h.

1466 : cont(nullptr), index(0), currentRange() {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
size_type  offset 
)
inline

Constructor from a container and a offset.

Definition at line 1469 of file sparse_vector.h.

1469  :
1470  cont(&c), index(std::min(offset, c.size())), currentRange()
1471  { refresh_state(); }
void refresh_state()
Reassigns the internal state according to the index.
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Definition: CORSIKAGen.fcl:7
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
const typename special::begin   
)
inline

Special constructor: initializes at the beginning of the container.

Definition at line 1474 of file sparse_vector.h.

1474  :
1475  cont(&c), index(0), currentRange(c.get_ranges().begin())
1476  {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
const typename special::end   
)
inline

Special constructor: initializes at the end of the container.

Definition at line 1479 of file sparse_vector.h.

1479  :
1480  cont(&c), index(c.size()), currentRange(c.get_ranges().end())
1481  {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index

Member Function Documentation

template<typename T>
range_const_iterator lar::sparse_vector< T >::const_iterator::get_current_range ( ) const
inline

Returns the current range internal value; use it at your own risk!!

Definition at line 1526 of file sparse_vector.h.

1526 { return currentRange; }
ranges_const_iterator currentRange
pointer to the current (or next) range
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator!= ( const const_iterator as) const
inline

Definition at line 1513 of file sparse_vector.h.

1514  { return (cont != as.cont) || (index != as.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator::const_reference lar::sparse_vector< T >::const_iterator::operator* ( ) const

Constant dereferenciation operator.

Definition at line 2417 of file sparse_vector.h.

2417  {
2418  // no container, no idea what to do
2419  if (!cont) throw std::out_of_range("iterator to no sparse vector");
2420 
2421  // index beyond the end: can't return any reference
2422  if (index >= cont->size()) return value_zero;
2423 
2424  // are we in a valid range? if not, we are past the last range
2425  if (currentRange == cont->ranges.end()) return value_zero;
2426 
2427  // if the index is beyond the current range, we are in the void
2428  if (index < currentRange->begin_index()) return value_zero;
2429 
2430  return (*currentRange)[index];
2431 } // lar::sparse_vector<T>::const_iterator::operator*()
size_type size() const
Returns the size of the vector.
static constexpr value_type value_zero
a representation of 0
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator lar::sparse_vector< T >::const_iterator::operator+ ( difference_type  delta) const

Definition at line 2455 of file sparse_vector.h.

2456 {
2457  if ((currentRange == cont->ranges.end())
2458  || !currentRange->includes(index + delta)
2459  )
2460  return const_iterator(*cont, index + delta);
2461  const_iterator iter(*this);
2462  iter.index += delta;
2463  return iter;
2464 } // lar::sparse_vector<T>::const_iterator::operator+()
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
const_iterator()
Default constructor, does not iterate anywhere.
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator++ ( )

Increment and decrement operators.

Definition at line 2397 of file sparse_vector.h.

2397  {
2398  // no container, not doing anything;
2399  // index beyond the end: stays there
2400  if (!cont || (index >= cont->size())) return *this;
2401 
2402  // increment the internal index
2403  ++index;
2404 
2405  // were we in a valid range?
2406  if (currentRange != cont->ranges.end()) {
2407  // if the new index is beyond the current range, pick the next
2408  if (currentRange->end_index() <= index) ++currentRange;
2409  }
2410  // if we have no valid range, we are forever in the void
2411  return *this;
2412 } // lar::sparse_vector<T>::iterator::operator++()
size_type size() const
Returns the size of the vector.
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
template<typename T>
const_iterator lar::sparse_vector< T >::const_iterator::operator++ ( int  )
inline

Definition at line 1493 of file sparse_vector.h.

1494  { const_iterator copy(*this); const_iterator::operator++(); return copy; }
const_iterator & operator++()
Increment and decrement operators.
const_iterator()
Default constructor, does not iterate anywhere.
T copy(T const &v)
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator+= ( difference_type  delta)

Increment and decrement operators.

Definition at line 2436 of file sparse_vector.h.

2437 {
2438  if (delta == 1) return this->operator++();
2439  index += delta;
2440  if ((currentRange == cont->ranges.end())
2441  || !currentRange->includes(index)
2442  )
2443  refresh_state();
2444  return *this;
2445 } // lar::sparse_vector<T>::const_iterator::operator+=()
void refresh_state()
Reassigns the internal state according to the index.
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
const_iterator & operator++()
Increment and decrement operators.
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator lar::sparse_vector< T >::const_iterator::operator- ( difference_type  delta) const
inline

Definition at line 2468 of file sparse_vector.h.

2469  { return this->operator+ (-delta); }
const_iterator operator+(difference_type delta) const
template<typename T >
lar::sparse_vector< T >::const_iterator::difference_type lar::sparse_vector< T >::const_iterator::operator- ( const const_iterator iter) const
inline

Distance operator.

distance operator

Definition at line 2476 of file sparse_vector.h.

2477 {
2478  if (cont != iter.cont) {
2479  throw std::runtime_error("lar::sparse_vector::const_iterator:"
2480  " difference with alien iterator");
2481  }
2482  return index -iter.index;
2483 } // lar::sparse_vector<T>::const_iterator::operator-(const_iterator)
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator-= ( difference_type  delta)
inline

Definition at line 2449 of file sparse_vector.h.

2450  { return this->operator+= (-delta); }
const_iterator & operator+=(difference_type delta)
Increment and decrement operators.
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator< ( const const_iterator than) const
inline

Definition at line 1515 of file sparse_vector.h.

1516  { return (cont == than.cont) && (index < than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator<= ( const const_iterator than) const
inline

Definition at line 1519 of file sparse_vector.h.

1520  { return (cont == than.cont) && (index <= than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator== ( const const_iterator as) const
inline

Iterator comparisons.

Definition at line 1511 of file sparse_vector.h.

1512  { return (cont == as.cont) && (index == as.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator> ( const const_iterator than) const
inline

Definition at line 1517 of file sparse_vector.h.

1518  { return (cont == than.cont) && (index > than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator>= ( const const_iterator than) const
inline

Definition at line 1521 of file sparse_vector.h.

1522  { return (cont == than.cont) && (index >= than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
const_reference lar::sparse_vector< T >::const_iterator::operator[] ( size_type  offset) const
inline

Random access.

Definition at line 1484 of file sparse_vector.h.

1485  { return (*cont)[index + offset]; }
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Definition: CORSIKAGen.fcl:7
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
void lar::sparse_vector< T >::const_iterator::refresh_state ( )
protected

Reassigns the internal state according to the index.

Definition at line 2487 of file sparse_vector.h.

2487  {
2488  // update the currentRange
2489  // currentRange is the range including the current item, or next to it
2490  if (cont) {
2491  // the following is actually the range after the index:
2493  // if the index is inside the previous index, then we want to move there:
2494  if (currentRange != cont->ranges.begin()) {
2495  if ((currentRange - 1)->end_index() > index) --currentRange;
2496  }
2497  }
2498  else {
2499  currentRange = {};
2500  }
2501 } // lar::sparse_vector<T>::const_iterator::refresh_state()
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
range_iterator find_next_range_iter(size_type index)
Returns an iterator to the range after index.
size_type index
pointer to the current value, as absolute index

Friends And Related Function Documentation

template<typename T>
friend class container_t
friend

Definition at line 1437 of file sparse_vector.h.

Member Data Documentation

template<typename T>
const container_t* lar::sparse_vector< T >::const_iterator::cont
protected

pointer to the container

Definition at line 1559 of file sparse_vector.h.

template<typename T>
ranges_const_iterator lar::sparse_vector< T >::const_iterator::currentRange
protected

pointer to the current (or next) range

Definition at line 1561 of file sparse_vector.h.

template<typename T>
size_type lar::sparse_vector< T >::const_iterator::index
protected

pointer to the current value, as absolute index

Definition at line 1560 of file sparse_vector.h.


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