5 #ifndef JODA_DOCUMENTCOSTHANDLER_H
6 #define JODA_DOCUMENTCOSTHANDLER_H
9 #include <rapidjson/encodings.h>
10 #include <rapidjson/rapidjson.h>
15 typedef rapidjson::UTF8<>::Ch Ch;
23 theoreticalCost +=
sizeof(
RJValue);
28 theoreticalCost +=
sizeof(
RJValue);
33 theoreticalCost +=
sizeof(
RJValue);
37 bool Uint(
unsigned int i) {
38 theoreticalCost +=
sizeof(
RJValue);
43 theoreticalCost +=
sizeof(
RJValue);
48 theoreticalCost +=
sizeof(
RJValue);
53 theoreticalCost +=
sizeof(
RJValue);
57 bool RawNumber(
const Ch *str, rapidjson::SizeType len,
bool copy) {
58 return String(str, len, copy);
61 bool String(
const Ch *ch, rapidjson::SizeType len,
bool copy) {
62 theoreticalCost +=
sizeof(
RJValue);
63 if (copy && !canBeShortString(len))
64 theoreticalCost +=
sizeof(RJValue::Ch) * len;
70 bool Key(
const Ch *str, rapidjson::SizeType len,
bool copy) {
71 return String(str, len, copy);
75 theoreticalCost +=
sizeof(
RJValue);
83 theoreticalCost +=
sizeof(
RJValue);
94 switch (doc.GetType()) {
95 case rapidjson::kObjectType: {
96 cost +=
sizeof(RJValue::Member) *
97 (doc.MemberCapacity() - doc.MemberCount());
98 for (
const auto &item : doc.GetObject()) {
103 case rapidjson::kArrayType: {
104 cost +=
sizeof(
RJValue) * (doc.Capacity() - doc.Size());
105 for (
const auto &item : doc.GetArray()) {
109 case rapidjson::kStringType: {
111 auto len = doc.GetStringLength();
112 if (!isShortString(doc)) {
113 cost +=
sizeof(RJValue::Ch) * len;
122 cost +=
sizeof(std::vector<std::string>) + paths.size();
123 theoreticalCost +=
sizeof(std::vector<std::string>) + paths.size();
124 for (
const auto &path : paths) {
125 cost += path.size() *
sizeof(char);
126 theoreticalCost += path.size() *
sizeof(char);
136 size_t theoreticalCost = 0;
140 bool canBeShortString(
size_t len)
const {
141 if (RAPIDJSON_64BIT == 0 || RAPIDJSON_48BITPOINTER_OPTIMIZATION == 1)
146 bool isShortString(
const RJValue &doc)
const {
147 return canBeShortString(doc.GetStringLength());
rapidjson::GenericDocument< RJChar, RJMemoryPoolAlloc, RJBaseAlloc > RJDocument
Definition: RJFwd.h:28
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: DocumentCostHandler.h:14
bool StartArray()
Definition: DocumentCostHandler.h:80
bool String(const Ch *ch, rapidjson::SizeType len, bool copy)
Definition: DocumentCostHandler.h:61
void addViewPaths(const std::vector< std::string > &paths)
Definition: DocumentCostHandler.h:121
void checkValue(const RJValue &doc)
Definition: DocumentCostHandler.h:93
bool Uint(unsigned int i)
Definition: DocumentCostHandler.h:37
bool Int(int i)
Definition: DocumentCostHandler.h:32
bool Null()
Definition: DocumentCostHandler.h:22
bool EndArray(rapidjson::SizeType len)
Definition: DocumentCostHandler.h:82
size_t getTheoreticalCost() const
Definition: DocumentCostHandler.h:132
bool Int64(int64_t int64)
Definition: DocumentCostHandler.h:42
size_t getCost() const
Definition: DocumentCostHandler.h:130
bool Uint64(uint64_t uint64)
Definition: DocumentCostHandler.h:47
DocumentCostHandler()
Definition: DocumentCostHandler.h:18
bool Default()
Definition: DocumentCostHandler.h:20
void checkDocument(const RJDocument &doc)
Definition: DocumentCostHandler.h:87
bool Double(double d)
Definition: DocumentCostHandler.h:52
bool StartObject()
Definition: DocumentCostHandler.h:68
bool EndObject(rapidjson::SizeType len)
Definition: DocumentCostHandler.h:74
bool RawNumber(const Ch *str, rapidjson::SizeType len, bool copy)
Definition: DocumentCostHandler.h:57
bool Bool(bool b)
Definition: DocumentCostHandler.h:27
bool Key(const Ch *str, rapidjson::SizeType len, bool copy)
Definition: DocumentCostHandler.h:70