12#include <spdlog/spdlog.h>
69 for (
const auto& child : other.
children)
72 children.emplace_back(std::make_unique<RouteArgDef>(*child));
74 children.emplace_back(nullptr);
80 :
type(std::move(other.type)),
requirement(std::move(other.requirement)),
children(std::move(other.children)) {}
84 std::vector<std::unique_ptr<RouteArgDef>>
children;
110 const std::string &
getData()
const;
124 const std::vector<std::unique_ptr<RouteArgDef>> &
getChildren()
const;
135 constexpr static const char ARRAY_START_IDENTIFIER =
'[';
136 constexpr static const char ARRAY_END_IDENTIFIER =
']';
138 constexpr static const unsigned int MAX_OBJECT_FIELDS = 5;
139 constexpr static const char OBJECT_START_IDENTIFIER =
'(';
140 constexpr static const char OBJECT_END_IDENTIFIER =
')';
141 constexpr static const char OBJECT_FIELDS_DELIMETER =
';';
146 typename T::value_type;
147 typename T::iterator;
154 std::is_array<T>::value ||
155 std::is_same_v<T, std::vector<typename T::value_type>> ||
156 std::is_same_v<T, std::list<typename T::value_type>>
162 template<
typename... Ts>
165 template<
typename T1,
typename T2>
171 && std::tuple_size<T>::value > 0
172 && std::tuple_size<T>::value < MAX_OBJECT_FIELDS;
230 template <IsTupleLike TupleT, std::
size_t Size>
233 template <IsTupleLike TupleT>
242 if(!t0)
return std::unexpected(t0.error());
245 if(!t1)
return std::unexpected(t1.error());
247 return std::make_tuple(*t0, *t1);
251 template <IsTupleLike TupleT>
260 if(!t0)
return std::unexpected(t0.error());
263 if(!t1)
return std::unexpected(t1.error());
266 if(!t2)
return std::unexpected(t2.error());
268 return std::make_tuple(*t0, *t1, *t2);
272 template <IsTupleLike TupleT>
281 if(!t0)
return std::unexpected(t0.error());
284 if(!t1)
return std::unexpected(t1.error());
287 if(!t2)
return std::unexpected(t2.error());
290 if(!t3)
return std::unexpected(t3.error());
292 return std::make_tuple(*t0, *t1, *t2, *t3);
297 template<IsTupleLike TupleT>
304 std::string data = arg.
getData();
310 data = data.substr(1, data.size() - 2);
313 std::vector<std::string> values_str;
314 std::size_t begin = 0;
317 while ((end = data.find(OBJECT_FIELDS_DELIMETER, begin)) != std::string::npos) {
318 values_str.push_back(data.substr(begin, (end - begin)));
322 values_str.push_back(data.substr(begin));
327 template<IsSequenceContainer ContainerT>
330 using T =
typename ContainerT::value_type;
336 std::string data = arg.
getData();
342 data = data.substr(1, data.size() - 2);
345 constexpr static const char array_values_delimeter =
',';
347 std::vector<std::string> values_str;
348 std::size_t begin = 0;
351 while ((end = data.find(array_values_delimeter, begin)) != std::string::npos) {
352 values_str.push_back(data.substr(begin, (end - begin)));
356 values_str.push_back(data.substr(begin));
359 const auto & array_type = *arg.
getChildren().at(0);
361 for (
const auto & value_str : values_str)
365 if(!parsed_value)
return std::unexpected(parsed_value.error());
367 values.emplace_back(*parsed_value);
375struct std::formatter<
dcn::server::RouteArgType> : std::formatter<std::string> {
389 return formatter<string>::format(
"", ctx);
394struct std::formatter<
dcn::server::RouteArgRequirement> : std::formatter<std::string> {
404 return formatter<string>::format(
"", ctx);
409struct std::formatter<
dcn::server::RouteArg> : std::formatter<std::string> {
411 return formatter<string>::format(
A class representing a route argument.
Definition route_arg.hpp:94
const std::vector< std::unique_ptr< RouteArgDef > > & getChildren() const
Gets the children of the route argument.
Definition route_arg.cpp:27
RouteArgRequirement getRequirement() const
Gets the requirement of the route argument.
Definition route_arg.cpp:22
RouteArgType getType() const
Gets the type of the route argument.
Definition route_arg.cpp:12
const std::string & getData() const
Gets the data associated with the route argument.
Definition route_arg.cpp:17
RouteArg(RouteArgDef def, std::string data)
Definition route_arg.cpp:5
Definition route_arg.hpp:145
Definition route_arg.hpp:152
Definition route_arg.hpp:169
parse::Result< T > parseRouteArgAs(const server::RouteArg &arg)
Definition route_arg.hpp:298
parse::Result< server::RouteArgDef > parseRouteArgDefFromString(const std::string str)
Parses a string to a RouteArgDef.
Definition route_arg.cpp:47
parse::Result< std::size_t > parseRouteArgAs< std::size_t >(const server::RouteArg &arg)
Parses a RouteArg as a unsigned integer.
Definition route_arg.cpp:188
parse::Result< std::string > parseRouteArgAs< std::string >(const server::RouteArg &arg)
Parses a RouteArg as a string.
Definition route_arg.cpp:257
server::RouteArgType parseRouteArgTypeFromString(const std::string &str)
Parses a string to a RouteArgType.
Definition route_arg.cpp:35
parse::Result< std::uint32_t > parseRouteArgAs< std::uint32_t >(const server::RouteArg &arg)
Parses a RouteArg as a 32bit unsigned integer.
Definition route_arg.cpp:223
std::expected< T, ParseError > Result
Definition parse_error.hpp:26
RouteArgRequirement
Enum to represent the requirement of a route argument.
Definition route_arg.hpp:42
@ Unknown
Definition route_arg.hpp:44
@ required
Definition route_arg.hpp:47
@ optional
Definition route_arg.hpp:46
RouteArgType
Enum to represent the type of a route argument.
Definition route_arg.hpp:24
@ unsigned_integer
Definition route_arg.hpp:29
@ base58
Definition route_arg.hpp:30
@ Unknown
Definition route_arg.hpp:26
@ object
Definition route_arg.hpp:33
@ character
Definition route_arg.hpp:28
@ string
Definition route_arg.hpp:31
@ array
Definition route_arg.hpp:32
Definition decentralised_art.hpp:35
Definition parse_error.hpp:11
@ TYPE_MISMATCH
Definition parse_error.hpp:18
@ INVALID_VALUE
Definition parse_error.hpp:16
parse::Result< TupleT > operator()(const std::vector< std::unique_ptr< dcn::server::RouteArgDef > > &defs, const std::vector< std::string > &values_str)
Definition route_arg.hpp:236
parse::Result< TupleT > operator()(const std::vector< std::unique_ptr< dcn::server::RouteArgDef > > &defs, const std::vector< std::string > &values_str)
Definition route_arg.hpp:254
parse::Result< TupleT > operator()(const std::vector< std::unique_ptr< dcn::server::RouteArgDef > > &defs, const std::vector< std::string > &values_str)
Definition route_arg.hpp:275
Definition route_arg.hpp:231
Definition route_arg.hpp:160
A pair of RouteArgType and RouteArgRequirement.
Definition route_arg.hpp:57
RouteArgDef(RouteArgDef &&other) noexcept
Definition route_arg.hpp:79
RouteArgDef(RouteArgType type, RouteArgRequirement requirement)
Definition route_arg.hpp:58
std::vector< std::unique_ptr< RouteArgDef > > children
Definition route_arg.hpp:84
RouteArgType type
Definition route_arg.hpp:82
RouteArgDef(const RouteArgDef &other)
Definition route_arg.hpp:65
RouteArgDef(RouteArgType type, RouteArgRequirement requirement, std::vector< std::unique_ptr< RouteArgDef > > children)
Definition route_arg.hpp:61
RouteArgRequirement requirement
Definition route_arg.hpp:83