cesium-native 0.43.0
Loading...
Searching...
No Matches
ObjectJsonHandler.h
1#pragma once
2
3#include "JsonHandler.h"
4#include "Library.h"
5
6#include <CesiumUtility/IntrusivePointer.h>
7
8#include <optional>
9
10namespace CesiumJsonReader {
14class CESIUMJSONREADER_API ObjectJsonHandler : public JsonHandler {
15public:
16 ObjectJsonHandler() noexcept : JsonHandler() {}
17
19 virtual IJsonHandler* readObjectStart() override /* final */;
21 virtual IJsonHandler* readObjectEnd() override /* final */;
22
23protected:
28 virtual IJsonHandler* StartSubObject() noexcept;
33 virtual IJsonHandler* EndSubObject() noexcept;
34
46 template <typename TAccessor, typename TProperty>
48 property(const char* currentKey, TAccessor& accessor, TProperty& value) {
49 this->_currentKey = currentKey;
50
51 if constexpr (isOptional<TProperty>::value) {
52 value.emplace();
53 accessor.reset(this, &value.value());
54 } else if constexpr (isIntrusivePointer<TProperty>::value) {
55 value.emplace();
56 accessor.reset(this, value.get());
57 } else {
58 accessor.reset(this, &value);
59 }
60
61 return &accessor;
62 }
63
67 const char* getCurrentKey() const noexcept;
68
70 virtual void reportWarning(
71 const std::string& warning,
72 std::vector<std::string>&& context = std::vector<std::string>()) override;
73
74protected:
78 void setCurrentKey(const char* key) noexcept;
79
80private:
81 template <typename T> struct isOptional {
82 static constexpr bool value = false;
83 };
84
85 template <typename T> struct isOptional<std::optional<T>> {
86 static constexpr bool value = true;
87 };
88
89 template <typename T> struct isIntrusivePointer {
90 static constexpr bool value = false;
91 };
92
93 template <typename T>
94 struct isIntrusivePointer<CesiumUtility::IntrusivePointer<T>> {
95 static constexpr bool value = true;
96 };
97
98 int32_t _depth = 0;
99 const char* _currentKey = nullptr;
100};
101} // namespace CesiumJsonReader
Base interface for all JSON handlers. Types that need to be deserialized from JSON should implement I...
A dummy implementation of IJsonHandler that will report a warning and return its parent when any of i...
Definition JsonHandler.h:19
IJsonHandler for handling JSON objects.
virtual IJsonHandler * readObjectStart() override
Called when the JSON parser encounters the beginning of an object.
const char * getCurrentKey() const noexcept
Obtains the most recent key handled by this JsonHandler.
Classes for reading JSON.
Utility classes for Cesium.
STL namespace.