5 #ifndef JODA_UNARYNUMBERPROVIDER_H
6 #define JODA_UNARYNUMBERPROVIDER_H
12 #define degreesToRadians(angleDegrees) ((angleDegrees)*M_PI / 180.0)
13 #define radiansToDegrees(angleRadians) ((angleRadians)*180.0 / M_PI)
34 std::vector<std::unique_ptr<IValueProvider>> &¶meters)
38 DCHECK(
isAtom()) <<
"Only atom ReturnTypes allowed";
45 std::string
getName()
const override {
return Calc::name; };
51 std::unique_ptr<joda::query::IValueProvider>
duplicate()
const override {
57 for (
const auto ¶m :
params) {
58 c &= param->isConst();
66 auto val =
params[0]->getAtomValue(json, alloc);
67 if (!val.IsNumber())
return RJValue();
68 if (val.IsUint64())
return Calc::calculate(val.GetUint64(), alloc);
69 if (val.IsInt64())
return Calc::calculate(val.GetInt64(), alloc);
70 return Calc::calculate(val.GetDouble(), alloc);
72 auto val =
params[0]->getValue(json, alloc);
73 if (val ==
nullptr || !val->IsNumber())
return RJValue();
74 if (val->IsUint64())
return Calc::calculate(val->GetUint64(), alloc);
75 if (val->IsInt64())
return Calc::calculate(val->GetInt64(), alloc);
76 return Calc::calculate(val->GetDouble(), alloc);
82 DCHECK(!
isAtom()) <<
"Did not check for atom first";
90 for (
unsigned int i = 0; i <
params.size(); ++i) {
100 static constexpr
auto name =
"ABS";
122 static constexpr
auto name =
"ROUND";
126 return RJValue(std::round(val));
144 static constexpr
auto name =
"TRUNC";
148 return RJValue(std::trunc(val));
166 static constexpr
auto name =
"SQRT";
171 return RJValue(std::sqrt(val));
176 return RJValue(std::sqrt(val));
181 return RJValue(std::sqrt(val));
191 static constexpr
auto name =
"CEIL";
195 return RJValue(std::ceil(val));
213 static constexpr
auto name =
"FLOOR";
217 return RJValue(std::floor(val));
235 static constexpr
auto name =
"DEGREES";
257 static constexpr
auto name =
"RADIANS";
279 static constexpr
auto name =
"ACOS";
283 if (val < -1 || val > 1)
return RJValue();
284 return RJValue(std::acos(val));
289 return RJValue(std::acos(val));
293 if (val < -1 || val > 1)
return RJValue();
294 return RJValue(std::acos(val));
304 static constexpr
auto name =
"ASIN";
308 if (val < -1 || val > 1)
return RJValue();
309 return RJValue(std::asin(val));
314 return RJValue(std::asin(val));
318 if (val < -1 || val > 1)
return RJValue();
319 return RJValue(std::asin(val));
329 static constexpr
auto name =
"ATAN";
333 return RJValue(std::atan(val));
337 return RJValue(std::atan(val));
341 return RJValue(std::atan(val));
351 static constexpr
auto name =
"COS";
373 static constexpr
auto name =
"SIN";
395 static constexpr
auto name =
"TAN";
#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
#define radiansToDegrees(angleRadians)
Definition: UnaryNumberProvider.h:13
#define degreesToRadians(angleDegrees)
Definition: UnaryNumberProvider.h:12
Definition: RapidJsonDocument.h:22
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: UnaryNumberProvider.h:31
UnaryNumberProvider(std::vector< std::unique_ptr< IValueProvider >> &¶meters)
Definition: UnaryNumberProvider.h:33
std::string getName() const override
Definition: UnaryNumberProvider.h:45
bool isConst() const override
Definition: UnaryNumberProvider.h:55
std::string toString() const override
Definition: UnaryNumberProvider.h:47
joda::query::IValueType getReturnType() const override
Definition: UnaryNumberProvider.h:41
std::unique_ptr< joda::query::IValueProvider > duplicate() const override
Definition: UnaryNumberProvider.h:51
void checkAllParamTypes()
Definition: UnaryNumberProvider.h:89
const RJValue * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: UnaryNumberProvider.h:80
RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: UnaryNumberProvider.h:63
Definition: AttributeStatAggregator.h:12
UnaryNumberProvider< UnaryAcosCalculationFunction > AcosProvider
Definition: UnaryNumberProvider.h:298
UnaryNumberProvider< UnaryCeilCalculationFunction > CeilProvider
Definition: UnaryNumberProvider.h:207
UnaryNumberProvider< UnarySqrtCalculationFunction > SqrtProvider
Definition: UnaryNumberProvider.h:185
UnaryNumberProvider< UnaryTanCalculationFunction > TanProvider
Definition: UnaryNumberProvider.h:411
UnaryNumberProvider< UnaryAsinCalculationFunction > AsinProvider
Definition: UnaryNumberProvider.h:323
UnaryNumberProvider< UnaryDegreesCalculationFunction > DegreesProvider
Definition: UnaryNumberProvider.h:251
UnaryNumberProvider< UnaryAbsCalculationFunction > AbsProvider
Definition: UnaryNumberProvider.h:116
UnaryNumberProvider< UnaryFloorCalculationFunction > FloorProvider
Definition: UnaryNumberProvider.h:229
UnaryNumberProvider< UnaryRadiansCalculationFunction > RadiansProvider
Definition: UnaryNumberProvider.h:273
UnaryNumberProvider< UnaryAtanCalculationFunction > AtanProvider
Definition: UnaryNumberProvider.h:345
UnaryNumberProvider< UnaryRoundCalculationFunction > RoundProvider
Definition: UnaryNumberProvider.h:138
UnaryNumberProvider< UnaryTruncCalculationFunction > TruncProvider
Definition: UnaryNumberProvider.h:160
UnaryNumberProvider< UnarySinCalculationFunction > SinProvider
Definition: UnaryNumberProvider.h:389
UnaryNumberProvider< UnaryCosCalculationFunction > CosProvider
Definition: UnaryNumberProvider.h:367
IValueType
Definition: IValueProvider.h:33
@ IV_Number
Definition: IValueProvider.h:35
Definition: UnaryNumberProvider.h:99
static constexpr auto name
Definition: UnaryNumberProvider.h:100
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:101
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:103
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:111
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:107
Definition: UnaryNumberProvider.h:278
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:280
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:282
static constexpr auto name
Definition: UnaryNumberProvider.h:279
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:292
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:287
Definition: UnaryNumberProvider.h:303
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:307
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:305
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:317
static constexpr auto name
Definition: UnaryNumberProvider.h:304
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:312
Definition: UnaryNumberProvider.h:328
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:340
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:336
static constexpr auto name
Definition: UnaryNumberProvider.h:329
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:332
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:330
Definition: UnaryNumberProvider.h:190
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:192
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:194
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:198
static constexpr auto name
Definition: UnaryNumberProvider.h:191
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:202
Definition: UnaryNumberProvider.h:350
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:358
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:352
static constexpr auto name
Definition: UnaryNumberProvider.h:351
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:362
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:354
Definition: UnaryNumberProvider.h:234
static constexpr auto name
Definition: UnaryNumberProvider.h:235
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:238
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:246
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:236
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:242
Definition: UnaryNumberProvider.h:212
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:214
static constexpr auto name
Definition: UnaryNumberProvider.h:213
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:224
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:216
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:220
Definition: UnaryNumberProvider.h:256
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:268
static constexpr auto name
Definition: UnaryNumberProvider.h:257
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:258
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:264
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:260
Definition: UnaryNumberProvider.h:121
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:125
static constexpr auto name
Definition: UnaryNumberProvider.h:122
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:133
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:123
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:129
Definition: UnaryNumberProvider.h:372
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:384
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:380
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:376
static constexpr auto name
Definition: UnaryNumberProvider.h:373
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:374
Definition: UnaryNumberProvider.h:165
static constexpr auto name
Definition: UnaryNumberProvider.h:166
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:167
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:169
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:179
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:174
Definition: UnaryNumberProvider.h:394
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:396
static constexpr auto name
Definition: UnaryNumberProvider.h:395
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:402
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:406
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:398
Definition: UnaryNumberProvider.h:143
static constexpr joda::query::IValueType retType
Definition: UnaryNumberProvider.h:145
static RJValue calculate(int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:155
static RJValue calculate(double val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:147
static constexpr auto name
Definition: UnaryNumberProvider.h:144
static RJValue calculate(u_int64_t val, RJMemoryPoolAlloc &alloc)
Definition: UnaryNumberProvider.h:151