mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Add missing initializer_list constructor for TypedDictionary
This commit is contained in:
@@ -85,6 +85,10 @@ class Ref {
|
|||||||
|
|
||||||
//virtual RefCounted * get_reference() const { return reference; }
|
//virtual RefCounted * get_reference() const { return reference; }
|
||||||
public:
|
public:
|
||||||
|
static _FORCE_INLINE_ String get_class_static() {
|
||||||
|
return T::get_class_static();
|
||||||
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ bool operator==(const T *p_ptr) const {
|
_FORCE_INLINE_ bool operator==(const T *p_ptr) const {
|
||||||
return reference == p_ptr;
|
return reference == p_ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,13 @@ struct GetTypeInfo<const TypedDictionary<K, V> &> {
|
|||||||
_FORCE_INLINE_ TypedDictionary() { \
|
_FORCE_INLINE_ TypedDictionary() { \
|
||||||
set_typed(m_variant_type, StringName(), Variant(), Variant::OBJECT, T::get_class_static(), Variant()); \
|
set_typed(m_variant_type, StringName(), Variant(), Variant::OBJECT, T::get_class_static(), Variant()); \
|
||||||
} \
|
} \
|
||||||
|
_FORCE_INLINE_ TypedDictionary(std::initializer_list<KeyValue<m_type, T>> p_init) : \
|
||||||
|
Dictionary() { \
|
||||||
|
set_typed(m_variant_type, StringName(), Variant(), Variant::OBJECT, std::remove_pointer<T>::type::get_class_static(), Variant()); \
|
||||||
|
for (const KeyValue<m_type, T> &E : p_init) { \
|
||||||
|
operator[](E.key) = E.value; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
}; \
|
}; \
|
||||||
template <typename T> \
|
template <typename T> \
|
||||||
struct GetTypeInfo<TypedDictionary<m_type, T>> { \
|
struct GetTypeInfo<TypedDictionary<m_type, T>> { \
|
||||||
|
|||||||
@@ -606,4 +606,28 @@ TEST_CASE("[Dictionary] Iteration") {
|
|||||||
a2.clear();
|
a2.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Dictionary] Object value init") {
|
||||||
|
Object *a = memnew(Object);
|
||||||
|
Object *b = memnew(Object);
|
||||||
|
TypedDictionary<double, Object *> tdict = {
|
||||||
|
{ 0.0, a },
|
||||||
|
{ 5.0, b },
|
||||||
|
};
|
||||||
|
CHECK_EQ(tdict[0.0], Variant(a));
|
||||||
|
CHECK_EQ(tdict[5.0], Variant(b));
|
||||||
|
memdelete(a);
|
||||||
|
memdelete(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Dictionary] RefCounted value init") {
|
||||||
|
Ref<RefCounted> a = memnew(RefCounted);
|
||||||
|
Ref<RefCounted> b = memnew(RefCounted);
|
||||||
|
TypedDictionary<double, Ref<RefCounted>> tdict = {
|
||||||
|
{ 0.0, a },
|
||||||
|
{ 5.0, b },
|
||||||
|
};
|
||||||
|
CHECK_EQ(tdict[0.0], Variant(a));
|
||||||
|
CHECK_EQ(tdict[5.0], Variant(b));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TestDictionary
|
} // namespace TestDictionary
|
||||||
|
|||||||
Reference in New Issue
Block a user