9 #ifndef INCLUDE_FUNAPI_COMMON_JSON_H_ 10 #define INCLUDE_FUNAPI_COMMON_JSON_H_ 13 #pragma GCC diagnostic ignored "-Wtype-limits" 14 #include <rapidjson/document.h> 15 #pragma GCC diagnostic warning "-Wtype-limits" 20 typedef rapidjson::GenericValue<
21 rapidjson::UTF8<char>, rapidjson::CrtAllocator> JsonValueImpl;
27 class FUNAPI_DLL_VISIBILITY
Json :
private JsonValueImpl {
31 class FUNAPI_DLL_VISIBILITY
Attribute :
private Member {
33 string GetName()
const;
34 const Json &GetValue()
const;
46 typedef boost::function<void(
const string & ,
48 size_t )> ParseErrorCallback;
78 static const ParseErrorCallback kDefaultParseErrorHandler;
82 explicit Json(
bool value);
83 explicit Json(
int value);
84 explicit Json(int64_t value);
85 explicit Json(
double value);
86 explicit Json(
const char *value);
87 explicit Json(
const string &value);
93 void Copy(
Json *to)
const;
98 bool FromString(
const string &json_string,
99 const ParseErrorCallback &cb = NULL);
100 bool FromString(
const string &json_string,
102 const ParseErrorCallback &cb = NULL);
103 bool FromStringInsitu(
string *json_string,
104 const ParseErrorCallback &cb = NULL);
107 bool FromStringWithComments(
const string &json_string,
108 const ParseErrorCallback &cb = NULL));
109 bool FromString(
const char *json_string,
110 const ParseErrorCallback &cb = NULL);
111 bool FromStringInsitu(
char *json_string,
112 const ParseErrorCallback &cb = NULL);
113 bool FromString(
const char *json_string,
115 const ParseErrorCallback &cb = NULL);
116 bool FromStringInsitu(
char *json_string,
118 const ParseErrorCallback &cb = NULL);
119 bool FromFile(
const string &file_path,
120 const ParseErrorCallback &cb = NULL);
121 bool FromFileWithComments(
const string &file_path,
122 const ParseErrorCallback &cb = NULL);
124 bool FromStream(std::istream &input_stream,
125 const ParseErrorCallback &cb = NULL);
129 bool FromStreamWithComments(std::istream &input_stream,
130 const ParseErrorCallback &cb = NULL));
132 bool FromStream(std::istream &input_stream,
134 const ParseErrorCallback &cb = NULL);
136 string ToString(
bool pretty =
false)
const;
137 void ToString(
string *str,
bool pretty =
false)
const;
138 void ToString(Buffer *buffer,
bool pretty =
false)
const;
139 void ToString(std::ostream *stream,
bool pretty =
false)
const;
145 bool IsInteger()
const;
146 bool IsDouble()
const;
147 bool IsString()
const;
148 bool IsArray()
const;
149 bool IsObject()
const;
152 Json &operator=(
bool value);
153 Json &operator=(
int value);
154 Json &operator=(int64_t value);
155 Json &operator=(
double value);
156 Json &operator=(
const char *value);
157 Json &operator=(
const string &value);
165 void SetBool(
bool value);
166 bool GetBool()
const;
169 void SetInteger(int64_t value);
170 int64_t GetInteger()
const;
173 void SetDouble(
double value);
174 double GetDouble()
const;
177 void SetString(
const string &value);
178 string GetString()
const;
183 const Json &operator[](
size_t index)
const;
184 Json &operator[](
size_t index);
187 void PushBack(
bool value);
188 void PushBack(
int value);
189 void PushBack(int64_t value);
190 void PushBack(
double value);
191 void PushBack(
const char *value);
192 void PushBack(
const string &value);
193 void PushBack(
const Json &value);
195 void RemoveElementByIndex(
size_t index);
196 ValueIterator RemoveElement(ValueIterator iterator);
197 void RemoveAllElements();
199 ValueIterator Begin();
201 ConstValueIterator Begin()
const;
202 ConstValueIterator End()
const;
206 const Json &operator[](
const string &attr_name)
const;
207 Json &operator[](
const string &attr_name);
209 bool HasAttribute(
const string &attr_name)
const;
210 bool HasAttribute(
const string &attr_name, Type type)
const;
212 void AddAttribute(
const string &attr_name,
bool value);
213 void AddAttribute(
const string &attr_name,
int value);
214 void AddAttribute(
const string &attr_name, int64_t value);
215 void AddAttribute(
const string &attr_name,
double value);
216 void AddAttribute(
const string &attr_name,
const char *value);
217 void AddAttribute(
const string &attr_name,
const string &value);
218 void AddAttribute(
const string &attr_name,
const Json &value);
220 const Json &GetAttribute(
const string &attr_name)
const;
221 Json &GetAttribute(
const string &attr_name);
223 AttributeIterator FindAttribute(
const string &attr_name);
224 ConstAttributeIterator FindAttribute(
const string &attr_name)
const;
226 bool RemoveAttribute(
const string &attr_name);
227 AttributeIterator RemoveAttribute(AttributeIterator iterator);
228 void RemoveAllAttributes();
230 size_t MemberCount()
const;
231 AttributeIterator AttributeBegin();
232 AttributeIterator AttributeEnd();
233 ConstAttributeIterator AttributeBegin()
const;
234 ConstAttributeIterator AttributeEnd()
const;
238 FUNAPI_DLL_VISIBILITY
bool IsEqual(
const Json &value1,
const Json &value2);
239 FUNAPI_DLL_VISIBILITY
bool operator==(
const Json &lhs,
const Json &rhs);
240 FUNAPI_DLL_VISIBILITY
bool operator!=(
const Json &lhs,
const Json &rhs);
241 FUNAPI_DLL_VISIBILITY
bool operator<(
const Json &lhs,
const Json &rhs);
243 FUNAPI_DLL_VISIBILITY
const string &ToString(Json::Type type);
244 FUNAPI_DLL_VISIBILITY
245 std::ostream &operator<<(std::ostream &out, Json::Type type);
249 #endif // INCLUDE_FUNAPI_COMMON_JSON_H_
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89