]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/reflection.cpp
Add reflection infrastructure
[libs/game.git] / source / game / reflection.cpp
diff --git a/source/game/reflection.cpp b/source/game/reflection.cpp
new file mode 100644 (file)
index 0000000..d188e50
--- /dev/null
@@ -0,0 +1,28 @@
+#include "reflection.h"
+#include <msp/debug/demangle.h>
+
+using namespace std;
+
+namespace Msp::Game {
+namespace Reflection {
+
+ClassBase::ClassBase(Reflector &r, type_index t):
+       reflector(r),
+       type(t),
+       name(Debug::demangle(t.name()))
+{ }
+
+bool ClassBase::is_direct_base_of(const ClassBase &other) const
+{
+       return ranges::find(other.bases, this)!=other.bases.end();
+}
+
+bool ClassBase::is_base_of(const ClassBase &other) const
+{
+       if(is_direct_base_of(other))
+               return true;
+       return ranges::any_of(other.bases, [this](const ClassBase *b){ return is_base_of(*b); });
+}
+
+} // namespace Reflection
+} // namespace Msp::Game