cxtream  0.5.1
C++17 data pipeline with Python bindings.
column.hpp
1 /****************************************************************************
2  * cxtream library
3  * Copyright (c) 2017, Cognexa Solutions s.r.o.
4  * Author(s) Filip Matzner
5  *
6  * This file is distributed under the MIT License.
7  * See the accompanying file LICENSE.txt for the complete license agreement.
8  ****************************************************************************/
9 
10 #ifndef CXTREAM_CORE_STREAM_COLUMN_HPP
11 #define CXTREAM_CORE_STREAM_COLUMN_HPP
12 
13 #include <initializer_list>
14 #include <type_traits>
15 #include <vector>
16 
17 namespace cxtream::stream {
18 
23 template <typename T, bool = std::is_copy_constructible<T>{}>
24 class column_base {
25 private:
26  std::vector<T> value_;
27 
28 public:
29 
30  using batch_type = std::vector<T>;
31  using example_type = T;
32 
33  // constructors //
34 
35  column_base() = default;
36  column_base(T&& rhs)
37  {
38  value_.emplace_back(std::move(rhs));
39  }
40  column_base(const T& rhs)
41  : value_{rhs}
42  {}
43 
44  column_base(std::initializer_list<T> rhs)
45  : value_{std::move(rhs)}
46  {}
47 
48  column_base(std::vector<T>&& rhs)
49  : value_{std::move(rhs)}
50  {}
51 
52  column_base(const std::vector<T>& rhs)
53  : value_{rhs}
54  {}
55 
56  // conversion operators //
57 
58  operator std::vector<T>&() &
59  {
60  return value_;
61  }
62 
63  operator std::vector<T>&&() &&
64  {
65  return std::move(value_);
66  }
67 
68  // value accessors //
69 
70  std::vector<T>& value() { return value_; }
71  const std::vector<T>& value() const { return value_; }
72 };
73 
75 template <typename T>
76 struct column_base<T, false> : column_base<T, true> {
78 
79  column_base() = default;
80  column_base(const T& rhs) = delete;
81  column_base(const std::vector<T>& rhs) = delete;
82 };
83 
84 } // namespace cxtream::stream
85 
90 #define CXTREAM_DEFINE_COLUMN(col_name, col_type) \
91 struct col_name : cxtream::stream::column_base<col_type> { \
92  using cxtream::stream::column_base<col_type>::column_base; \
93  static constexpr const char* name() { return #col_name; } \
94 };
95 
96 #endif
Base class for cxtream columns.
Definition: column.hpp:24