userver: userver/storages/clickhouse/impl/iterators_helper.hpp Source File
Loading...
Searching...
No Matches
iterators_helper.hpp
1#pragma once
2
3#include <tuple>
4#include <type_traits>
5#include <utility>
6
7#include <userver/storages/clickhouse/impl/block_wrapper_fwd.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace storages::clickhouse::impl {
12
13template <typename TypesTuple>
14struct IteratorsTuple;
15
16template <typename... Ts>
17struct IteratorsTuple<std::tuple<Ts...>> {
18 using type = std::tuple<typename Ts::iterator...>;
19};
20
21template <typename T>
22using IteratorsTupleT = typename IteratorsTuple<T>::type;
23
24template <typename T,
25 typename Seq = std::make_index_sequence<std::tuple_size_v<T>>>
26class IteratorsHelper;
27
28template <typename T, size_t... I>
29class IteratorsHelper<T, std::index_sequence<I...>> {
30 public:
31 static void Init(IteratorsTupleT<T>& begin_iterators,
32 IteratorsTupleT<T>& end_iterators,
33 clickhouse::impl::BlockWrapper& block) {
34 (..., (std::get<I>(begin_iterators) = GetBegin<I>(block)));
35 (..., (std::get<I>(end_iterators) = GetEnd<I>(block)));
36 }
37
38 static void PrefixIncrement(IteratorsTupleT<T>& iterators) {
39 (..., ++std::get<I>(iterators));
40 }
41
42 static IteratorsTupleT<T> PostfixIncrement(IteratorsTupleT<T>& iterators) {
43 return IteratorsTupleT<T>{std::get<I>(iterators)++...};
44 }
45
46 private:
47 template <size_t Index>
48 static auto GetBegin(clickhouse::impl::BlockWrapper& block) {
49 using ColumnType = std::tuple_element_t<Index, T>;
50 return ColumnType{io::columns::GetWrappedColumn(block, Index)}.begin();
51 }
52
53 template <size_t Index>
54 static auto GetEnd(clickhouse::impl::BlockWrapper& block) {
55 using ColumnType = std::tuple_element_t<Index, T>;
56 return ColumnType{io::columns::GetWrappedColumn(block, Index)}.end();
57 }
58};
59
60} // namespace storages::clickhouse::impl
61
62USERVER_NAMESPACE_END