JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
UnaryPointerAcceptProvider.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 15/07/2019.
3 //
4 
5 #ifndef JODA_UNARYPOINTERACCEPTPROVIDER_H
6 #define JODA_UNARYPOINTERACCEPTPROVIDER_H
7 
8 #include "IValueProvider.h"
9 #include "PointerProvider.h"
10 #include "ValueAccepter.h"
11 
12 namespace joda::query {
13 /*
14  * Concept Calc:
15  * class Calc {
16  * typedef <Type> RetType
17  * RJValue Accept(json,alloc,ptr);
18  * RJValue getValue(json,alloc,ptr);
19  * RJValue getValue(json,alloc,ptr);
20  * constexpr name = <name>
21  * }
22  */
23 
24 template <class Calc>
26  public:
28  std::vector<std::unique_ptr<IValueProvider>> &&parameters)
29  : IValueProvider(std::move(parameters)) {
30  checkParamSize(1);
31  if (!Calc::acceptAll) checkParamType(0, Calc::inType);
32  DCHECK(isAtom()) << "Only atom ReturnTypes allowed";
33  accepter = ValueAccepter(params.front());
34  }
35 
36  IValueType getReturnType() const override { return Calc::retType; }
37 
38  std::string getName() const override { return Calc::name; };
39 
40  std::string toString() const override { return IValueProvider::toString(); }
41 
42  std::unique_ptr<IValueProvider> duplicate() const override {
43  return std::make_unique<UnaryPointerAcceptProvider<Calc>>(
45  };
46 
47  bool isAtom() const override { return true; }
48 
49  const RJValue *getValue(const RapidJsonDocument &json,
50  RJMemoryPoolAlloc &alloc) const override {
51  DCHECK(!isAtom()) << "Did not check for atom first";
52  return nullptr;
53  };
54 
56  RJMemoryPoolAlloc &alloc) const override {
57  DCHECK(isAtom()) << "Did not check for atom first";
58  if (params.front()->isAtom()) {
59  auto v = params.front()->getAtomValue(json, alloc);
60  return Calc::pointer(&v);
61  }
62  auto ptr = accepter.getPointer(json, alloc);
63  if (ptr != nullptr) return Calc::pointer(ptr);
64  auto vo = accepter.getObjVO(json, alloc);
65  if (vo != nullptr) return Calc::virtualObject(vo);
66  return Calc::accept(json, alloc, accepter);
67  };
68 
69  bool isConst() const override { return params.front()->isConst(); }
70 
71  void getAttributes(std::vector<std::string> &vec) const override {}
72 
74 
75  private:
76  ValueAccepter accepter;
77 };
78 } // namespace joda::query
79 #endif // JODA_UNARYPOINTERACCEPTPROVIDER_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
void checkParamSize(unsigned int expected)
Definition: IValueProvider.cpp:112
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: UnaryPointerAcceptProvider.h:25
bool isAtom() const override
Definition: UnaryPointerAcceptProvider.h:47
std::string getName() const override
Definition: UnaryPointerAcceptProvider.h:38
UnaryPointerAcceptProvider(std::vector< std::unique_ptr< IValueProvider >> &&parameters)
Definition: UnaryPointerAcceptProvider.h:27
IValueType getReturnType() const override
Definition: UnaryPointerAcceptProvider.h:36
RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: UnaryPointerAcceptProvider.h:55
std::string toString() const override
Definition: UnaryPointerAcceptProvider.h:40
std::unique_ptr< IValueProvider > duplicate() const override
Definition: UnaryPointerAcceptProvider.h:42
void getAttributes(std::vector< std::string > &vec) const override
Definition: UnaryPointerAcceptProvider.h:71
const RJValue * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: UnaryPointerAcceptProvider.h:49
bool isConst() const override
Definition: UnaryPointerAcceptProvider.h:69
Definition: ValueAccepter.h:16
const RJValue * getPointer(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const
Definition: ValueAccepter.h:127
const VirtualObject * getObjVO(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const
Definition: ValueAccepter.h:135
Definition: AttributeStatAggregator.h:12
IValueType
Definition: IValueProvider.h:33