5 #ifndef JODA_IVALUEPROVIDER_H
6 #define JODA_IVALUEPROVIDER_H
7 #include <glog/logging.h>
8 #include <rapidjson/document.h>
9 #include <rapidjson/fwd.h>
12 #include <experimental/optional>
20 #define CREATE_FACTORY(FCLASS) \
21 static std::unique_ptr<IValueProvider> _FACTORY( \
22 std::vector<std::unique_ptr<IValueProvider>> &¶ms) { \
23 return std::make_unique<FCLASS>(std::move(params)); \
49 virtual const char *
what()
const throw() {
return whatStr.c_str(); }
63 const std::string &name) {
64 whatStr = name +
": Parameter " + std::to_string(i) +
65 " is of wrong type. Expected: ";
86 DCHECK(
false) <<
"Expected null parameter? O.o";
99 whatStr = name +
": Wrong number of parameters";
102 const std::string &name,
bool min =
false) {
104 whatStr = name +
": Expected ";
108 whatStr += std::to_string(expected) +
109 " parameters, but got " + std::to_string(count);
122 whatStr = name +
": Missing parameter " + std::to_string(i);
133 const std::string &name) {
135 whatStr = name +
": Parameter " + std::to_string(i) +
" has to be a constant.";
152 std::vector<std::unique_ptr<IValueProvider>> &¶meters);
188 virtual std::unique_ptr<IValueProvider>
duplicate()
const = 0;
192 virtual std::string
toString()
const;
223 std::vector<std::string> ret;
233 for (
auto &¶m :
params) {
234 param->getAttributes(vec);
257 if (lhs ==
nullptr)
return false;
263 rhs = other->
getValue(json, tmpAlloc);
265 if (rhs ==
nullptr)
return false;
267 auto lhsType = lhs->GetType();
268 auto rhsType = rhs->GetType();
269 if (lhsType != rhsType)
return false;
271 if (lhsType == rapidjson::kTrueType && rhsType == rapidjson::kTrueType)
273 if (lhsType == rapidjson::kFalseType && rhsType == rapidjson::kFalseType)
276 if (lhsType == rapidjson::kNumberType &&
277 rhsType == rapidjson::kNumberType) {
278 if (lhs->IsUint64() && rhs->IsUint64())
279 return lhs->GetUint64() == rhs->GetUint64();
280 if (lhs->IsInt64() && rhs->IsInt64())
281 return lhs->GetInt64() == rhs->GetInt64();
282 return fabs(lhs->GetDouble() - rhs->GetDouble()) <
283 std::numeric_limits<double>::epsilon();
286 if (lhsType == rapidjson::kStringType &&
287 rhsType == rapidjson::kStringType) {
288 return strcmp(lhs->GetString(), rhs->GetString()) == 0;
291 if (lhsType == rapidjson::kNullType && rhsType == rapidjson::kNullType) {
320 const std::unique_ptr<IValueProvider> &val,
323 if (!val->isAtom()) {
324 auto *retPtr = val->getValue(json, alloc);
325 if (retPtr !=
nullptr && retPtr->IsString()) {
326 ret = retPtr->GetString();
329 }
else if (val->isString()) {
330 auto retVal = val->getAtomValue(json, alloc);
331 if (retVal.IsString()) {
332 ret = retVal.GetString();
373 std::vector<std::unique_ptr<IValueProvider>>
params;
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
Definition: IValueProvider.h:130
ConstParameterException(unsigned int i, const std::string &name)
Definition: IValueProvider.h:132
Definition: IValueProvider.h:143
virtual std::string getName() const =0
void checkMinParamSize(unsigned int expected)
Definition: IValueProvider.cpp:118
virtual bool isAny() const
Definition: IValueProvider.h:214
IValueProvider()
Definition: IValueProvider.cpp:84
virtual bool isConst() const =0
std::vector< std::unique_ptr< IValueProvider > > params
Definition: IValueProvider.h:373
void checkParamSize(unsigned int expected)
Definition: IValueProvider.cpp:112
virtual bool isAtom() const
Definition: IValueProvider.h:215
virtual bool isArray() const
Definition: IValueProvider.h:212
std::vector< std::unique_ptr< IValueProvider > > duplicateParameters() const
Definition: IValueProvider.cpp:104
static void replaceConstSubexpressions(std::unique_ptr< IValueProvider > &val)
Definition: IValueProvider.cpp:11
virtual ~IValueProvider()=default
virtual std::unique_ptr< IValueProvider > duplicate() const =0
bool getParamString(std::string &ret, const std::unique_ptr< IValueProvider > &val, const RapidJsonDocument &json) const
Definition: IValueProvider.h:319
virtual bool equalizable() const
Definition: IValueProvider.h:309
bool equal(IValueProvider *other, const RapidJsonDocument &json) const
Definition: IValueProvider.h:244
void checkOptionalParamType(unsigned int i, IValueType expected)
Definition: IValueProvider.cpp:134
virtual IValueType getReturnType() const =0
virtual bool isBool() const
Definition: IValueProvider.h:210
void checkParamType(unsigned int i, IValueType expected)
Definition: IValueProvider.cpp:125
virtual RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const =0
std::string getParameterStringRepresentation() const
Definition: IValueProvider.cpp:87
virtual bool comparable() const
Definition: IValueProvider.h:302
virtual std::string toString() const
Definition: IValueProvider.cpp:99
virtual bool isObject() const
Definition: IValueProvider.h:211
virtual RJValue const * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const =0
virtual std::vector< std::string > getAttributes() const
Definition: IValueProvider.h:222
virtual bool isNumber() const
Definition: IValueProvider.h:209
static bool constBoolCheck(std::unique_ptr< IValueProvider > &val)
Definition: IValueProvider.cpp:62
virtual bool isString() const
Definition: IValueProvider.h:208
virtual void getAttributes(std::vector< std::string > &vec) const
Definition: IValueProvider.h:232
virtual bool isNull() const
Definition: IValueProvider.h:213
Definition: IValueProvider.h:117
MissingParameterException(unsigned int i, const std::string &name)
Definition: IValueProvider.h:119
Definition: IValueProvider.h:96
WrongParameterCountException(const std::string &name)
Definition: IValueProvider.h:98
WrongParameterCountException(unsigned int count, unsigned int expected, const std::string &name, bool min=false)
Definition: IValueProvider.h:101
Definition: IValueProvider.h:46
virtual const char * what() const
Definition: IValueProvider.h:49
WrongParameterException(const std::string &whatStr)
Definition: IValueProvider.h:48
std::string whatStr
Definition: IValueProvider.h:53
WrongParameterException()=default
Definition: IValueProvider.h:60
WrongParameterTypeException(unsigned int i, IValueType expected, const std::string &name)
Definition: IValueProvider.h:62
Definition: AttributeStatAggregator.h:12
IValueType
Definition: IValueProvider.h:33
@ IV_Object
Definition: IValueProvider.h:37
@ IV_Number
Definition: IValueProvider.h:35
@ IV_Bool
Definition: IValueProvider.h:36
@ IV_Null
Definition: IValueProvider.h:40
@ IV_String
Definition: IValueProvider.h:34
@ IV_Any
Definition: IValueProvider.h:39
@ IV_Array
Definition: IValueProvider.h:38