summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-03 16:17:11 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-01-03 16:17:11 +0100
commit603dedfa2b3704730fa4db8e7f84702b26da9ae6 (patch)
treed2e03ce8bfc90c54aa7e6ee560aeafc3c5cabdb0
parent17e79d4535ef4dba7346dedb2a8341fc4421fa23 (diff)
Improved contains functionality (now includes the parent types of each aggregated type and the aggregated types of each parent)
-rw-r--r--src/core/common/Rtti.cpp10
-rw-r--r--test/core/common/RttiTest.cpp31
2 files changed, 34 insertions, 7 deletions
diff --git a/src/core/common/Rtti.cpp b/src/core/common/Rtti.cpp
index 0443a8d..5de2b4c 100644
--- a/src/core/common/Rtti.cpp
+++ b/src/core/common/Rtti.cpp
@@ -53,13 +53,19 @@ void RttiBase::initialize() const
if (!initialized) {
initialized = true;
- // Insert the parent types of the parent types
+ // Insert the parent types of the parent types and the aggregated types
+ // if the parents
{
std::unordered_set<const RttiBase *> origParents = parents;
for (const RttiBase *parent : origParents) {
parent->initialize();
parents.insert(parent->parents.begin(), parent->parents.end());
}
+ for (const RttiBase *parent : parents) {
+ parent->initialize();
+ aggregatedTypes.insert(parent->aggregatedTypes.begin(),
+ parent->aggregatedTypes.end());
+ }
parents.insert(this);
}
@@ -71,6 +77,8 @@ void RttiBase::initialize() const
aggregatedType->initialize();
aggregatedTypes.insert(aggregatedType->aggregatedTypes.begin(),
aggregatedType->aggregatedTypes.end());
+ aggregatedTypes.insert(aggregatedType->parents.begin(),
+ aggregatedType->parents.end());
}
}
}
diff --git a/test/core/common/RttiTest.cpp b/test/core/common/RttiTest.cpp
index 7990593..fdeb8f0 100644
--- a/test/core/common/RttiTest.cpp
+++ b/test/core/common/RttiTest.cpp
@@ -35,15 +35,23 @@ class RttiTestClass3 {
};
class RttiTestClass4 {
};
+class RttiTestClass5 {
+};
+class RttiTestClass6 {
+};
+class RttiTestClass7 {
+};
-extern const Rtti<RttiTestClass2> Type6;
+extern const Rtti<RttiTestClass6> Type6;
+extern const Rtti<RttiTestClass7> Type7;
const Rtti<RttiTestClass1> Type1("Type1");
const Rtti<RttiTestClass2> Type2("Type2");
const Rtti<RttiTestClass3> Type3("Type3", {&Type1});
const Rtti<RttiTestClass4> Type4("Type4", {&Type3, &Type2});
-const Rtti<RttiTestClass1> Type5("Type5", {}, {&Type6});
-const Rtti<RttiTestClass2> Type6("Type6", {}, {&Type5, &Type1});
+const Rtti<RttiTestClass5> Type5("Type5", {}, {&Type6, &Type7});
+const Rtti<RttiTestClass6> Type6("Type6", {}, {&Type1});
+const Rtti<RttiTestClass7> Type7("Type7", {&Type6}, {});
TEST(Rtti, isa)
{
@@ -78,21 +86,32 @@ TEST(Rtti, contains)
ASSERT_FALSE(t->contains(Type4));
ASSERT_FALSE(t->contains(Type5));
ASSERT_FALSE(t->contains(Type6));
+ ASSERT_FALSE(t->contains(Type7));
}
ASSERT_TRUE(Type5.contains(Type1));
ASSERT_FALSE(Type5.contains(Type2));
ASSERT_FALSE(Type5.contains(Type3));
ASSERT_FALSE(Type5.contains(Type4));
- ASSERT_TRUE(Type5.contains(Type5));
+ 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_TRUE(Type6.contains(Type5));
- ASSERT_TRUE(Type6.contains(Type6));
+ 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));
}
}
}