13#include <spdlog/spdlog.h>
83 std::vector<std::unique_ptr<RouteArgDef>>
children;
109 const std::string &
getData()
const;
123 const std::vector<std::unique_ptr<RouteArgDef>> &
getChildren()
const;
134 constexpr static const char ARRAY_START_IDENTIFIER =
'[';
135 constexpr static const char ARRAY_END_IDENTIFIER =
']';
137 constexpr static const unsigned int MAX_OBJECT_FIELDS = 5;
138 constexpr static const char OBJECT_START_IDENTIFIER =
'(';
139 constexpr static const char OBJECT_END_IDENTIFIER =
')';
140 constexpr static const char OBJECT_FIELDS_DELIMETER =
';';
145 typename T::value_type;
146 typename T::iterator;
153 std::is_array<T>::value ||
154 std::is_same_v<T, std::vector<typename T::value_type>> ||
155 std::is_same_v<T, std::list<typename T::value_type>>
159 struct is_tuple_like_impl : std::false_type {};
161 template<
typename...
Ts>
162 struct is_tuple_like_impl<std::
tuple<Ts...>> : std::true_type {};
164 template<
typename T1,
typename T2>
165 struct is_tuple_like_impl<std::
pair<T1, T2>> : std::true_type {};
170 && std::tuple_size<T>::value > 0
171 && std::tuple_size<T>::value < MAX_OBJECT_FIELDS;
193 std::optional<RouteArgDef> parseRouteArgDefFromString(
const std::string
str);
197 std::optional<T> parseRouteArgAs(
const RouteArg &
arg);
209 std::optional<std::size_t> parseRouteArgAs<std::size_t>(
const RouteArg &
arg);
221 std::optional<std::uint32_t> parseRouteArgAs<std::uint32_t>(
const RouteArg &
arg);
233 std::optional<std::string> parseRouteArgAs<std::string>(
const RouteArg &
arg);
236 template <IsTupleLike TupleT, std::
size_t Size>
239 template <IsTupleLike TupleT>
240 struct TupleParser<
TupleT, 2>
242 std::optional<TupleT> operator()(
const std::vector<std::unique_ptr<dcn::RouteArgDef>> &
defs,
const std::vector<std::string> &
values_str)
244 if(
values_str.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
245 if(
defs.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
250 if(!
t0 || !
t1)
return std::nullopt;
252 return std::make_tuple(*
t0, *
t1);
256 template <IsTupleLike TupleT>
257 struct TupleParser<
TupleT, 3>
259 std::optional<TupleT> operator()(
const std::vector<std::unique_ptr<dcn::RouteArgDef>> &
defs,
const std::vector<std::string> &
values_str)
261 if(
values_str.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
262 if(
defs.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
268 if(!
t0 || !
t1 || !
t2)
return std::nullopt;
270 return std::make_tuple(*
t0, *
t1, *
t2);
274 template <IsTupleLike TupleT>
275 struct TupleParser<
TupleT, 4>
277 std::optional<TupleT> operator()(
const std::vector<std::unique_ptr<dcn::RouteArgDef>> &
defs,
const std::vector<std::string> &
values_str)
279 if(
values_str.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
280 if(
defs.size() != std::tuple_size<TupleT>::value)
return std::nullopt;
287 if(!
t0 || !
t1 || !
t2 || !
t3)
return std::nullopt;
289 return std::make_tuple(*
t0, *
t1, *
t2, *
t3);
294 template<IsTupleLike TupleT>
295 std::optional<TupleT> parseRouteArgAs(
const RouteArg&
arg)
298 if(std::tuple_size<TupleT>::value == 0)
return std::nullopt;
299 if(
arg.getChildren().size() != std::tuple_size<TupleT>::value)
return std::nullopt;
301 std::string
data =
arg.getData();
302 if(
data.empty())
return std::nullopt;
303 if(
data.front() != OBJECT_START_IDENTIFIER)
return std::nullopt;
304 if(
data.back() != OBJECT_END_IDENTIFIER)
return std::nullopt;
311 std::size_t
begin = 0;
314 while ((
end =
data.find(OBJECT_FIELDS_DELIMETER,
begin)) != std::string::npos) {
324 template<IsSequenceContainer ContainerT>
325 std::optional<ContainerT> parseRouteArgAs(
const RouteArg&
arg)
327 using T =
typename ContainerT::value_type;
330 if(
arg.getChildren().size() != 1)
return std::nullopt;
331 if(
arg.getChildren().at(0) ==
nullptr)
return std::nullopt;
333 std::string
data =
arg.getData();
334 if(
data.empty())
return std::nullopt;
335 if(
data.front() != ARRAY_START_IDENTIFIER)
return std::nullopt;
336 if(
data.back() != ARRAY_END_IDENTIFIER)
return std::nullopt;
345 std::size_t
begin = 0;
373struct std::formatter<
dcn::RouteArgType> : std::formatter<std::string> {
387 return formatter<string>::format(
"", ctx);
392struct std::formatter<
dcn::RouteArgRequirement> : std::formatter<std::string> {
402 return formatter<string>::format(
"", ctx);
407struct std::formatter<
dcn::RouteArg> : std::formatter<std::string> {
409 return formatter<string>::format(
A class representing a route argument.
Definition route_arg.hpp:93
RouteArgType getType() const
Gets the type of the route argument.
Definition route_arg.cpp:12
RouteArgRequirement getRequirement() const
Gets the requirement of the route argument.
Definition route_arg.cpp:22
const std::string & getData() const
Gets the data associated with the route argument.
Definition route_arg.cpp:17
const std::vector< std::unique_ptr< RouteArgDef > > & getChildren() const
Gets the children of the route argument.
Definition route_arg.cpp:27
Definition route_arg.hpp:144
Definition route_arg.hpp:151
Definition route_arg.hpp:168
Definition decentralised_art.hpp:30
RouteArgRequirement
Enum to represent the requirement of a route argument.
Definition route_arg.hpp:41
RouteArgType
Enum to represent the type of a route argument.
Definition route_arg.hpp:23
A pair of RouteArgType and RouteArgRequirement.
Definition route_arg.hpp:56
RouteArgType type
Definition route_arg.hpp:81
RouteArgRequirement requirement
Definition route_arg.hpp:82
RouteArgDef(const RouteArgDef &other)
Definition route_arg.hpp:64
RouteArgDef(RouteArgDef &&other) noexcept
Definition route_arg.hpp:78
RouteArgDef(RouteArgType type, RouteArgRequirement requirement)
Definition route_arg.hpp:57
std::vector< std::unique_ptr< RouteArgDef > > children
Definition route_arg.hpp:83
RouteArgDef(RouteArgType type, RouteArgRequirement requirement, std::vector< std::unique_ptr< RouteArgDef > > children)
Definition route_arg.hpp:60