7#include <unordered_map>
23 auto it = this->extensions.find(T::ExtensionName);
24 return it != this->extensions.end();
35 auto it = this->extensions.find(T::ExtensionName);
36 if (it == this->extensions.end()) {
40 return std::any_cast<T>(&it->second);
45 return const_cast<T*
>(std::as_const(*this).getExtension<T>());
73 template <
typename T,
typename... ConstructorArgumentTypes>
74 T&
addExtension(ConstructorArgumentTypes&&... constructorArguments) {
79 std::make_any<T>(std::forward<ConstructorArgumentTypes>(
80 constructorArguments)...))
82 return std::any_cast<T&>(extension);
91 extensions.erase(T::ExtensionName);
132 this->extras.size() * (
sizeof(std::string) +
sizeof(
JsonValue)));
133 for (
const auto& [k, v] : this->extras) {
134 accum += int64_t(k.capacity() *
sizeof(
char) -
sizeof(std::string));
135 accum += v.getSizeBytes() - int64_t(
sizeof(
JsonValue));
139 this->unknownProperties.size() *
140 (
sizeof(std::string) +
sizeof(
JsonValue)));
141 for (
const auto& [k, v] : this->unknownProperties) {
142 accum += int64_t(k.capacity() *
sizeof(
char) -
sizeof(std::string));
143 accum += v.getSizeBytes() - int64_t(
sizeof(
JsonValue));
A generic implementation of a value in a JSON structure.
std::map< std::string, JsonValue > Object
The type to represent an Object JSON value.
Utility classes for Cesium.
The base class for objects that have extensions and extras.
const T * getExtension() const noexcept
Gets an extension given its static type.
JsonValue::Object extras
Application-specific data.
T * getExtension() noexcept
Gets an extension given its static type.
JsonValue::Object unknownProperties
Unknown properties that exist on this object but do not have any representation in the statically-typ...
int64_t getSizeBytes() const
Calculates the size in bytes of this ExtensibleObject, including all of its extras but NOT including ...
const JsonValue * getGenericExtension(const std::string &extensionName) const noexcept
Gets a generic extension with the given name as a CesiumUtility::JsonValue.
T & addExtension(ConstructorArgumentTypes &&... constructorArguments)
Adds a statically-typed extension to this object.
JsonValue * getGenericExtension(const std::string &extensionName) noexcept
Gets a generic extension with the given name as a CesiumUtility::JsonValue.
void removeExtension()
Removes a statically-typed extension from this object.
bool hasExtension() const noexcept
Checks if an extension exists given its static type.
std::unordered_map< std::string, std::any > extensions
The extensions attached to this object.