summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/common/Rtti.cpp7
-rw-r--r--src/core/common/Rtti.hpp2
-rw-r--r--src/core/managed/Managed.cpp5
-rw-r--r--src/core/managed/Managed.hpp12
-rw-r--r--test/core/common/RttiTest.cpp62
5 files changed, 52 insertions, 36 deletions
diff --git a/src/core/common/Rtti.cpp b/src/core/common/Rtti.cpp
index 5de2b4c..edfcda8 100644
--- a/src/core/common/Rtti.cpp
+++ b/src/core/common/Rtti.cpp
@@ -54,7 +54,7 @@ void RttiBase::initialize() const
initialized = true;
// Insert the parent types of the parent types and the aggregated types
- // if the parents
+ // of the parents
{
std::unordered_set<const RttiBase *> origParents = parents;
for (const RttiBase *parent : origParents) {
@@ -69,7 +69,8 @@ void RttiBase::initialize() const
parents.insert(this);
}
- // Insert the aggregated types of the aggregated types
+ // Insert the aggregated types of the aggregated types and the parents
+ // of each aggregated type
{
std::unordered_set<const RttiBase *> origAggregatedTypes =
aggregatedTypes;
@@ -90,7 +91,7 @@ bool RttiBase::isa(const RttiBase &other) const
return parents.count(&other) > 0;
}
-bool RttiBase::contains(const RttiBase &other) const
+bool RttiBase::aggregatedOf(const RttiBase &other) const
{
initialize();
return aggregatedTypes.count(&other) > 0;
diff --git a/src/core/common/Rtti.hpp b/src/core/common/Rtti.hpp
index 090b65b..deaf128 100644
--- a/src/core/common/Rtti.hpp
+++ b/src/core/common/Rtti.hpp
@@ -189,7 +189,7 @@ public:
* @param other is the other type for which should be checked whether this
* type is directly or indirectly aggregated of it.
*/
- bool contains(const RttiBase &other) const;
+ bool aggregatedOf(const RttiBase &other) const;
};
/**
diff --git a/src/core/managed/Managed.cpp b/src/core/managed/Managed.cpp
index 341e0d0..cede819 100644
--- a/src/core/managed/Managed.cpp
+++ b/src/core/managed/Managed.cpp
@@ -80,4 +80,9 @@ bool Managed::triggerEvent(Event &ev) { return mgr.triggerEvent(this, ev); }
const RttiBase &Managed::type() const { return typeOf(*this); }
bool Managed::isa(const RttiBase &t) const { return type().isa(t); }
+
+bool Managed::aggregatedOf(const RttiBase &t) const
+{
+ return type().aggregatedOf(t);
+}
}
diff --git a/src/core/managed/Managed.hpp b/src/core/managed/Managed.hpp
index cdf81aa..fecbfdd 100644
--- a/src/core/managed/Managed.hpp
+++ b/src/core/managed/Managed.hpp
@@ -199,13 +199,23 @@ public:
const RttiBase &type() const;
/**
- * Returns true if this Managed instance is of the given RttiBase.
+ * Returns true if this Managed instance is of the type described by the
+ * given RttiBase instance.
*
* @param true if the RttiBase registered for this particular Managed
* class is of the given type or one of the registered parent types is of
* the given type.
*/
bool isa(const RttiBase &t) const;
+
+ /**
+ * Returns true if this Managed instance may contain instances of the type
+ * described by the given RttiBase instance.
+ *
+ * @param true if the RttiBase registered for this particular Managed class
+ * may contain instance of the given type.
+ */
+ bool aggregatedOf(const RttiBase &t) const;
};
/**
diff --git a/test/core/common/RttiTest.cpp b/test/core/common/RttiTest.cpp
index fdeb8f0..e875efa 100644
--- a/test/core/common/RttiTest.cpp
+++ b/test/core/common/RttiTest.cpp
@@ -76,42 +76,42 @@ TEST(Rtti, isa)
ASSERT_TRUE(Type4.isa(Type4));
}
-TEST(Rtti, contains)
+TEST(Rtti, aggregatedOf)
{
std::vector<const RttiBase *> types{&Type1, &Type2, &Type3, &Type4};
for (auto t : types) {
- ASSERT_FALSE(t->contains(Type1));
- ASSERT_FALSE(t->contains(Type2));
- ASSERT_FALSE(t->contains(Type3));
- ASSERT_FALSE(t->contains(Type4));
- ASSERT_FALSE(t->contains(Type5));
- ASSERT_FALSE(t->contains(Type6));
- ASSERT_FALSE(t->contains(Type7));
+ ASSERT_FALSE(t->aggregatedOf(Type1));
+ ASSERT_FALSE(t->aggregatedOf(Type2));
+ ASSERT_FALSE(t->aggregatedOf(Type3));
+ ASSERT_FALSE(t->aggregatedOf(Type4));
+ ASSERT_FALSE(t->aggregatedOf(Type5));
+ ASSERT_FALSE(t->aggregatedOf(Type6));
+ ASSERT_FALSE(t->aggregatedOf(Type7));
}
- ASSERT_TRUE(Type5.contains(Type1));
- ASSERT_FALSE(Type5.contains(Type2));
- ASSERT_FALSE(Type5.contains(Type3));
- ASSERT_FALSE(Type5.contains(Type4));
- ASSERT_FALSE(Type5.contains(Type5));
- ASSERT_TRUE(Type5.contains(Type6));
- ASSERT_TRUE(Type5.contains(Type7));
-
- ASSERT_TRUE(Type6.contains(Type1));
- ASSERT_FALSE(Type6.contains(Type2));
- ASSERT_FALSE(Type6.contains(Type3));
- ASSERT_FALSE(Type6.contains(Type4));
- ASSERT_FALSE(Type6.contains(Type5));
- ASSERT_FALSE(Type6.contains(Type6));
- ASSERT_FALSE(Type6.contains(Type7));
-
- ASSERT_TRUE(Type7.contains(Type1));
- ASSERT_FALSE(Type7.contains(Type2));
- ASSERT_FALSE(Type7.contains(Type3));
- ASSERT_FALSE(Type7.contains(Type4));
- ASSERT_FALSE(Type7.contains(Type5));
- ASSERT_FALSE(Type7.contains(Type6));
- ASSERT_FALSE(Type7.contains(Type7));
+ ASSERT_TRUE(Type5.aggregatedOf(Type1));
+ ASSERT_FALSE(Type5.aggregatedOf(Type2));
+ ASSERT_FALSE(Type5.aggregatedOf(Type3));
+ ASSERT_FALSE(Type5.aggregatedOf(Type4));
+ ASSERT_FALSE(Type5.aggregatedOf(Type5));
+ ASSERT_TRUE(Type5.aggregatedOf(Type6));
+ ASSERT_TRUE(Type5.aggregatedOf(Type7));
+
+ ASSERT_TRUE(Type6.aggregatedOf(Type1));
+ ASSERT_FALSE(Type6.aggregatedOf(Type2));
+ ASSERT_FALSE(Type6.aggregatedOf(Type3));
+ ASSERT_FALSE(Type6.aggregatedOf(Type4));
+ ASSERT_FALSE(Type6.aggregatedOf(Type5));
+ ASSERT_FALSE(Type6.aggregatedOf(Type6));
+ ASSERT_FALSE(Type6.aggregatedOf(Type7));
+
+ ASSERT_TRUE(Type7.aggregatedOf(Type1));
+ ASSERT_FALSE(Type7.aggregatedOf(Type2));
+ ASSERT_FALSE(Type7.aggregatedOf(Type3));
+ ASSERT_FALSE(Type7.aggregatedOf(Type4));
+ ASSERT_FALSE(Type7.aggregatedOf(Type5));
+ ASSERT_FALSE(Type7.aggregatedOf(Type6));
+ ASSERT_FALSE(Type7.aggregatedOf(Type7));
}
}
}