3#include <Infinity/Types/Core/Data.hpp>
4#include <Infinity/Types/Core/Value.hpp>
5#include <Infinity/Types/Containers/Array.hpp>
7#include <unordered_map>
13 class ImmutableMapSerializer;
123 std::unique_ptr<Core::Base>
clone()
const override;
165 bool hasKey(
const std::string& key)
const;
194 void set(
const std::string& key, std::shared_ptr<const Core::Data> data);
215 void set(
const std::string& key,
const T& data)
217 if constexpr (std::is_base_of_v<Core::Data, T>)
219 _map[key] = std::make_shared<T>(data);
221 _map[key] = std::make_shared<Core::Value<T>>(data);
242 void set(
const std::string& key, T&& data)
244 if constexpr (std::is_base_of_v<Core::Data, T>)
246 _map[key] = std::make_shared<T>(std::move(data));
248 size_t size =
sizeof(uint8_t) +
sizeof(Infinity::Types::getTypeID<T>().hash) +
sizeof(T);
249 _map[key] = std::make_shared<Core::Value<T>>(std::move(data));
291 const T&
get(
const std::string& key)
const
293 if constexpr (std::is_base_of_v<Core::Data, T>)
295 const T& a = *
dynamic_cast<const T*
>(_map.at(key).get());
298 auto val =
dynamic_cast<const Core::Value<T>*
>(_map.at(key).get());
326 return get<const Core::Value<T>>(key).get();
345 std::unordered_map<
std::
string,
std::shared_ptr<const Core::Data>> _map;
347 friend class
Infinity::IO::Data::ImmutableMapSerializer;
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Type-safe heterogeneous key-value container for configuration and metadata.
Definition ImmutableMap.hpp:85
const Core::Data * get(const std::string &key) const
Gets a type-erased pointer to the value at the specified key.
void clear()
Removes all key-value pairs from the map.
void set(const std::string &key, std::shared_ptr< const Core::Data > data)
Sets a key-value pair from a type-erased Data pointer.
bool hasKey(const std::string &key) const
Checks if a key exists in the map.
virtual const Infinity::Types::TypeID & typeId() const override
Gets the TypeID for ImmutableMap.
void set(const std::string &key, const T &data)
Sets a key-value pair with automatic type wrapping (copy).
Definition ImmutableMap.hpp:215
const T & getValue(const std::string &key) const
Gets the underlying value from a Value<T> wrapper.
Definition ImmutableMap.hpp:324
ImmutableMap & operator=(ImmutableMap &&move)
Move assignment operator.
bool hasValueAtKey(const std::string &key) const
Checks if a key exists and contains a plain value (POD type).
void set(const std::string &key, T &&data)
Sets a key-value pair with automatic type wrapping (move).
Definition ImmutableMap.hpp:242
ImmutableMap(const ImmutableMap ©)
Copy constructor.
ImmutableMap()
Default constructor.
virtual ~ImmutableMap()
Destructor.
ImmutableMap & operator=(const ImmutableMap ©)
Copy assignment operator.
ImmutableMap(ImmutableMap &&move)
Move constructor.
const T & get(const std::string &key) const
Gets a typed reference to the value at the specified key.
Definition ImmutableMap.hpp:291
size_t size() const noexcept
Gets the number of key-value pairs in the map.
std::unique_ptr< Core::Base > clone() const override
Base class for complex data types with memory wrapping and property support.
Definition Data.hpp:49
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
T & get()
Gets a mutable reference to the underlying value.
Definition Value.inl:60
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71