cesium-native 0.44.2
Loading...
Searching...
No Matches
ObjectJsonHandler.h
1#pragma once
2
3#include <CesiumJsonReader/JsonHandler.h>
4#include <CesiumJsonReader/Library.h>
5#include <CesiumUtility/IntrusivePointer.h>
6
7#include <optional>
8
9namespace CesiumJsonReader {
13class CESIUMJSONREADER_API ObjectJsonHandler : public JsonHandler {
14public:
15 ObjectJsonHandler() noexcept : JsonHandler() {}
16
18 virtual IJsonHandler* readObjectStart() override /* final */;
20 virtual IJsonHandler* readObjectEnd() override /* final */;
21
22protected:
27 virtual IJsonHandler* StartSubObject() noexcept;
32 virtual IJsonHandler* EndSubObject() noexcept;
33
45 template <typename TAccessor, typename TProperty>
47 property(const char* currentKey, TAccessor& accessor, TProperty& value) {
48 this->_currentKey = currentKey;
49
50 if constexpr (isOptional<TProperty>::value) {
51 value.emplace();
52 accessor.reset(this, &value.value());
53 } else if constexpr (isIntrusivePointer<TProperty>::value) {
54 value.emplace();
55 accessor.reset(this, value.get());
56 } else {
57 accessor.reset(this, &value);
58 }
59
60 return &accessor;
61 }
62
66 const char* getCurrentKey() const noexcept;
67
69 virtual void reportWarning(
70 const std::string& warning,
71 std::vector<std::string>&& context = std::vector<std::string>()) override;
72
73protected:
77 void setCurrentKey(const char* key) noexcept;
78
79private:
80 template <typename T> struct isOptional {
81 static constexpr bool value = false;
82 };
83
84 template <typename T> struct isOptional<std::optional<T>> {
85 static constexpr bool value = true;
86 };
87
88 template <typename T> struct isIntrusivePointer {
89 static constexpr bool value = false;
90 };
91
92 template <typename T>
93 struct isIntrusivePointer<CesiumUtility::IntrusivePointer<T>> {
94 static constexpr bool value = true;
95 };
96
97 int32_t _depth = 0;
98 const char* _currentKey = nullptr;
99};
100} // 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.