summaryrefslogtreecommitdiff
path: root/src/database/row.hpp
blob: 1253f931a83af91a009bdadc0c4026fd4314b4b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include <type_traits>

template <typename... T>
struct Row
{
  Row(std::string name):
      table_name(std::move(name))
  {}

  template <typename Type>
  typename Type::real_type& col()
  {
    auto&& col = std::get<Type>(this->columns);
    return col.value;
  }

  template <typename Type>
  const auto& col() const
  {
    auto&& col = std::get<Type>(this->columns);
    return col.value;
  }

  void clear()
  {
    this->clear_col<0>();
  }

  std::tuple<T...> columns;
  std::string table_name;

private:
  template <std::size_t N>
  typename std::enable_if<N < sizeof...(T), void>::type
  clear_col()
  {
    std::get<N>(this->columns).clear();
    this->clear_col<N+1>();
  }
  template <std::size_t N>
  typename std::enable_if<N == sizeof...(T), void>::type
  clear_col()
  { }
};