AWS SDK for C++  0.12.9
AWS SDK for C++
JsonSerializer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <aws/core/Core_EXPORTS.h>
19 
20 #include <aws/core/utils/Array.h>
24 
25 #include <utility>
26 
27 namespace Aws
28 {
29  namespace Utils
30  {
31  namespace Json
32  {
37  {
38  public:
42  JsonValue();
43 
48  JsonValue(const Aws::String& value);
49 
53  JsonValue(Aws::IStream& istream);
54 
58  JsonValue(const JsonValue& value);
59 
63  JsonValue(JsonValue&& value);
64 
65  JsonValue& operator=(const JsonValue& other);
66 
67  JsonValue& operator=(JsonValue&& other);
68 
69  bool operator!=(const JsonValue& other)
70  {
71  return m_value != other.m_value;
72  }
73 
74  bool operator==(const JsonValue& other)
75  {
76  return m_value == other.m_value;
77  }
78 
82  Aws::String GetString(const Aws::String& key) const;
83  Aws::String GetString(const char* key) const;
84 
88  JsonValue& WithString(const Aws::String& key, const Aws::String& value);
89  JsonValue& WithString(const char* key, const Aws::String& value);
90 
94  JsonValue& AsString(const Aws::String& value);
95 
99  Aws::String AsString() const;
100 
104  bool GetBool(const Aws::String& key) const;
105  bool GetBool(const char* key) const;
106 
110  JsonValue& WithBool(const Aws::String& key, bool value);
111  JsonValue& WithBool(const char* key, bool value);
112 
116  JsonValue& AsBool(bool value);
117 
121  bool AsBool() const;
122 
126  int GetInteger(const Aws::String& key) const;
127  int GetInteger(const char* key) const;
128 
132  JsonValue& WithInteger(const Aws::String& key, int value);
133  JsonValue& WithInteger(const char* key, int value);
134 
138  JsonValue& AsInteger(int value);
139 
143  int AsInteger() const;
144 
148  long long GetInt64(const Aws::String& key) const;
149  long long GetInt64(const char* key) const;
150 
154  JsonValue& WithInt64(const Aws::String& key, long long value);
155  JsonValue& WithInt64(const char* key, long long value);
156 
160  JsonValue& AsInt64(long long value);
161 
165  long long AsInt64() const;
166 
170  double GetDouble(const Aws::String& key) const;
171  double GetDouble(const char* key) const;
172 
176  JsonValue& WithDouble(const Aws::String& key, double value);
177  JsonValue& WithDouble(const char* key, double value);
178 
182  JsonValue& AsDouble(double value);
183 
187  double AsDouble() const;
188 
192  Array<JsonValue> GetArray(const Aws::String& key) const;
193  Array<JsonValue> GetArray(const char* key) const;
194 
198  JsonValue& WithArray(const Aws::String& key, const Array<Aws::String>& array);
199  JsonValue& WithArray(const char* key, const Array<Aws::String>& array);
200 
206  JsonValue& WithArray(const Aws::String& key, Array<Aws::String>&& array);
207 
211  JsonValue& WithArray(const Aws::String& key, const Array<JsonValue>& array);
212 
218  JsonValue& WithArray(const Aws::String& key, Array<JsonValue>&& array);
219 
223  JsonValue& AsArray(const Array<JsonValue>& array);
224 
228  JsonValue& AsArray(Array<JsonValue>&& array);
229 
233  Array<JsonValue> AsArray() const;
234 
238  JsonValue GetObject(const char* key) const;
239  JsonValue GetObject(const Aws::String& key) const;
240 
244  JsonValue& WithObject(const Aws::String& key, const JsonValue& value);
245  JsonValue& WithObject(const char* key, const JsonValue& value);
246 
250  JsonValue& WithObject(const Aws::String& key, const JsonValue&& value);
251  JsonValue& WithObject(const char* key, const JsonValue&& value);
252 
256  JsonValue& AsObject(const JsonValue& value);
257 
261  JsonValue& AsObject(JsonValue&& value);
262 
266  JsonValue AsObject() const;
267 
272  Aws::Map<Aws::String, JsonValue> GetAllObjects() const;
273 
279  bool ValueExists(const char* key) const;
280  bool ValueExists(const Aws::String& key) const;
281 
286  Aws::String WriteCompact(bool treatAsObject = true) const;
287 
291  void WriteCompact(Aws::OStream& ostream, bool treatAsObject = true) const;
292 
297  Aws::String WriteReadable(bool treatAsObject = true) const;
298 
302  void WriteReadable(Aws::OStream& ostream, bool treatAsObject = true) const;
303 
308  inline bool WasParseSuccessful() const
309  {
310  return m_wasParseSuccessful;
311  }
312 
316  inline const Aws::String& GetErrorMessage() const
317  {
318  return m_errorMessage;
319  }
323  void AppendValue(const JsonValue& value);
324 
325  bool IsObject() const;
326  bool IsBool() const;
327  bool IsString() const;
328  bool IsIntegerType() const;
329  bool IsFloatingPointType() const;
330  bool IsListType() const;
331 
333 
334  private:
336 
337  JsonValue& operator=(Aws::External::Json::Value& other);
338 
339  mutable Aws::External::Json::Value m_value;
340  bool m_wasParseSuccessful;
341  Aws::String m_errorMessage;
342  };
343 
344  } // namespace Json
345  } // namespace Utils
346 } // namespace Aws
347 
Represents a JSON value.
Definition: json.h:511
const Aws::String & GetErrorMessage() const
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:28
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:30
bool operator==(const JsonValue &other)
bool operator!=(const JsonValue &other)
std::basic_ostream< char, std::char_traits< char > > OStream
Definition: AWSStreamFwd.h:31
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::External::Json::Value & ModifyRawValue()
#define AWS_CORE_API
Definition: Core_EXPORTS.h:30
JSON (JavaScript Object Notation).