1 #ifndef JODA_PARAMETERPACK_H
2 #define JODA_PARAMETERPACK_H
17 template <std::
size_t k>
20 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
21 const std::string &name) {
22 if (k < parameters.size())
34 template <std::
size_t k,
class T>
36 typedef std::optional<typename T::ReturnT>
ReturnT;
39 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
40 const std::string &name) {
41 if (k >= parameters.size())
return;
42 return T::check(parameters, name);
46 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
48 if (k >= parameters.size())
return {};
49 return std::make_optional(T::extractValue(parameters));
59 template <std::
size_t k,
class T,
class Default>
64 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
65 const std::string &name) {
66 if (k >= parameters.size())
return;
67 return T::check(parameters, name);
71 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
73 if (k >= parameters.size())
return Default::value;
74 return T::extractValue(parameters, json, alloc);
79 static constexpr
bool value =
true;
83 static constexpr
bool value =
false;
93 template <std::
size_t k,
class T1,
class T2,
class Default>
95 typedef typename std::variant<typename T1::ReturnT, typename T2::ReturnT>
99 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
100 const std::string &name) {
102 T1::check(parameters, name);
104 T2::check(parameters, name);
109 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
112 return T1::extractValue(parameters, json, alloc);
114 T2::extractValue(parameters, json, alloc);
124 template <std::
size_t k>
129 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
130 const std::string &name) {
132 if (!(parameters[k]->isString() || parameters[k]->isAny()))
138 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
140 auto &val = parameters[k];
141 if (!val->isAtom()) {
142 auto *retPtr = val->getValue(json, alloc);
143 if (retPtr !=
nullptr && retPtr->IsString()) {
144 return retPtr->GetString();
146 }
else if (val->isString()) {
147 auto retVal = val->getAtomValue(json, alloc);
148 if (retVal.IsString()) {
149 return retVal.GetString();
161 template <std::
size_t k>
166 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
167 const std::string &name) {
169 if (!(parameters[k]->isBool() || parameters[k]->isAny()))
175 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
177 auto &val = parameters[k];
178 if (!val->isAtom()) {
179 auto *retPtr = val->getValue(json, alloc);
180 if (retPtr !=
nullptr && retPtr->IsBool()) {
181 return retPtr->GetBool();
183 }
else if (val->isBool()) {
184 auto retVal = val->getAtomValue(json, alloc);
185 if (retVal.IsBool()) {
186 return retVal.GetBool();
198 template <std::
size_t k>
203 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
204 const std::string &name) {
206 if (!(parameters[k]->isObject() || parameters[k]->isAny()))
212 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
214 auto ¶m = parameters[k];
218 template <
class Handler>
220 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
223 auto ¶m = parameters[k];
225 if (param->isAtom()) {
226 auto v = param->getAtomValue(json, alloc);
227 return v.Accept(handler);
229 return accepter.
Accept(param, json, alloc, handler);
238 template <std::
size_t k>
243 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
244 const std::string &name) {
250 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
252 auto ¶m = parameters[k];
256 template <
class Handler>
258 const std::vector<std::unique_ptr<IValueProvider>> ¶meters,
261 auto ¶m = parameters[k];
263 if (param->isAtom()) {
264 auto v = param->getAtomValue(json, alloc);
265 return v.Accept(handler);
267 return accepter.
Accept(param, json, alloc, handler);
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
Definition: RapidJsonDocument.h:22
Definition: IValueProvider.h:117
Definition: ValueAccepter.h:16
bool Accept(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc, Handler &h) const
Definition: ValueAccepter.h:32
Definition: IValueProvider.h:96
Definition: IValueProvider.h:46
Definition: IValueProvider.h:60
Definition: ParameterPack.h:8
IncompatibleTypeException()
Definition: ParameterPack.h:10
Definition: ParameterPack.h:6
@ IV_Object
Definition: IValueProvider.h:37
@ IV_Bool
Definition: IValueProvider.h:36
@ IV_String
Definition: IValueProvider.h:34
Definition: ParameterPack.h:239
ValueAccepter ReturnT
Definition: ParameterPack.h:240
static bool accept(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, Handler &handler, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:257
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:249
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:242
Definition: ParameterPack.h:162
bool ReturnT
Definition: ParameterPack.h:163
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:174
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:165
Definition: ParameterPack.h:82
static constexpr bool value
Definition: ParameterPack.h:83
Definition: ParameterPack.h:18
static constexpr void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:19
Definition: ParameterPack.h:199
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:202
ValueAccepter ReturnT
Definition: ParameterPack.h:200
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:211
static bool accept(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, Handler &handler, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:219
Definition: ParameterPack.h:35
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:38
std::optional< typename T::ReturnT > ReturnT
Definition: ParameterPack.h:36
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:45
Definition: ParameterPack.h:60
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:63
T::ReturnT ReturnT
Definition: ParameterPack.h:61
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:70
Definition: ParameterPack.h:94
std::variant< typename T1::ReturnT, typename T2::ReturnT > ReturnT
Definition: ParameterPack.h:96
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:98
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:108
Definition: ParameterPack.h:125
static void check(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const std::string &name)
Definition: ParameterPack.h:128
static ReturnT extractValue(const std::vector< std::unique_ptr< IValueProvider >> ¶meters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: ParameterPack.h:137
std::string ReturnT
Definition: ParameterPack.h:126
Definition: ParameterPack.h:78
static constexpr bool value
Definition: ParameterPack.h:79