5 #ifndef JODA_BINARYNUMBERPROVIDER_H
6 #define JODA_BINARYNUMBERPROVIDER_H
12 #define JODA_MATH_FUNC_NOOP "NOOP"
36 std::vector<std::unique_ptr<IValueProvider>> &¶meters,
41 DCHECK(
isAtom()) <<
"Only atom ReturnTypes allowed";
62 return params[0]->toString() +
" " + Calc::op +
" " +
67 std::unique_ptr<joda::query::IValueProvider>
duplicate()
const override {
74 for (
const auto ¶m :
params) {
75 c &= param->isConst();
88 tmplhs =
params[0]->getAtomValue(json, alloc);
91 lhs =
params[0]->getValue(json, alloc);
93 if (lhs ==
nullptr || !lhs->IsNumber())
return RJValue();
96 tmprhs =
params[1]->getAtomValue(json, alloc);
99 rhs =
params[1]->getValue(json, alloc);
101 if (rhs ==
nullptr || !rhs->IsNumber())
return RJValue();
103 if (lhs->IsUint64() && rhs->IsUint64())
104 return Calc::calculate(lhs->GetUint64(), rhs->GetUint64(), alloc);
105 if (lhs->IsInt64() && rhs->IsInt64())
106 return Calc::calculate(lhs->GetInt64(), rhs->GetInt64(), alloc);
107 return Calc::calculate(lhs->GetDouble(), rhs->GetDouble(), alloc);
112 DCHECK(!
isAtom()) <<
"Did not check for atom first";
122 for (
unsigned int i = 0; i <
params.size(); ++i) {
132 static constexpr
auto name =
"SUM";
133 static constexpr
auto op =
"+";
158 static constexpr
auto name =
"SUB";
159 static constexpr
auto op =
"-";
170 return RJValue(int64_t(lhs - rhs));
187 static constexpr
auto name =
"DIV";
188 static constexpr
auto op =
"/";
193 if (rhs == 0)
return RJValue();
199 if (rhs == 0)
return RJValue();
205 if (rhs == 0)
return RJValue();
216 static constexpr
auto name =
"PROD";
217 static constexpr
auto op =
"*";
242 static constexpr
auto name =
"MOD";
243 static constexpr
auto op =
"%";
248 if (rhs == 0)
return RJValue();
249 return RJValue(std::fmod(lhs, rhs));
254 if (rhs == 0)
return RJValue();
260 if (rhs == 0)
return RJValue();
271 static constexpr
auto name =
"POW";
277 double const res = std::pow(lhs, rhs);
278 if (!std::isfinite(res))
return RJValue();
284 double const res = std::pow(lhs, rhs);
285 if (!std::isfinite(res))
return RJValue();
291 double const res = std::pow(lhs, rhs);
292 if (!std::isfinite(res))
return RJValue();
303 static constexpr
auto name =
"ATAN2";
309 return RJValue(std::atan2(lhs, rhs));
314 return RJValue(std::atan2(lhs, rhs));
319 return RJValue(std::atan2(lhs, rhs));
#define JODA_MATH_FUNC_NOOP
Definition: BinaryNumberProvider.h:12
#define CREATE_FACTORY(FCLASS)
Definition: IValueProvider.h:20
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
Definition: BinaryNumberProvider.h:33
bool isConst() const override
Definition: BinaryNumberProvider.h:72
const RJValue * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: BinaryNumberProvider.h:110
RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: BinaryNumberProvider.h:80
std::string toString() const override
Definition: BinaryNumberProvider.h:57
joda::query::IValueType getReturnType() const override
Definition: BinaryNumberProvider.h:44
BinaryNumberProvider(std::vector< std::unique_ptr< IValueProvider >> &¶meters, bool opMode=false)
Definition: BinaryNumberProvider.h:35
std::string getName() const override
Definition: BinaryNumberProvider.h:48
void checkAllParamTypes()
Definition: BinaryNumberProvider.h:121
bool opMode
Definition: BinaryNumberProvider.h:114
std::unique_ptr< joda::query::IValueProvider > duplicate() const override
Definition: BinaryNumberProvider.h:67
Definition: IValueProvider.h:143
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
std::vector< std::unique_ptr< IValueProvider > > duplicateParameters() const
Definition: IValueProvider.cpp:104
void checkParamType(unsigned int i, IValueType expected)
Definition: IValueProvider.cpp:125
virtual std::string toString() const
Definition: IValueProvider.cpp:99
Definition: AttributeStatAggregator.h:12
BinaryNumberProvider< BinaryModCalculationFunction > ModuloProvider
Definition: BinaryNumberProvider.h:265
BinaryNumberProvider< BinaryAtan2CalculationFunction > Atan2Provider
Definition: BinaryNumberProvider.h:323
BinaryNumberProvider< BinarySumCalculationFunction > SumProvider
Definition: BinaryNumberProvider.h:152
BinaryNumberProvider< BinaryDivCalculationFunction > DivProvider
Definition: BinaryNumberProvider.h:210
BinaryNumberProvider< BinarySubCalculationFunction > SubtractProvider
Definition: BinaryNumberProvider.h:181
BinaryNumberProvider< BinaryProdCalculationFunction > ProductProvider
Definition: BinaryNumberProvider.h:236
BinaryNumberProvider< BinaryPowCalculationFunction > PowerProvider
Definition: BinaryNumberProvider.h:297
IValueType
Definition: IValueProvider.h:33
@ IV_Number
Definition: IValueProvider.h:35
Definition: BinaryNumberProvider.h:302
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:317
static constexpr auto op
Definition: BinaryNumberProvider.h:304
static constexpr auto name
Definition: BinaryNumberProvider.h:303
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:305
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:312
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:307
Definition: BinaryNumberProvider.h:186
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:189
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:191
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:203
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:197
static constexpr auto op
Definition: BinaryNumberProvider.h:188
static constexpr auto name
Definition: BinaryNumberProvider.h:187
Definition: BinaryNumberProvider.h:241
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:244
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:258
static constexpr auto name
Definition: BinaryNumberProvider.h:242
static constexpr auto op
Definition: BinaryNumberProvider.h:243
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:246
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:252
Definition: BinaryNumberProvider.h:270
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:282
static constexpr auto op
Definition: BinaryNumberProvider.h:272
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:289
static constexpr auto name
Definition: BinaryNumberProvider.h:271
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:273
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:275
Definition: BinaryNumberProvider.h:215
static constexpr auto name
Definition: BinaryNumberProvider.h:216
static constexpr auto op
Definition: BinaryNumberProvider.h:217
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:230
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:220
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:225
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:218
Definition: BinaryNumberProvider.h:157
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:175
static constexpr auto op
Definition: BinaryNumberProvider.h:159
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:160
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:162
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:167
static constexpr auto name
Definition: BinaryNumberProvider.h:158
Definition: BinaryNumberProvider.h:131
static constexpr auto op
Definition: BinaryNumberProvider.h:133
static constexpr joda::query::IValueType retType
Definition: BinaryNumberProvider.h:134
static constexpr auto name
Definition: BinaryNumberProvider.h:132
static RJValue calculate(int64_t lhs, int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:146
static RJValue calculate(u_int64_t lhs, u_int64_t rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:141
static RJValue calculate(double lhs, double rhs, RJMemoryPoolAlloc &alloc)
Definition: BinaryNumberProvider.h:136