Belle II Software  release-08-01-10
DiscreteValue.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <array>
11 #include <vector>
12 #include <iostream>
13 
14 namespace Belle2 {
19  namespace TrackFindingCDC {
20 
22  template<class T, class ATag = T>
23  class DiscreteValue : public std::vector<T>::const_iterator {
24 
25  private:
27  using Super = typename std::vector<T>::const_iterator;
28 
31 
32  public:
34  using Super::Super;
35 
37  DiscreteValue() = default;
38 
40  explicit DiscreteValue(const Super& iter) : Super(iter) {}
41 
44  explicit DiscreteValue(T& value) : Super(&value) {}
45 
47  explicit operator const T& () const
48  { return **this; }
49 
51  friend std::ostream& operator<<(std::ostream& output, const This& discreteValue)
52  { return output << *discreteValue; }
53 
55  using Array = std::vector<T>;
56 
58  static
59  std::array<This, 2> getRange(Array& values)
60  { return {{ This(values.front()), This(values.back()) }}; }
61  };
62 
63  }
65 }
Representation for a discrete position in an array of discrete positions.
Definition: DiscreteValue.h:23
DiscreteValue(const Super &iter)
Constructor from underlying iterator type.
Definition: DiscreteValue.h:40
DiscreteValue(T &value)
Constructor from a reference to the underlying type Care must be taken to feed it a reference that co...
Definition: DiscreteValue.h:44
DiscreteValue()=default
Default constructor for to obtain a valid object in all contexts.
static std::array< This, 2 > getRange(Array &values)
Extract the range from an array providing the discrete values.
Definition: DiscreteValue.h:59
friend std::ostream & operator<<(std::ostream &output, const This &discreteValue)
Output operator for debugging.
Definition: DiscreteValue.h:51
typename std::vector< T >::const_iterator Super
Type of the base class.
Definition: DiscreteValue.h:27
DiscreteValue< T, ATag > This
Type of this class.
Definition: DiscreteValue.h:30
std::vector< T > Array
The type of the array which contains the underlying values.
Definition: DiscreteValue.h:55
Abstract base class for different kinds of events.