|
| | ImmutableMap () |
| | Default constructor.
|
| |
| | ImmutableMap (const ImmutableMap ©) |
| | Copy constructor.
|
| |
| | ImmutableMap (ImmutableMap &&move) |
| | Move constructor.
|
| |
| virtual | ~ImmutableMap () |
| | Destructor.
|
| |
| std::unique_ptr< Core::Base > | clone () const override |
| |
| virtual const Infinity::Types::TypeID & | typeId () const override |
| | Gets the TypeID for ImmutableMap.
|
| |
| ImmutableMap & | operator= (const ImmutableMap ©) |
| | Copy assignment operator.
|
| |
| ImmutableMap & | operator= (ImmutableMap &&move) |
| | Move assignment operator.
|
| |
| bool | hasKey (const std::string &key) const |
| | Checks if a key exists in the map.
|
| |
| 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, std::shared_ptr< const Core::Data > data) |
| | Sets a key-value pair from a type-erased Data pointer.
|
| |
| template<typename T > |
| void | set (const std::string &key, const T &data) |
| | Sets a key-value pair with automatic type wrapping (copy).
|
| |
| template<typename T > |
| void | set (const std::string &key, T &&data) |
| | Sets a key-value pair with automatic type wrapping (move).
|
| |
| const Core::Data * | get (const std::string &key) const |
| | Gets a type-erased pointer to the value at the specified key.
|
| |
| template<typename T > |
| const T & | get (const std::string &key) const |
| | Gets a typed reference to the value at the specified key.
|
| |
| template<typename T > |
| const T & | getValue (const std::string &key) const |
| | Gets the underlying value from a Value<T> wrapper.
|
| |
| void | clear () |
| | Removes all key-value pairs from the map.
|
| |
| size_t | size () const noexcept |
| | Gets the number of key-value pairs in the map.
|
| |
| | Data () |
| |
| | Data (const Data &other) |
| |
| | Data (Data &&other) |
| |
| Data & | operator= (const Data &other) |
| |
| Data & | operator= (Data &&other) |
| |
| virtual | ~Data () |
| | Virtual destructor.
|
| |
| bool | hasProperty (const std::string &key) const |
| |
| template<typename T > |
| void | setProperty (const std::string &key, T &&value) |
| | Sets a typed property value.
|
| |
| template<typename T > |
| void | setProperty (const std::string &key, const T &value) |
| | Sets a typed property value.
|
| |
| void | setProperty (const std::string &key, PropertyValue &&value) |
| | Sets a typed property value.
|
| |
| const PropertyValue & | getProperty (const std::string &key) const |
| | Gets a property value without type checking.
|
| |
| template<typename T > |
| const T & | getProperty (const std::string &key) const |
| | Gets a typed property value.
|
| |
| void | removeProperty (const std::string &key) |
| |
| virtual | ~Base () |
| | Virtual destructor.
|
| |
| virtual std::istream & | legibleDataRead (std::istream &in) override |
| | Deserializes the object from a single-line text representation.
|
| |
| virtual std::ostream & | legibleDataWrite (std::ostream &out) const override |
| | Serializes the object to a single-line text representation.
|
| |
Type-safe heterogeneous key-value container for configuration and metadata.
ImmutableMap provides a dictionary-like container that stores string-keyed values of heterogeneous types within the Infinity type system. Despite its name, the map is mutable but stores immutable shared pointers to const Data, promoting safe sharing and preventing accidental modification of stored values.
The map automatically handles type wrapping, storing POD types as Value<T> and Data-derived types directly. This makes it ideal for:
- Component configuration parameters
- Metadata and property bags
- Named outputs from procedural systems
- Serializable settings and preferences
- Type-safe data exchange between components
Key features:
- Heterogeneous storage: different value types in the same map
- Type-safe retrieval with automatic unwrapping
- Automatic Value<T> wrapping for POD types
- Full serialization support (read/write/wrap)
- Integration with ProceduralSystem input/output ports
- Move semantics for efficient large object storage
The "immutable" aspect refers to the const-correctness of stored data: values are stored as shared_ptr<const Data>, preventing modification after insertion while allowing safe sharing across the system.
- Note
- Keys are case-sensitive strings.
-
Attempting to retrieve a non-existent key throws std::out_of_range.
-
Use hasKey() to safely check for key existence before retrieval.
Example usage:
config.
set(
"resolution", 1024);
config.
set(
"scale", 50.0f);
config.
set(
"seed", 12345u);
config.
set(
"name", std::string(
"TerrainGen"));
Vector3 position{100.0f, 0.0f, 100.0f};
config.
set(
"spawn_point", position);
int res = config.
get<
int>(
"resolution");
float scale = config.
get<
float>(
"scale");
const Vector3& spawn = config.
get<Vector3>(
"spawn_point");
if (config.
hasKey(
"optional_param")) {
auto value = config.
get<
float>(
"optional_param");
}
system->setIn("config", std::move(config));
metadata.set("author", std::string("John Doe"));
metadata.set("version", 2);
metadata.set("creation_date", std::string("2025-01-15"));
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 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.
ImmutableMap()
Default constructor.