JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
PointerProvider.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 11/13/17.
3 //
4 
5 #ifndef JODA_POINTERPROVIDER_H
6 #define JODA_POINTERPROVIDER_H
7 
8 #include <rapidjson/fwd.h>
9 #include <rapidjson/pointer.h>
10 #include <variant>
11 #include "IValueProvider.h"
12 
13 namespace joda::query {
18  public:
19  PointerProvider(const std::string &str);
20 
21  bool comparable() const override;
22  bool equalizable() const override;
23  std::unique_ptr<IValueProvider> duplicate() const override;
24  std::string toString() const override;
25  std::string getAttributeString() const;
26  bool isConst() const override;
28  RJMemoryPoolAlloc &alloc) const override;
29  const RJValue *getValue(const RapidJsonDocument &json,
30  RJMemoryPoolAlloc &alloc) const override;
31  void getAttributes(std::vector<std::string> &vec) const override;
32  std::vector<std::string> getAttributes() const override;
33  bool isString() const override;
34  bool isNumber() const override;
35  bool isBool() const override;
36  bool isObject() const override;
37  bool isArray() const override;
38  bool isAny() const override;
39  std::string getName() const override;
40  IValueType getReturnType() const override;
41 
48  std::variant<const RJValue, std::optional<const RJValue *>,
49  const VirtualObject *>
51  RJMemoryPoolAlloc &alloc) const;
52 
53  protected:
55  std::string ptrStr;
56 
57  public:
58  template <class Handler>
59  bool Accept(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc,
60  Handler &h) const {
61  if (json.isView()) {
62  auto &v = json.getView();
63  DCHECK(v != nullptr);
64  if (ptrStr.empty()) {
65  return v->Accept(h);
66  } else {
67  v->setPrefix(ptrStr);
68  auto res = v->Accept(h);
69  v->setPrefix("");
70  return res;
71  }
72  } else {
73  auto ptr = json.Get(pointer);
74  if (ptr != nullptr) {
75  return ptr->Accept(h);
76  } else
77  h.Null();
78  return true;
79  }
80  }
81 
82  bool objIsPointerEvaluatable(const RapidJsonDocument &json) const;
83  const VirtualObject *getVO(const RapidJsonDocument &json) const;
84 };
85 } // namespace joda::query
86 
87 #endif // JODA_POINTERPROVIDER_H
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericPointer< RJValue, RJBaseAlloc > RJPointer
Definition: RJFwd.h:30
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
RJValue const * Get(const RJPointer &ptr) const
Definition: RapidJsonDocument.cpp:56
const std::unique_ptr< ViewLayer > & getView() const
Definition: RapidJsonDocument.cpp:65
bool isView() const
Definition: RapidJsonDocument.cpp:49
Definition: VirtualObject.h:13
Definition: IValueProvider.h:143
Definition: PointerProvider.h:17
const RJValue * getValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: PointerProvider.cpp:31
bool isBool() const override
Definition: PointerProvider.cpp:38
std::string ptrStr
Definition: PointerProvider.h:55
std::vector< std::string > getAttributes() const override
Definition: PointerProvider.cpp:54
bool isObject() const override
Definition: PointerProvider.cpp:39
RJValue getAtomValue(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const override
Definition: PointerProvider.cpp:26
bool objIsPointerEvaluatable(const RapidJsonDocument &json) const
Definition: PointerProvider.cpp:60
bool equalizable() const override
Definition: PointerProvider.cpp:9
bool isConst() const override
Definition: PointerProvider.cpp:25
std::unique_ptr< IValueProvider > duplicate() const override
Definition: PointerProvider.cpp:15
bool isAny() const override
Definition: PointerProvider.cpp:41
const VirtualObject * getVO(const RapidJsonDocument &json) const
Definition: PointerProvider.cpp:65
bool isArray() const override
Definition: PointerProvider.cpp:40
std::string toString() const override
Definition: PointerProvider.cpp:18
bool isString() const override
Definition: PointerProvider.cpp:36
bool Accept(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc, Handler &h) const
Definition: PointerProvider.h:59
std::string getAttributeString() const
Definition: PointerProvider.cpp:22
bool comparable() const override
Definition: PointerProvider.cpp:8
IValueType getReturnType() const override
Definition: PointerProvider.cpp:45
PointerProvider(const std::string &str)
Definition: PointerProvider.cpp:11
std::variant< const RJValue, std::optional< const RJValue * >, const VirtualObject * > getPointerIfExists(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) const
Definition: PointerProvider.cpp:75
bool isNumber() const override
Definition: PointerProvider.cpp:37
std::string getName() const override
Definition: PointerProvider.cpp:43
RJPointer pointer
Definition: PointerProvider.h:54
Definition: AttributeStatAggregator.h:12
IValueType
Definition: IValueProvider.h:33