cesium-native 0.43.0
Loading...
Searching...
No Matches
JsonReaderOptions.h
1#pragma once
2
3#include "IExtensionJsonHandler.h"
4#include "Library.h"
5
6#include <functional>
7#include <map>
8#include <memory>
9#include <optional>
10#include <string>
11#include <vector>
12
13namespace CesiumJsonReader {
14
18enum class ExtensionState {
26 Enabled,
27
36
43};
44
48class CESIUMJSONREADER_API JsonReaderOptions {
49public:
57 return this->_captureUnknownProperties;
58 }
59
66 void setCaptureUnknownProperties(bool value) {
67 this->_captureUnknownProperties = value;
68 }
69
78 template <typename TExtended, typename TExtensionHandler>
79 void registerExtension(const std::string& extensionName) {
80 auto it =
81 this->_extensions.emplace(extensionName, ObjectTypeToHandler()).first;
82 it->second.insert_or_assign(
83 TExtended::TypeName,
84 ExtensionReaderFactory([](const JsonReaderOptions& context) {
85 return std::make_unique<TExtensionHandler>(context);
86 }));
87 }
88
98 template <typename TExtended, typename TExtensionHandler>
100 auto it =
101 this->_extensions
102 .emplace(TExtensionHandler::ExtensionName, ObjectTypeToHandler())
103 .first;
104 it->second.insert_or_assign(
105 TExtended::TypeName,
106 ExtensionHandlerFactory([](const JsonReaderOptions& context) {
107 return std::make_unique<TExtensionHandler>(context);
108 }));
109 }
110
118 ExtensionState getExtensionState(const std::string& extensionName) const;
119
138 void
139 setExtensionState(const std::string& extensionName, ExtensionState newState);
140
149 std::unique_ptr<IExtensionJsonHandler> createExtensionHandler(
150 const std::string_view& extensionName,
151 const std::string& extendedObjectType) const;
152
153private:
154 using ExtensionHandlerFactory =
155 std::function<std::unique_ptr<IExtensionJsonHandler>(
156 const JsonReaderOptions&)>;
157 using ObjectTypeToHandler = std::map<std::string, ExtensionHandlerFactory>;
158 using ExtensionNameMap = std::map<std::string, ObjectTypeToHandler>;
159
160 ExtensionNameMap _extensions;
161 std::unordered_map<std::string, ExtensionState> _extensionStates;
162 bool _captureUnknownProperties = true;
163};
164
165} // namespace CesiumJsonReader
Holds options for reading statically-typed data structures from JSON.
std::unique_ptr< IExtensionJsonHandler > createExtensionHandler(const std::string_view &extensionName, const std::string &extendedObjectType) const
Creates an extension handler for the given extension.
void setCaptureUnknownProperties(bool value)
Sets a value indicating whether the values of unknown properties are captured in the CesiumUtility::E...
ExtensionState getExtensionState(const std::string &extensionName) const
Returns whether an extension is enabled or disabled.
void registerExtension(const std::string &extensionName)
Registers an extension for an object.
void setExtensionState(const std::string &extensionName, ExtensionState newState)
Enables or disables an extension.
void registerExtension()
Registers an extension for an object.
bool getCaptureUnknownProperties() const
Gets a value indicating whether the values of unknown properties are captured in the CesiumUtility::E...
Classes for reading JSON.
ExtensionState
The state of an extension.
@ Enabled
The extension is enabled.
@ Disabled
The extension is disabled.
@ JsonOnly
The extension is enabled but will always be deserialized as a CesiumUtility::JsonValue.