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 }
77 
78 
79 template <typename... Args>
80 class TableItr {
81  using Layout = std::tuple<Args...>;
82  std::array<void*, sizeof...(Args)> m_values;
83 public:
84  using value_type = MutableRowView<Args...>;
85 
86  explicit TableItr( std::array<void*, sizeof...(Args)> const& iValues):
87  m_values{iValues} {}
88 
89  explicit TableItr( std::array<void*, sizeof...(Args)> const& iValues, long iOffset):
90  m_values{iValues} {
91  impl::TableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, iOffset);
92  }
93 
94  explicit TableItr( std::array<void*, sizeof...(Args)> const& iValues, unsigned int iOffset):
95  m_values{iValues} {
96  impl::TableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, static_cast<long>(iOffset));
97  }
98 
100  return value_type{m_values};
101  }
102 
104  impl::TableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, 1);
105  return *this;
106  }
107 
108  bool operator==( const TableItr<Args...>& iOther) {
109  return m_values[0] == iOther.m_values[0];
110  }
111 
112  bool operator!=( const TableItr<Args...>& iOther) {
113  return m_values[0] != iOther.m_values[0];
114  }
115 
116  TableItr<Args...> makeOffset(long iDiff) const {
117  return TableItr<Args...>{ m_values, iDiff };
118  }
119 };
120 
121 template <typename... Args>
122 TableItr<Args...> operator+(TableItr<Args...> const& iLHS, long iDiff) {
123  return iLHS.makeOffset(iDiff);
124 }
125 
126 template <typename... Args>
128  using Layout = std::tuple<Args...>;
129  std::array<void const*, sizeof...(Args)> m_values;
130 public:
131  using value_type = RowView<Args...>;
132 
133  explicit ConstTableItr( std::array<void const*, sizeof...(Args)> const& iValues):
134  m_values{iValues} {}
135 
136  ConstTableItr( std::array<void const*, sizeof...(Args)> const& iValues, long iOffset):
137  m_values{iValues} {
138  impl::ConstTableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, iOffset);
139  }
140 
141  ConstTableItr( std::array<void const*, sizeof...(Args)> const& iValues, unsigned int iOffset):
142  m_values{iValues} {
143  impl::ConstTableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, static_cast<long>(iOffset));
144  }
145 
147  return value_type{m_values};
148  }
149 
151  impl::ConstTableItrAdvance<sizeof...(Args)-1, Args...>::advance(m_values, 1);
152  return *this;
153  }
154 
155  bool operator==( const ConstTableItr<Args...>& iOther) {
156  return m_values[0] == iOther.m_values[0];
157  }
158 
159  bool operator!=( const ConstTableItr<Args...>& iOther) {
160  return m_values[0] != iOther.m_values[0];
161  }
162 
163  TableItr<Args...> makeOffset(long iDiff) const {
164  return TableItr<Args...>{ m_values, iDiff };
165  }
166 };
167 
168 template <typename... Args>
169 ConstTableItr<Args...> operator+(ConstTableItr<Args...> const& iLHS, long iDiff) {
170  return iLHS.makeOffset(iDiff);
171 }
172 
173 }
174 }
175 
176 
177 #endif
type
Definition: HCALResponse.h:21
std::tuple< Args... > Layout
Definition: TableItr.h:37
bool operator==(const TableItr< Args... > &iOther)
Definition: TableItr.h:108
std::tuple< Args... > Layout
Definition: TableItr.h:128
std::tuple< Args... > Layout
Definition: TableItr.h:81
std::tuple< Args... > Layout
Definition: TableItr.h:58
ConstTableItr & operator++()
Definition: TableItr.h:150
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:122
TableItr(std::array< void *, sizeof...(Args)> const &iValues, long iOffset)
Definition: TableItr.h:89
static void advance(std::array< void *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:38
TableItr< Args... > makeOffset(long iDiff) const
Definition: TableItr.h:116
TableItr(std::array< void *, sizeof...(Args)> const &iValues)
Definition: TableItr.h:86
value_type operator*() const
Definition: TableItr.h:146
TableItr(std::array< void *, sizeof...(Args)> const &iValues, unsigned int iOffset)
Definition: TableItr.h:94
value_type operator*()
Definition: TableItr.h:99
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues, long iOffset)
Definition: TableItr.h:136
const std::complex< double > I
Definition: I.h:8
std::array< void *, sizeof...(Args)> m_values
Definition: TableItr.h:82
static void advance(std::array< void *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:49
bool operator!=(const ConstTableItr< Args... > &iOther)
Definition: TableItr.h:159
bool operator==(const ConstTableItr< Args... > &iOther)
Definition: TableItr.h:155
std::array< void const *, sizeof...(Args)> m_values
Definition: TableItr.h:129
bool operator!=(const TableItr< Args... > &iOther)
Definition: TableItr.h:112
TableItr & operator++()
Definition: TableItr.h:103
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues, unsigned int iOffset)
Definition: TableItr.h:141
HLT enums.
TableItr< Args... > makeOffset(long iDiff) const
Definition: TableItr.h:163
ConstTableItr(std::array< void const *, sizeof...(Args)> const &iValues)
Definition: TableItr.h:133
static void advance(std::array< void const *, sizeof...(Args)> &iArray, long iStep)
Definition: TableItr.h:59