scenepic 1.1.0
3D Visualization Made Easy
json_value.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_JSON_VALUE_H_
5#define _SCENEPIC_JSON_VALUE_H_
6
7#include <cstdint>
8#include <iostream>
9#include <map>
10#include <string>
11#include <vector>
12
13namespace scenepic
14{
16 enum class JsonType
17 {
18 Object,
19 Array,
20 String,
21 Integer,
22 Double,
23 Boolean,
24 Null
25 };
26
30 {
31 public:
34
39
43 JsonValue(const std::string& value);
44
48 JsonValue(std::string&& value);
49
53 JsonValue(const char* value);
54
58 JsonValue(double value);
59
63 JsonValue(std::int64_t value);
64
68 JsonValue(bool value);
69
74 void resize(std::size_t size);
75
80 void append(JsonValue&& object);
81
86 void append(const JsonValue& object);
87
92 JsonValue& operator[](const std::string& key);
93
98 const JsonValue& operator[](const std::string& key) const;
99
103 JsonValue& operator=(const std::string& value);
104
108 JsonValue& operator=(std::string&& value);
109
113 JsonValue& operator=(const char* value);
114
118 JsonValue& operator=(double value);
119
123 JsonValue& operator=(std::int64_t value);
124
128 JsonValue& operator=(bool value);
129
131 JsonType type() const;
132
134 std::string to_string() const;
135
137 const std::string& as_string() const;
138
140 double as_double() const;
141
143 float as_float() const;
144
146 std::int64_t as_int() const;
147
149 bool as_boolean() const;
150
152 const std::vector<JsonValue>& values() const;
153
155 const std::map<std::string, JsonValue>& lookup() const;
156
161 static JsonValue parse(std::istream& stream);
162
165
166 private:
167 std::string m_string;
168 double m_double;
169 std::int64_t m_int;
170 bool m_bool;
171 JsonType m_type;
172 std::map<std::string, JsonValue> m_lookup;
173 std::vector<JsonValue> m_values;
174 };
175} // namespace scenepic
176
177#endif
Representation of a JSON value according to the specification at https://www.json....
Definition: json_value.h:30
float as_float() const
Return this object intepreted as a float.
const std::map< std::string, JsonValue > & lookup() const
Return the key/value lookup for this JSON object.
JsonValue(JsonType type)
Constructor.
JsonValue & operator=(double value)
Set the value of this object to the specified value.
const std::vector< JsonValue > & values() const
Return the values of this JSON array.
JsonValue & operator=(const std::string &value)
Set the value of this object to the specified value.
JsonValue(bool value)
Constructor.
JsonValue(double value)
Constructor.
const JsonValue & operator[](const std::string &key) const
Return the value stored in this object at the specified key.
JsonValue()
Constructor.
JsonValue & operator[](const std::string &key)
Return the value stored in this object at the specified key.
JsonValue & operator=(std::int64_t value)
Set the value of this object to the specified value.
JsonValue(const std::string &value)
Constructor.
std::int64_t as_int() const
Return this object intepreted as an integer.
JsonType type() const
The type of this object.
void append(JsonValue &&object)
Append the object to this array.
JsonValue & operator=(const char *value)
Set the value of this object to the specified value.
JsonValue & operator=(std::string &&value)
Set the value of this object to the specified value.
void append(const JsonValue &object)
Append the object to this array.
std::string to_string() const
A string representation of this object in valid JSON.
double as_double() const
Return this object interpreted as a double.
JsonValue & operator=(bool value)
Set the value of this object to the specified value.
static JsonValue parse(std::istream &stream)
Parse a JsonValue object from the provided input stream.
static JsonValue nullSingleton()
Return a singleton representating a JSON NULL object.
JsonValue(std::string &&value)
Constructor.
JsonValue(std::int64_t value)
Constructor.
const std::string & as_string() const
Return this object interpreted as a string.
JsonValue(const char *value)
Constructor.
void resize(std::size_t size)
Convert this objec to an array of the specified size.
bool as_boolean() const
Return this object intepreted as a boolean.
Definition: audio_track.h:14
JsonType
Types of JsonValue objects.
Definition: json_value.h:17