MCPcopy Create free account
hub / github.com/Tencent/rapidjson / FilterKeyHandler

Class FilterKeyHandler

example/filterkeydom/filterkeydom.cpp:19–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17// This handler forwards event into an output handler, with filtering the descendent events of specified key.
18template <typename OutputHandler>
19class FilterKeyHandler {
20public:
21 typedef char Ch;
22
23 FilterKeyHandler(OutputHandler& outputHandler, const Ch* keyString, SizeType keyLength) :
24 outputHandler_(outputHandler), keyString_(keyString), keyLength_(keyLength), filterValueDepth_(), filteredKeyCount_()
25 {}
26
27 bool Null() { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Null() && EndValue(); }
28 bool Bool(bool b) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Bool(b) && EndValue(); }
29 bool Int(int i) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int(i) && EndValue(); }
30 bool Uint(unsigned u) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint(u) && EndValue(); }
31 bool Int64(int64_t i) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int64(i) && EndValue(); }
32 bool Uint64(uint64_t u) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint64(u) && EndValue(); }
33 bool Double(double d) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Double(d) && EndValue(); }
34 bool RawNumber(const Ch* str, SizeType len, bool copy) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.RawNumber(str, len, copy) && EndValue(); }
35 bool String (const Ch* str, SizeType len, bool copy) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.String (str, len, copy) && EndValue(); }
36
37 bool StartObject() {
38 if (filterValueDepth_ > 0) {
39 filterValueDepth_++;
40 return true;
41 }
42 else {
43 filteredKeyCount_.push(0);
44 return outputHandler_.StartObject();
45 }
46 }
47
48 bool Key(const Ch* str, SizeType len, bool copy) {
49 if (filterValueDepth_ > 0)
50 return true;
51 else if (len == keyLength_ && std::memcmp(str, keyString_, len) == 0) {
52 filterValueDepth_ = 1;
53 return true;
54 }
55 else {
56 ++filteredKeyCount_.top();
57 return outputHandler_.Key(str, len, copy);
58 }
59 }
60
61 bool EndObject(SizeType) {
62 if (filterValueDepth_ > 0) {
63 filterValueDepth_--;
64 return EndValue();
65 }
66 else {
67 // Use our own filtered memberCount
68 SizeType memberCount = filteredKeyCount_.top();
69 filteredKeyCount_.pop();
70 return outputHandler_.EndObject(memberCount) && EndValue();
71 }
72 }
73
74 bool StartArray() {
75 if (filterValueDepth_ > 0) {
76 filterValueDepth_++;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected