aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
JsonObject.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/Types.h>
8
9namespace Aws
10{
11 struct cJSON;
12
13 namespace Crt
14 {
15 class JsonView;
21 {
22 public:
26 JsonObject();
27
31 JsonObject(const String &value);
32
37 JsonObject(const JsonObject &value);
38
43 JsonObject(JsonObject &&value) noexcept;
44
46
50 JsonObject &operator=(const JsonObject &other);
51
59 JsonObject &operator=(JsonObject &&other) noexcept;
60
61 bool operator==(const JsonObject &other) const;
62 bool operator!=(const JsonObject &other) const;
63
67 JsonObject &WithString(const String &key, const String &value);
68 JsonObject &WithString(const char *key, const String &value);
69
73 JsonObject &AsString(const String &value);
74
78 JsonObject &WithBool(const String &key, bool value);
79 JsonObject &WithBool(const char *key, bool value);
80
84 JsonObject &AsBool(bool value);
85
89 JsonObject &WithInteger(const String &key, int value);
90 JsonObject &WithInteger(const char *key, int value);
91
95 JsonObject &AsInteger(int value);
96
100 JsonObject &WithInt64(const String &key, int64_t value);
101 JsonObject &WithInt64(const char *key, int64_t value);
102
106 JsonObject &AsInt64(int64_t value);
107
111 JsonObject &WithDouble(const String &key, double value);
112 JsonObject &WithDouble(const char *key, double value);
113
117 JsonObject &AsDouble(double value);
118
122 JsonObject &WithArray(const String &key, const Vector<String> &array);
123 JsonObject &WithArray(const char *key, const Vector<String> &array);
124
129 JsonObject &WithArray(const String &key, const Vector<JsonObject> &array);
130
135 JsonObject &WithArray(const String &key, Vector<JsonObject> &&array);
136
140 JsonObject &AsArray(const Vector<JsonObject> &array);
141
145 JsonObject &AsArray(Vector<JsonObject> &&array);
146
150 JsonObject &AsNull();
151
156 JsonObject &WithObject(const String &key, const JsonObject &value);
157 JsonObject &WithObject(const char *key, const JsonObject &value);
158
162 JsonObject &WithObject(const String &key, JsonObject &&value);
163 JsonObject &WithObject(const char *key, JsonObject &&value);
164
168 JsonObject &AsObject(const JsonObject &value);
169
173 JsonObject &AsObject(JsonObject &&value);
174
179 inline bool WasParseSuccessful() const { return m_wasParseSuccessful; }
180
184 inline const String &GetErrorMessage() const { return m_errorMessage; }
185
189 JsonView View() const;
190
191 private:
192 void Destroy();
193 JsonObject(cJSON *value);
194 cJSON *m_value;
195 bool m_wasParseSuccessful;
196 String m_errorMessage;
197 friend class JsonView;
198 };
199
207 {
208 public:
209 /* constructors */
210 JsonView();
211 JsonView(const JsonObject &val);
212 JsonView &operator=(const JsonObject &val);
213
217 String GetString(const String &key) const;
221 String GetString(const char *key) const;
222
227 String AsString() const;
228
232 bool GetBool(const String &key) const;
236 bool GetBool(const char *key) const;
237
241 bool AsBool() const;
242
247 int GetInteger(const String &key) const;
252 int GetInteger(const char *key) const;
253
257 int AsInteger() const;
258
263 int64_t GetInt64(const String &key) const;
268 int64_t GetInt64(const char *key) const;
269
273 int64_t AsInt64() const;
274
278 double GetDouble(const String &key) const;
282 double GetDouble(const char *key) const;
283
287 double AsDouble() const;
288
292 Vector<JsonView> GetArray(const String &key) const;
296 Vector<JsonView> GetArray(const char *key) const;
297
301 Vector<JsonView> AsArray() const;
302
306 JsonView GetJsonObject(const String &key) const;
310 JsonView GetJsonObject(const char *key) const;
311
312 JsonObject GetJsonObjectCopy(const String &key) const;
313
314 JsonObject GetJsonObjectCopy(const char *key) const;
315
319 JsonView AsObject() const;
320
325 Map<String, JsonView> GetAllObjects() const;
326
331 bool ValueExists(const String &key) const;
336 bool ValueExists(const char *key) const;
337
341 bool KeyExists(const String &key) const;
345 bool KeyExists(const char *key) const;
346
350 bool IsObject() const;
351
355 bool IsBool() const;
356
360 bool IsString() const;
361
366 bool IsIntegerType() const;
367
371 bool IsFloatingPointType() const;
372
376 bool IsListType() const;
377
381 bool IsNull() const;
382
387 String WriteCompact(bool treatAsObject = true) const;
388
393 String WriteReadable(bool treatAsObject = true) const;
394
398 JsonObject Materialize() const;
399
400 private:
401 JsonView(cJSON *val);
402 JsonView &operator=(cJSON *val);
403 cJSON *m_value;
404 };
405 } // namespace Crt
406} // namespace Aws
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Definition: JsonObject.h:21
const String & GetErrorMessage() const
Definition: JsonObject.h:184
bool WasParseSuccessful() const
Definition: JsonObject.h:179
Definition: JsonObject.h:207
std::map< K, V, std::less< K >, StlAllocator< std::pair< const K, V > > > Map
Definition: Types.h:49
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:55
bool operator==(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:665
bool operator!=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:690
Definition: Api.h:14
struct Aws::cJSON cJSON
Definition: cJSON.h:122