]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/reflection.h
Decorate things which constitute the public API of the library
[libs/game.git] / source / game / reflection.h
index df974b113d3f32a22a1b1b36227d4be654a0193b..7b75541f5c65bdbb8ce65dd95b67f259cc25af22 100644 (file)
@@ -6,6 +6,7 @@
 #include <string>
 #include <typeindex>
 #include <vector>
+#include "mspgame_api.h"
 
 namespace Msp::Game {
 namespace Reflection {
@@ -40,7 +41,7 @@ public:
 };
 
 
-class ClassBase
+class MSPGAME_API ClassBase
 {
 protected:
        Reflector &reflector;
@@ -85,7 +86,7 @@ private:
 };
 
 
-class Reflector
+class MSPGAME_API Reflector
 {
 private:
        std::vector<std::unique_ptr<ClassBase>> classes;
@@ -93,8 +94,10 @@ private:
        std::vector<std::unique_ptr<ClassBase>>::const_iterator lower_bound(const std::type_index &) const;
 
 public:
+       ClassBase *find_class(const std::type_index &) const;
+
        template<typename T>
-       Class<T> *find_class() const;
+       Class<T> *find_class() const { return static_cast<Class<T> *>(find_class(typeid(T))); }
 
        template<typename T>
        Class<T> &get_or_create_class();
@@ -109,14 +112,6 @@ inline std::vector<std::unique_ptr<ClassBase>>::const_iterator Reflector::lower_
        return std::ranges::lower_bound(classes, type, {}, [](auto &c){ return c->get_type(); });
 }
 
-template<typename T>
-inline Class<T> *Reflector::find_class() const
-{
-       std::type_index type = typeid(T);
-       auto i = lower_bound(type);
-       return (i!=classes.end() && (*i)->get_type()==type ? static_cast<Class<T> *>(i->get()) : nullptr);
-}
-
 template<typename T>
 inline Class<T> &Reflector::get_or_create_class()
 {