SRS-control 0.1.4
Loading...
Searching...
No Matches
DataConvertOptions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cstdint>
6#include <fmt/base.h>
7#include <fmt/format.h>
8#include <string_view>
9#include <utility>
10
11namespace srs::process
12{
23
24 constexpr auto convert_option_to_string(DataConvertOptions option) -> std::string_view
25 {
26 using enum DataConvertOptions;
27 switch (option)
28 {
29 case none:
30 return std::string_view{ "none" };
31 case raw:
32 return std::string_view{ "raw" };
33 case raw_frame:
34 return std::string_view{ "raw_frame" };
35 case structure:
36 return std::string_view{ "structure" };
38 return std::string_view{ "structure_to_proto" };
39 case proto:
40 return std::string_view{ "proto" };
41 case proto_frame:
42 return std::string_view{ "proto_frame" };
43 default:
44 return std::string_view{ "invalid" };
45 }
46 }
47
49 {
51 : dependee{ option }
52 , depender{ next_option }
53 {
54 }
57 };
58
59 constexpr auto EMPTY_CONVERT_OPTION_COUNT_MAP = []()
60 {
61 using enum DataConvertOptions;
62 return std::array{ std::make_pair(raw, 0), std::make_pair(raw_frame, 0),
63 std::make_pair(structure, 0), std::make_pair(structure_to_proto, 0),
64 std::make_pair(proto, 0), std::make_pair(proto_frame, 0) };
65 }();
66
77
78 // NOLINTBEGIN (misc-no-recursion)
79 constexpr auto convert_option_has_dependency(DataConvertOptions dependee, DataConvertOptions depender) -> bool
80 {
81 // fmt::println("-----------dependee: {}, depender: {}",
82 // convert_option_to_string(dependee),
83 // convert_option_to_string(dependee));
84 if (dependee == depender)
85 {
86 return true;
87 }
88
89 return std::ranges::any_of(CONVERT_OPTION_RELATIONS,
90 [dependee, depender](ConvertOptionRelation relation) -> bool
91 {
92 if (dependee == relation.dependee)
93 {
94 if (depender == relation.depender)
95 {
96 return true;
97 }
98 return convert_option_has_dependency(relation.depender, depender);
99 }
100
101 // nothing is depending on it
102 return false;
103 });
104 }
105 // NOLINTEND (misc-no-recursion)
106
107} // namespace srs::process
108
109template <>
110class fmt::formatter<srs::process::DataConvertOptions>
111{
112 public:
113 static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
114 template <typename FmtContent>
115 constexpr auto format(srs::process::DataConvertOptions option, FmtContent& ctn) const
116 {
117 // TODO: DUPLICATES
119 switch (option)
120 {
121 case none:
122 return fmt::format_to(ctn.out(), "none");
123 case raw:
124 return fmt::format_to(ctn.out(), "raw");
125 case raw_frame:
126 return fmt::format_to(ctn.out(), "raw_frame");
127 case structure:
128 return fmt::format_to(ctn.out(), "structure");
129 case proto:
130 return fmt::format_to(ctn.out(), "proto");
131 case proto_frame:
132 return fmt::format_to(ctn.out(), "proto_frame");
133 case structure_to_proto:
134 return fmt::format_to(ctn.out(), "structure_to_proto");
135 default:
136 return fmt::format_to(ctn.out(), "invalid");
137 }
138 }
139};
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(srs::process::DataConvertOptions option, FmtContent &ctn) const
constexpr auto EMPTY_CONVERT_OPTION_COUNT_MAP
constexpr auto CONVERT_OPTION_RELATIONS
constexpr auto convert_option_to_string(DataConvertOptions option) -> std::string_view
constexpr auto convert_option_has_dependency(DataConvertOptions dependee, DataConvertOptions depender) -> bool
constexpr ConvertOptionRelation(DataConvertOptions option, DataConvertOptions next_option)