cesium-native 0.43.0
Loading...
Searching...
No Matches
JsonHelpers.h
1#pragma once
2
3#include <glm/fwd.hpp>
4#include <rapidjson/fwd.h>
5
6#include <optional>
7#include <string>
8#include <vector>
9
10namespace CesiumUtility {
11
15class JsonHelpers final {
16public:
24 static std::optional<double>
25 getScalarProperty(const rapidjson::Value& tileJson, const std::string& key);
34 static std::optional<glm::dmat4x4> getTransformProperty(
35 const rapidjson::Value& tileJson,
36 const std::string& key);
37
52 static std::optional<std::vector<double>> getDoubles(
53 const rapidjson::Value& json,
54 int32_t expectedSize,
55 const std::string& key);
56
66 static std::string getStringOrDefault(
67 const rapidjson::Value& json,
68 const std::string& key,
69 const std::string& defaultValue);
78 static std::string getStringOrDefault(
79 const rapidjson::Value& json,
80 const std::string& defaultValue);
81
91 static double getDoubleOrDefault(
92 const rapidjson::Value& json,
93 const std::string& key,
94 double defaultValue);
103 static double
104 getDoubleOrDefault(const rapidjson::Value& json, double defaultValue);
105
115 static uint32_t getUint32OrDefault(
116 const rapidjson::Value& json,
117 const std::string& key,
118 uint32_t defaultValue);
127 static uint32_t
128 getUint32OrDefault(const rapidjson::Value& json, uint32_t defaultValue);
129
139 static int32_t getInt32OrDefault(
140 const rapidjson::Value& json,
141 const std::string& key,
142 int32_t defaultValue);
151 static int32_t
152 getInt32OrDefault(const rapidjson::Value& json, int32_t defaultValue);
153
163 static uint64_t getUint64OrDefault(
164 const rapidjson::Value& json,
165 const std::string& key,
166 uint64_t defaultValue);
175 static uint64_t
176 getUint64OrDefault(const rapidjson::Value& json, uint64_t defaultValue);
177
187 static int64_t getInt64OrDefault(
188 const rapidjson::Value& json,
189 const std::string& key,
190 int64_t defaultValue);
199 static int64_t
200 getInt64OrDefault(const rapidjson::Value& json, int64_t defaultValue);
201
211 static bool getBoolOrDefault(
212 const rapidjson::Value& json,
213 const std::string& key,
214 bool defaultValue);
223 static bool getBoolOrDefault(const rapidjson::Value& json, bool defaultValue);
224
232 static std::vector<std::string>
233 getStrings(const rapidjson::Value& json, const std::string& key);
234
242 static std::vector<int64_t>
243 getInt64s(const rapidjson::Value& json, const std::string& key);
244};
245
246} // namespace CesiumUtility
A collection of helper functions to make reading JSON simpler.
Definition JsonHelpers.h:15
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, const std::string &key)
Obtains an array of numbers from the given 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 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 ...
Utility classes for Cesium.