12 #include <hipipe/build_config.hpp> 14 #ifdef HIPIPE_BUILD_PYTHON 15 #include <hipipe/core/python/utility/ndim_vector_converter.hpp> 18 #include <initializer_list> 33 template<
typename Column>
34 std::runtime_error extraction_error()
const 36 return std::runtime_error{
37 std::string{
"Trying to extract column `"} + Column{}.
name()
38 +
"` from a column of type `" + this->
name() +
"`."};
57 template<
typename Column>
61 return dynamic_cast<Column&
>(*this).data();
62 }
catch (
const std::bad_cast&) {
63 throw extraction_error<Column>();
70 template<
typename Column>
71 const typename Column::data_type&
extract()
const 74 return dynamic_cast<const Column&
>(*this).data();
75 }
catch (
const std::bad_cast&) {
76 throw extraction_error<Column>();
86 virtual std::string
name()
const = 0;
91 virtual std::size_t
size()
const = 0;
96 virtual void push_back(std::unique_ptr<abstract_column> rhs) = 0;
101 virtual std::unique_ptr<abstract_column>
take(std::size_t n) = 0;
105 #ifdef HIPIPE_BUILD_PYTHON 106 virtual boost::python::object to_python() = 0;
120 template <
typename ColumnName,
typename ExampleType>
145 template <
typename... Args>
147 : data_{std::forward<Args>(args)...}
153 std::size_t
size()
const override 176 std::unique_ptr<abstract_column>
take(std::size_t n)
override 178 if (n > data_.size()) {
179 throw std::runtime_error{
"hipipe: Attempting to take " 184 std::move(data_.begin(), data_.begin() + n, taken_examples.begin());
185 data_.erase(data_.begin(), data_.begin() + n);
186 return std::make_unique<ColumnName>(std::move(taken_examples));
205 void push_back(std::unique_ptr<abstract_column> rhs)
override 208 ColumnName& typed_rhs =
dynamic_cast<ColumnName&
>(*rhs);
209 data_.reserve(data_.size() + typed_rhs.data_.size());
211 data_.push_back(std::move(example));
213 }
catch (
const std::bad_cast&) {
214 throw std::runtime_error{
"hipipe: Attempting to push back " 215 "column `" + rhs->name() +
"` to column `" +
name() +
"."};
236 #ifdef HIPIPE_BUILD_PYTHON 237 boost::python::object to_python()
override 239 return hipipe::python::utility::to_python(std::move(data_));
251 #define HIPIPE_DEFINE_COLUMN(column_name_, example_type_) \ 252 struct column_name_ : hipipe::stream::column_base<column_name_, example_type_> { \ 253 using hipipe::stream::column_base<column_name_, example_type_>::column_base; \ 254 std::string name() const override { return #column_name_; } \ const Column::data_type & extract() const
virtual std::string name() const =0
column_base(Args &&... args)
The constructor.
data_type & data()
Get a reference to the stored vector of examples.
virtual std::unique_ptr< abstract_column > take(std::size_t n)=0
virtual void push_back(std::unique_ptr< abstract_column > rhs)=0
std::size_t size() const override
Get the number of examples in this column.
void push_back(std::unique_ptr< abstract_column > rhs) override
Concatenate the examples from two columns of the same type.
std::vector< example_type > data_type
The type of multiple examples. This is what the column actually stores.
virtual std::size_t size() const =0
Retrieve the number of examples stored in the column.
std::string to_string(const T &value)
Convert the given type to std::string.
const data_type & data() const
Get a const reference to the stored vector of examples.
Column::data_type & extract()
std::unique_ptr< abstract_column > take(std::size_t n) override
Steal the given number of examples from this column and create a new column out of those...
Abstract base class for HiPipe columns.
ExampleType example_type
The type of a single example.
Implementation stub of a column defined by HIPIPE_DEFINE_COLUMN macro.