]>
git.proxmox.com Git - ceph.git/blob - ceph/src/s3select/rapidjson/example/archiver/archiver.h
9 \brief Archiver concept
11 Archiver can be a reader or writer for serialization or deserialization respectively.
15 /// \returns true if the archiver is in normal state. false if it has errors.
16 operator bool() const;
19 Archiver& StartObject();
21 /// After calling StartObject(), assign a member with a name
22 Archiver& Member(const char* name);
24 /// After calling StartObject(), check if a member presents
25 bool HasMember(const char* name) const;
28 Archiver& EndObject();
31 /// \param size If Archiver::IsReader is true, the size of array is written.
32 Archiver& StartArray(size_t* size = 0);
37 /// Read/Write primitive types.
38 Archiver& operator&(bool& b);
39 Archiver& operator&(unsigned& u);
40 Archiver& operator&(int& i);
41 Archiver& operator&(double& d);
42 Archiver& operator&(std::string& s);
44 /// Write primitive types.
47 //! Whether it is a reader.
48 static const bool IsReader;
50 //! Whether it is a writer.
51 static const bool IsWriter;
55 /// Represents a JSON reader which implements Archiver concept.
60 \param json A non-const source json string for in-situ parsing.
61 \note in-situ means the source JSON string will be modified after parsing.
63 JsonReader(const char* json
);
70 operator bool() const { return !mError
; }
72 JsonReader
& StartObject();
73 JsonReader
& Member(const char* name
);
74 bool HasMember(const char* name
) const;
75 JsonReader
& EndObject();
77 JsonReader
& StartArray(size_t* size
= 0);
78 JsonReader
& EndArray();
80 JsonReader
& operator&(bool& b
);
81 JsonReader
& operator&(unsigned& u
);
82 JsonReader
& operator&(int& i
);
83 JsonReader
& operator&(double& d
);
84 JsonReader
& operator&(std::string
& s
);
86 JsonReader
& SetNull();
88 static const bool IsReader
= true;
89 static const bool IsWriter
= !IsReader
;
92 JsonReader(const JsonReader
&);
93 JsonReader
& operator=(const JsonReader
&);
98 void* mDocument
; ///< DOM result of parsing.
99 void* mStack
; ///< Stack for iterating the DOM
100 bool mError
; ///< Whether an error has occurred.
111 /// Obtains the serialized JSON string.
112 const char* GetString() const;
116 operator bool() const { return true; }
118 JsonWriter
& StartObject();
119 JsonWriter
& Member(const char* name
);
120 bool HasMember(const char* name
) const;
121 JsonWriter
& EndObject();
123 JsonWriter
& StartArray(size_t* size
= 0);
124 JsonWriter
& EndArray();
126 JsonWriter
& operator&(bool& b
);
127 JsonWriter
& operator&(unsigned& u
);
128 JsonWriter
& operator&(int& i
);
129 JsonWriter
& operator&(double& d
);
130 JsonWriter
& operator&(std::string
& s
);
131 JsonWriter
& SetNull();
133 static const bool IsReader
= false;
134 static const bool IsWriter
= !IsReader
;
137 JsonWriter(const JsonWriter
&);
138 JsonWriter
& operator=(const JsonWriter
&);
141 void* mWriter
; ///< JSON writer.
142 void* mStream
; ///< Stream buffer.
145 #endif // ARCHIVER_H__