cesium-native 0.64.0
Loading...
Searching...
No Matches
JsonReaderOptions.h
1#pragma once
2
3#include <CesiumJsonReader/IExtensionJsonHandler.h>
4#include <CesiumJsonReader/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
44
48class CESIUMJSONREADER_API JsonReaderOptions {
49public:
58 return this->_captureUnknownProperties;
59 }
60
68 void setCaptureUnknownProperties(bool value) {
69 this->_captureUnknownProperties = value;
70 }
71
80 template <typename TExtended, typename TExtensionHandler>
81 void registerExtension(const std::string& extensionName) {
82 auto it =
83 this->_extensions.emplace(extensionName, ObjectTypeToHandler()).first;
84 it->second.insert_or_assign(
85 TExtended::TypeName,
86 ExtensionReaderFactory([](const JsonReaderOptions& context) {
87 return std::make_unique<TExtensionHandler>(context);
88 }));
89 }
90
100 template <typename TExtended, typename TExtensionHandler>
102 auto it =
103 this->_extensions
104 .emplace(TExtensionHandler::ExtensionName, ObjectTypeToHandler())
105 .first;
106 it->second.insert_or_assign(
107 TExtended::TypeName,
108 ExtensionHandlerFactory([](const JsonReaderOptions& context) {
109 return std::make_unique<TExtensionHandler>(context);
110 }));
111 }
112
120 ExtensionState getExtensionState(const std::string& extensionName) const;
121
140 void
141 setExtensionState(const std::string& extensionName, ExtensionState newState);
142
151 std::unique_ptr<IExtensionJsonHandler> createExtensionHandler(
152 const std::string_view& extensionName,
153 const std::string& extendedObjectType) const;
154
155private:
156 using ExtensionHandlerFactory =
157 std::function<std::unique_ptr<IExtensionJsonHandler>(
158 const JsonReaderOptions&)>;
159 using ObjectTypeToHandler = std::map<std::string, ExtensionHandlerFactory>;
160 using ExtensionNameMap = std::map<std::string, ObjectTypeToHandler>;
161
162 ExtensionNameMap _extensions;
163 std::unordered_map<std::string, ExtensionState> _extensionStates;
164 bool _captureUnknownProperties = true;
165};
166
167} // 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.