cesium-native 0.50.0
Loading...
Searching...
No Matches
JsonHelpers.h
1#pragma once
2
3#include <CesiumUtility/JsonValue.h>
4
5#include <glm/fwd.hpp>
6#include <rapidjson/fwd.h>
7
8#include <optional>
9#include <string>
10#include <vector>
11
12namespace CesiumUtility {
13
17class JsonHelpers final {
18public:
26 static std::optional<double>
27 getScalarProperty(const rapidjson::Value& tileJson, const std::string& key);
36 static std::optional<glm::dmat4x4> getTransformProperty(
37 const rapidjson::Value& tileJson,
38 const std::string& key);
39
55 static std::optional<std::vector<double>> getDoubles(
56 const rapidjson::Value& json,
57 int32_t expectedSize,
58 const std::string& key);
59
73 static std::optional<std::vector<double>>
74 getDoubles(const rapidjson::Value& json, int32_t expectedSize);
75
85 static std::string getStringOrDefault(
86 const rapidjson::Value& json,
87 const std::string& key,
88 const std::string& defaultValue);
97 static std::string getStringOrDefault(
98 const rapidjson::Value& json,
99 const std::string& defaultValue);
100
110 static double getDoubleOrDefault(
111 const rapidjson::Value& json,
112 const std::string& key,
113 double defaultValue);
122 static double
123 getDoubleOrDefault(const rapidjson::Value& json, double defaultValue);
124
134 static uint32_t getUint32OrDefault(
135 const rapidjson::Value& json,
136 const std::string& key,
137 uint32_t defaultValue);
146 static uint32_t
147 getUint32OrDefault(const rapidjson::Value& json, uint32_t defaultValue);
148
158 static int32_t getInt32OrDefault(
159 const rapidjson::Value& json,
160 const std::string& key,
161 int32_t defaultValue);
170 static int32_t
171 getInt32OrDefault(const rapidjson::Value& json, int32_t defaultValue);
172
182 static uint64_t getUint64OrDefault(
183 const rapidjson::Value& json,
184 const std::string& key,
185 uint64_t defaultValue);
194 static uint64_t
195 getUint64OrDefault(const rapidjson::Value& json, uint64_t defaultValue);
196
206 static int64_t getInt64OrDefault(
207 const rapidjson::Value& json,
208 const std::string& key,
209 int64_t defaultValue);
218 static int64_t
219 getInt64OrDefault(const rapidjson::Value& json, int64_t defaultValue);
220
230 static bool getBoolOrDefault(
231 const rapidjson::Value& json,
232 const std::string& key,
233 bool defaultValue);
242 static bool getBoolOrDefault(const rapidjson::Value& json, bool defaultValue);
243
251 static std::vector<std::string>
252 getStrings(const rapidjson::Value& json, const std::string& key);
253
261 static std::vector<int64_t>
262 getInt64s(const rapidjson::Value& json, const std::string& key);
263
269 static JsonValue toJsonValue(const rapidjson::Value& json);
270};
271
272} // namespace CesiumUtility
A collection of helper functions to make reading JSON simpler.
Definition JsonHelpers.h:17
static int32_t getInt32OrDefault(const rapidjson::Value &json, const std::string &key, int32_t defaultValue)
Attempts to obtain a int32_t from the given key on the JSON object, returning a default value if this...
static std::string getStringOrDefault(const rapidjson::Value &json, const std::string &key, const std::string &defaultValue)
Attempts to obtain a string from the given key on the JSON object, returning a default value if this ...
static std::optional< double > getScalarProperty(const rapidjson::Value &tileJson, const std::string &key)
Attempts to read the value at key of tileJson as a double, returning std::nullopt if it wasn't found ...
static bool getBoolOrDefault(const rapidjson::Value &json, bool defaultValue)
Attempts to read json as a bool, returning a default value if this isn't possible.
static uint32_t getUint32OrDefault(const rapidjson::Value &json, uint32_t defaultValue)
Attempts to read json as a uint32_t, returning a default value if this isn't possible.
static std::optional< glm::dmat4x4 > getTransformProperty(const rapidjson::Value &tileJson, const std::string &key)
Attempts to read the value at key of tileJson as a glm::dmat4x4, returning std::nullopt if it wasn't ...
static std::string getStringOrDefault(const rapidjson::Value &json, const std::string &defaultValue)
Attempts to read json as a string, returning a default value if this isn't possible.
static int32_t getInt32OrDefault(const rapidjson::Value &json, int32_t defaultValue)
Attempts to read json as a int32_t, returning a default value if this isn't possible.
static uint32_t getUint32OrDefault(const rapidjson::Value &json, const std::string &key, uint32_t defaultValue)
Attempts to obtain a uint32_t from the given key on the JSON object, returning a default value if thi...
static int64_t getInt64OrDefault(const rapidjson::Value &json, const std::string &key, int64_t defaultValue)
Attempts to obtain a int64_t from the given key on the JSON object, returning a default value if this...
static std::vector< int64_t > getInt64s(const rapidjson::Value &json, const std::string &key)
Attempts to read an int64_t array from the property key of json, returning an empty vector if this is...
static bool getBoolOrDefault(const rapidjson::Value &json, const std::string &key, bool defaultValue)
Attempts to obtain a bool from the given key on the JSON object, returning a default value if this is...
static int64_t getInt64OrDefault(const rapidjson::Value &json, int64_t defaultValue)
Attempts to read json as a int64_t, returning a default value if this isn't possible.
static double getDoubleOrDefault(const rapidjson::Value &json, double defaultValue)
Attempts to read json as a double, returning a default value if this isn't possible.
static std::optional< std::vector< double > > getDoubles(const rapidjson::Value &json, int32_t expectedSize)
Obtains an array of numbers from the given JSON.
static std::optional< std::vector< double > > getDoubles(const rapidjson::Value &json, int32_t expectedSize, const std::string &key)
Obtains an array of numbers from the property that corresponds to the given key in the JSON.
static std::vector< std::string > getStrings(const rapidjson::Value &json, const std::string &key)
Attempts to read an array of strings from the property key of json, returning an empty vector if this...
static uint64_t getUint64OrDefault(const rapidjson::Value &json, const std::string &key, uint64_t defaultValue)
Attempts to obtain a uint64_t from the given key on the JSON object, returning a default value if thi...
static JsonValue toJsonValue(const rapidjson::Value &json)
Converts a rapidjson::Value to a CesiumUtility::JsonValue type.
static uint64_t getUint64OrDefault(const rapidjson::Value &json, uint64_t defaultValue)
Attempts to read json as a uint64_t, returning a default value if this isn't possible.
static double getDoubleOrDefault(const rapidjson::Value &json, const std::string &key, double defaultValue)
Attempts to obtain a double from the given key on the JSON object, returning a default value if this ...
A generic implementation of a value in a JSON structure.
Definition JsonValue.h:53
Utility classes for Cesium.