SRS-control 0.1.4
Loading...
Searching...
No Matches
DataConverterBase.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <boost/asio/experimental/coro.hpp>
6#include <boost/asio/use_awaitable.hpp>
7#include <boost/thread/future.hpp>
8#include <cstddef>
9#include <expected>
10#include <fmt/ranges.h>
11#include <gsl/gsl-lite.hpp>
12#include <string>
13#include <string_view>
14
15namespace srs::process
16{
17
18 template <typename Input, typename Output>
20 {
21 public:
22 using InputType = Input;
23 using OutputType = Output;
24
25 using enum DataConvertOptions;
26
27 using RunResult = std::expected<OutputType, std::string_view>;
28
29 explicit BaseTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines = 1)
30 : previous_conversion_{ prev_convert }
31 , name_{ name }
32 , n_lines_{ n_lines }
33 {
34 }
35
36 [[nodiscard]] auto get_n_lines() const -> std::size_t { return n_lines_; }
37 [[nodiscard]] auto get_required_conversion() const -> DataConvertOptions { return previous_conversion_; }
38 [[nodiscard]] auto get_name() const -> std::string_view { return name_; };
39 [[nodiscard]] auto get_name_str() const -> std::string { return std::string{ name_ }; };
40
41 private:
43 std::string name_ = "empty";
44 std::size_t n_lines_ = 1;
45 };
46
47 template <DataConvertOptions Conversion, typename Input, typename Output>
48 class ConverterTask : public BaseTask<Input, Output>
49 {
50 public:
51 constexpr static auto converter_type = Conversion;
52 explicit ConverterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines = 1)
53 : BaseTask<Input, Output>{ name, prev_convert, n_lines }
54 {
55 }
56 };
57
58 template <DataWriterOption writer, typename Input, typename Output>
59 class WriterTask : public BaseTask<Input, Output>
60 {
61 public:
62 constexpr static auto writer_type = writer;
63 explicit WriterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines = 1)
64 : BaseTask<Input, Output>{ name, prev_convert, n_lines }
65 {
66 }
67 };
68} // namespace srs::process
BaseTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
auto get_n_lines() const -> std::size_t
auto get_name_str() const -> std::string
process::DataConvertOptions previous_conversion_
std::expected< OutputType, std::string_view > RunResult
auto get_required_conversion() const -> DataConvertOptions
auto get_name() const -> std::string_view
ConverterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
WriterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
static constexpr auto writer_type