3131#pragma once
3232
3333#include < godot_cpp/core/type_info.hpp>
34+ #include < godot_cpp/templates/pair.hpp>
3435#include < godot_cpp/variant/dictionary.hpp>
3536#include < godot_cpp/variant/variant.hpp>
3637
@@ -57,54 +58,75 @@ class TypedDictionary : public Dictionary {
5758 _FORCE_INLINE_ TypedDictionary () {
5859 set_typed (Variant::OBJECT, K::get_class_static (), Variant (), Variant::OBJECT, V::get_class_static (), Variant ());
5960 }
61+ _FORCE_INLINE_ TypedDictionary (std::initializer_list<KeyValue<K, V>> p_init) :
62+ Dictionary() {
63+ set_typed (Variant::OBJECT, K::get_class_static (), Variant (), Variant::OBJECT, V::get_class_static (), Variant ());
64+ for (const KeyValue<K, V> &E : p_init) {
65+ operator [](E.key ) = E.value ;
66+ }
67+ }
6068};
6169
6270// specialization for the rest of variant types
6371
64- #define MAKE_TYPED_DICTIONARY_WITH_OBJECT (m_type, m_variant_type ) \
65- template <typename T> \
66- class TypedDictionary <T, m_type> : public Dictionary { \
67- public: \
68- _FORCE_INLINE_ void operator =(const Dictionary &p_dictionary) { \
69- ERR_FAIL_COND_MSG (!is_same_typed (p_dictionary), " Cannot assign an dictionary with a different element type." ); \
70- Dictionary::operator =(p_dictionary); \
71- } \
72- _FORCE_INLINE_ TypedDictionary (const Variant &p_variant) : \
73- TypedDictionary(Dictionary(p_variant)) { \
74- } \
75- _FORCE_INLINE_ TypedDictionary (const Dictionary &p_dictionary) { \
76- set_typed (Variant::OBJECT, T::get_class_static (), Variant (), m_variant_type, StringName (), Variant ()); \
77- if (is_same_typed (p_dictionary)) { \
78- Dictionary::operator =(p_dictionary); \
79- } else { \
80- assign (p_dictionary); \
81- } \
82- } \
83- _FORCE_INLINE_ TypedDictionary () { \
84- set_typed (Variant::OBJECT, T::get_class_static (), Variant (), m_variant_type, StringName (), Variant ()); \
85- } \
86- }; \
87- template <typename T> \
88- class TypedDictionary <m_type, T> : public Dictionary { \
89- public: \
90- _FORCE_INLINE_ void operator =(const Dictionary &p_dictionary) { \
91- ERR_FAIL_COND_MSG (!is_same_typed (p_dictionary), " Cannot assign an dictionary with a different element type." ); \
92- Dictionary::operator =(p_dictionary); \
93- } \
94- _FORCE_INLINE_ TypedDictionary (const Variant &p_variant) : \
95- TypedDictionary(Dictionary(p_variant)) { \
96- } \
97- _FORCE_INLINE_ TypedDictionary (const Dictionary &p_dictionary) { \
98- set_typed (m_variant_type, StringName (), Variant (), Variant::OBJECT, T::get_class_static (), Variant ()); \
99- if (is_same_typed (p_dictionary)) { \
100- Dictionary::operator =(p_dictionary); \
101- } else { \
102- assign (p_dictionary); \
103- } \
104- } \
105- _FORCE_INLINE_ TypedDictionary () { \
106- set_typed (m_variant_type, StringName (), Variant (), Variant::OBJECT, T::get_class_static (), Variant ()); \
107- } \
72+ #define MAKE_TYPED_DICTIONARY_WITH_OBJECT (m_type, m_variant_type ) \
73+ template <typename T> \
74+ class TypedDictionary <T, m_type> : public Dictionary { \
75+ public: \
76+ _FORCE_INLINE_ void operator =(const Dictionary &p_dictionary) { \
77+ ERR_FAIL_COND_MSG (!is_same_typed (p_dictionary), " Cannot assign an dictionary with a different element type." ); \
78+ Dictionary::operator =(p_dictionary); \
79+ } \
80+ _FORCE_INLINE_ TypedDictionary (const Variant &p_variant) : \
81+ TypedDictionary(Dictionary(p_variant)) { \
82+ } \
83+ _FORCE_INLINE_ TypedDictionary (const Dictionary &p_dictionary) { \
84+ set_typed (Variant::OBJECT, T::get_class_static (), Variant (), m_variant_type, StringName (), Variant ()); \
85+ if (is_same_typed (p_dictionary)) { \
86+ Dictionary::operator =(p_dictionary); \
87+ } else { \
88+ assign (p_dictionary); \
89+ } \
90+ } \
91+ _FORCE_INLINE_ TypedDictionary () { \
92+ set_typed (Variant::OBJECT, T::get_class_static (), Variant (), m_variant_type, StringName (), Variant ()); \
93+ } \
94+ _FORCE_INLINE_ TypedDictionary (std::initializer_list<KeyValue<T, m_type>> p_init) : \
95+ Dictionary() { \
96+ set_typed (Variant::OBJECT, T::get_class_static (), Variant (), m_variant_type, StringName (), Variant ()); \
97+ for (const KeyValue<T, m_type> &E : p_init) { \
98+ operator [](E.key ) = E.value ; \
99+ } \
100+ } \
101+ }; \
102+ template <typename T> \
103+ class TypedDictionary <m_type, T> : public Dictionary { \
104+ public: \
105+ _FORCE_INLINE_ void operator =(const Dictionary &p_dictionary) { \
106+ ERR_FAIL_COND_MSG (!is_same_typed (p_dictionary), " Cannot assign an dictionary with a different element type." ); \
107+ Dictionary::operator =(p_dictionary); \
108+ } \
109+ _FORCE_INLINE_ TypedDictionary (const Variant &p_variant) : \
110+ TypedDictionary(Dictionary(p_variant)) { \
111+ } \
112+ _FORCE_INLINE_ TypedDictionary (const Dictionary &p_dictionary) { \
113+ set_typed (m_variant_type, StringName (), Variant (), Variant::OBJECT, T::get_class_static (), Variant ()); \
114+ if (is_same_typed (p_dictionary)) { \
115+ Dictionary::operator =(p_dictionary); \
116+ } else { \
117+ assign (p_dictionary); \
118+ } \
119+ } \
120+ _FORCE_INLINE_ TypedDictionary () { \
121+ set_typed (m_variant_type, StringName (), Variant (), Variant::OBJECT, T::get_class_static (), Variant ()); \
122+ } \
123+ _FORCE_INLINE_ TypedDictionary (std::initializer_list<KeyValue<m_type, T>> p_init) : \
124+ Dictionary() { \
125+ set_typed (m_variant_type, StringName (), Variant (), Variant::OBJECT, std::remove_pointer<T>::type::get_class_static (), Variant ()); \
126+ for (const KeyValue<m_type, T> &E : p_init) { \
127+ operator [](E.key ) = E.value ; \
128+ } \
129+ } \
108130 };
109131
110132#define MAKE_TYPED_DICTIONARY_EXPANDED (m_type_key, m_variant_type_key, m_type_value, m_variant_type_value ) \
@@ -129,6 +151,13 @@ class TypedDictionary : public Dictionary {
129151 _FORCE_INLINE_ TypedDictionary () { \
130152 set_typed (m_variant_type_key, StringName (), Variant (), m_variant_type_value, StringName (), Variant ()); \
131153 } \
154+ _FORCE_INLINE_ TypedDictionary (std::initializer_list<KeyValue<m_type_key, m_type_value>> p_init) : \
155+ Dictionary() { \
156+ set_typed (m_variant_type_key, StringName (), Variant (), m_variant_type_value, StringName (), Variant ()); \
157+ for (const KeyValue<m_type_key, m_type_value> &E : p_init) { \
158+ operator [](E.key ) = E.value ; \
159+ } \
160+ } \
132161 };
133162
134163#define MAKE_TYPED_DICTIONARY_NIL (m_type, m_variant_type ) \
0 commit comments