CMS 3D CMS Logo

TableItr.h
Go to the documentation of this file.
1 #ifndef FWCore_SOA_TableItr_h
2 #define FWCore_SOA_TableItr_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SOA
6 // Class : TableItr
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu, 24 Aug 2017 19:49:27 GMT
19 //
20 
21 // system include files
22 #include <tuple>
23 #include <array>
24 #include <type_traits>
25 
26 // user include files
27 #include "RowView.h"
28 
29 // forward declarations
30 
31 namespace edm {
32  namespace soa {
33  namespace impl {
34 
35  template <int I, typename... Args>
36  struct TableItrAdvance {
37  using Layout = std::tuple<Args...>;
38  static void advance(std::array<void*, sizeof...(Args)>& iArray, long iStep) {
41  auto p = static_cast<Type*>(iArray[I]);
42  iArray[I] = p + iStep;
43  }
44  };
45 
46  template <typename... Args>
47  struct TableItrAdvance<0, Args...> {
48  using Layout = std::tuple<Args...>;
49  static void advance(std::array<void*, sizeof...(Args)>& iArray, long iStep) {
51  auto p = static_cast<Type*>(iArray[0]);
52  iArray[0] = p + iStep;
53  }
54  };
55 
56  template <int I, typename... Args>
58  using Layout = std::tuple<Args...>;
59  static void advance(std::array<void const*, sizeof...(Args)>& iArray, long iStep) {
62  auto p = static_cast<Type const*>(iArray[I]);
63  iArray[I] = p + iStep;
64  }
65  };
66 
67  template <typename... Args>
68  struct ConstTableItrAdvance<0, Args...> {
69  using Layout = std::tuple<Args...>;
70  static void advance(std::array<void const*, sizeof...(Args)>& iArray, long iStep) {
72  auto p = static_cast<Type const*>(iArray[0]);
73  iArray[0] = p + iStep;
74  }
75  };
76  } // namespace impl
77 
78  template <typename... Args>
79  class TableItr {
80  using Layout = std::tuple<Args...>;
81  std::array<void*, sizeof...(Args)> m_values;
82 
83  public:
84  using value_type = MutableRowView<Args...>;
85 
86  explicit TableItr(std::array<void*, sizeof...(Args)> const& iValues) : m_values{iValues} {}
87 
88  explicit TableItr(std::array<void*, sizeof...(Args)> const& iValues, long iOffset) : m_values{iValues} {
89  impl::TableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, iOffset);
90  }
91 
92  explicit TableItr(std::array<void*, sizeof...(Args)> const& iValues, unsigned int iOffset) : m_values{iValues} {
93  impl::TableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, static_cast<long>(iOffset));
94  }
95 
96  value_type operator*() { return value_type{m_values}; }
97 
99  impl::TableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, 1);
100  return *this;
101  }
102 
103  bool operator==(const TableItr<Args...>& iOther) { return m_values[0] == iOther.m_values[0]; }
104 
105  bool operator!=(const TableItr<Args...>& iOther) { return m_values[0] != iOther.m_values[0]; }
106 
107  TableItr<Args...> makeOffset(long iDiff) const { return TableItr<Args...>{m_values, iDiff}; }
108  };
109 
110  template <typename... Args>
111  TableItr<Args...> operator+(TableItr<Args...> const& iLHS, long iDiff) {
112  return iLHS.makeOffset(iDiff);
113  }
114 
115  template <typename... Args>
117  using Layout = std::tuple<Args...>;
118  std::array<void const*, sizeof...(Args)> m_values;
119 
120  public:
121  using value_type = RowView<Args...>;
122 
123  explicit ConstTableItr(std::array<void const*, sizeof...(Args)> const& iValues) : m_values{iValues} {}
124 
125  ConstTableItr(std::array<void const*, sizeof...(Args)> const& iValues, long iOffset) : m_values{iValues} {
126  impl::ConstTableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, iOffset);
127  }
128 
129  ConstTableItr(std::array<void const*, sizeof...(Args)> const& iValues, unsigned int iOffset) : m_values{iValues} {
130  impl::ConstTableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, static_cast<long>(iOffset));
131  }
132 
133  value_type operator*() const { return value_type{m_values}; }
134 
136  impl::ConstTableItrAdvance<sizeof...(Args) - 1, Args...>::advance(m_values, 1);
137  return *this;
138  }
139 
140  bool operator==(const ConstTableItr<Args...>& iOther) { return m_values[0] == iOther.m_values[0]; }
141 
142  bool operator!=(const ConstTableItr<Args...>& iOther) { return m_values[0] != iOther.m_values[0]; }
143 
144  TableItr<Args...> makeOffset(long iDiff) const { return TableItr<Args...>{m_values, iDiff}; }
145  };
146 
147  template <typename... Args>
148  ConstTableItr<Args...> operator+(ConstTableItr<Args...> const& iLHS, long iDiff) {
149  return iLHS.makeOffset(iDiff);
150  }
151 
152  } // namespace soa
153 } // namespace edm
154 
155 #endif
type
Definition: HCALResponse.h:21
std::tuple< Args... > Layout
Definition: TableItr.h:37
bool operator==(const TableItr< Args... > &iOther)
Definition: TableItr.h:103
std::tuple< Args... > Layout
Definition: TableItr.h:117
std::tuple< Args... > Layout
Definition: TableItr.h:80
std::tuple< Args... > Layout
Definition: TableItr.h:58
ConstTableItr & operator++()
Definition: TableItr.h:135
static void advance(std::array< void const *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:70
TableItr< Args... > operator+(TableItr< Args... > const &iLHS, long iDiff)
Definition: TableItr.h:111
TableItr(std::array< void *, sizeof...(Args)> const &iValues, long iOffset)
Definition: TableItr.h:88
static void advance(std::array< void *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:38
TableItr< Args... > makeOffset(long iDiff) const
Definition: TableItr.h:107
TableItr(std::array< void *, sizeof...(Args)> const &iValues)
Definition: TableItr.h:86
value_type operator*() const
Definition: TableItr.h:133
TableItr(std::array< void *, sizeof...(Args)> const &iValues, unsigned int iOffset)
Definition: TableItr.h:92
value_type operator*()
Definition: TableItr.h:96
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues, long iOffset)
Definition: TableItr.h:125
const std::complex< double > I
Definition: I.h:8
std::array< void *, sizeof...(Args)> m_values
Definition: TableItr.h:81
static void advance(std::array< void *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:49
bool operator!=(const ConstTableItr< Args... > &iOther)
Definition: TableItr.h:142
bool operator==(const ConstTableItr< Args... > &iOther)
Definition: TableItr.h:140
std::array< void const *, sizeof...(Args)> m_values
Definition: TableItr.h:118
bool operator!=(const TableItr< Args... > &iOther)
Definition: TableItr.h:105
TableItr & operator++()
Definition: TableItr.h:98
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues, unsigned int iOffset)
Definition: TableItr.h:129
HLT enums.
TableItr< Args... > makeOffset(long iDiff) const
Definition: TableItr.h:144
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues)
Definition: TableItr.h:123
static void advance(std::array< void const *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:59