JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
TemplateProvider.h
Go to the documentation of this file.
1 #ifndef JODA_TEMPLATEPROVIDER_H
2 #define JODA_TEMPLATEPROVIDER_H
3 
4 #include <joda/misc/RJFwd.h>
5 
6 #include "IValueProvider.h"
7 #include "ParameterPack.h"
8 
9 namespace joda::query {
10 
11 struct TemplateCalc {
12  // Parameters
18 
19  // Return value of the function
20  static constexpr IValueType retType = IV_Null;
21 
22  static constexpr auto name = "PLACEHOLDER";
28  static void checkParameters(
29  const std::vector<std::unique_ptr<IValueProvider>> &parameters){
30 
31  };
32 
34  const std::vector<std::unique_ptr<IValueProvider>> &parameters,
35  const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) {
36  return RJValue();
37  };
38 };
39 
43 template <class Calc>
45  public:
46  explicit TemplateProvider(
47  std::vector<std::unique_ptr<IValueProvider>> &&parameters)
48  : IValueProvider(std::move(parameters)) {
49  Calc::P0::check(params, Calc::name);
50  Calc::P1::check(params, Calc::name);
51  Calc::P2::check(params, Calc::name);
52  Calc::P3::check(params, Calc::name);
53  Calc::P4::check(params, Calc::name);
54  Calc::checkParameters(state, this->params);
55  };
56 
58  return Calc::retType;
59  }
60 
61  std::string getName() const override { return Calc::name; };
62 
63  std::string toString() const override { return IValueProvider::toString(); }
64 
65  std::unique_ptr<IValueProvider> duplicate() const override {
66  return std::make_unique<TemplateProvider<Calc>>(duplicateParameters());
67  };
68 
69  bool isConst() const override {
70  bool c = true;
71  for (const auto &param : params) {
72  c &= param->isConst();
73  }
74  return c;
75  }
76 
78  RJMemoryPoolAlloc &alloc) const override {
79  try {
80  return Calc::calculate(state, params, json, alloc);
81  }catch(const values::IncompatibleTypeException& e){
82  return RJValue();
83  }
84  };
85 
86  const RJValue *getValue(const RapidJsonDocument &json,
87  RJMemoryPoolAlloc &alloc) const override {
88  DCHECK(!isAtom()) << "Did not check for atom first";
89  return nullptr;
90  };
91 
92  bool isAtom() const override { return true; };
93 
95 
96  protected:
97  typename Calc::State state;
98 };
99 
100 } // namespace joda::query
101 
102 #endif // JODA_TEMPLATEPROVIDER_H
#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: IValueProvider.h:143
std::vector< std::unique_ptr< IValueProvider > > params
Definition: IValueProvider.h:373
std::vector< std::unique_ptr< IValueProvider > > duplicateParameters() const
Definition: IValueProvider.cpp:104
virtual std::string toString() const
Definition: IValueProvider.cpp:99
Definition: TemplateProvider.h:44
Calc::State state
Definition: TemplateProvider.h:92
std::unique_ptr< IValueProvider > duplicate() const override
Definition: TemplateProvider.h:65
TemplateProvider(std::vector< std::unique_ptr< IValueProvider >> &&parameters)
Definition: TemplateProvider.h:46
std::string getName() const override
Definition: TemplateProvider.h:61
std::string toString() const override
Definition: TemplateProvider.h:63
joda::query::IValueType getReturnType() const override
Definition: TemplateProvider.h:57
const RJValue * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: TemplateProvider.h:86
bool isAtom() const override
Definition: TemplateProvider.h:92
RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: TemplateProvider.h:77
bool isConst() const override
Definition: TemplateProvider.h:69
Definition: AttributeStatAggregator.h:12
IValueType
Definition: IValueProvider.h:33
@ IV_Null
Definition: IValueProvider.h:40
Definition: TemplateProvider.h:11
values::NoParameter< 4 > P4
Definition: TemplateProvider.h:17
static void checkParameters(const std::vector< std::unique_ptr< IValueProvider >> &parameters)
Definition: TemplateProvider.h:28
values::NoParameter< 2 > P2
Definition: TemplateProvider.h:15
values::NoParameter< 0 > P0
Definition: TemplateProvider.h:13
values::NoParameter< 1 > P1
Definition: TemplateProvider.h:14
values::NoParameter< 3 > P3
Definition: TemplateProvider.h:16
static constexpr IValueType retType
Definition: TemplateProvider.h:20
static RJValue calculate(const std::vector< std::unique_ptr< IValueProvider >> &parameters, const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc)
Definition: TemplateProvider.h:33
static constexpr auto name
Definition: TemplateProvider.h:22
Definition: ParameterPack.h:18