X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Freflection.h;h=7b75541f5c65bdbb8ce65dd95b67f259cc25af22;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=df974b113d3f32a22a1b1b36227d4be654a0193b;hpb=f377d216dfc44e36da3697557f38dfedcbec45d1;p=libs%2Fgame.git diff --git a/source/game/reflection.h b/source/game/reflection.h index df974b1..7b75541 100644 --- a/source/game/reflection.h +++ b/source/game/reflection.h @@ -6,6 +6,7 @@ #include #include #include +#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> classes; @@ -93,8 +94,10 @@ private: std::vector>::const_iterator lower_bound(const std::type_index &) const; public: + ClassBase *find_class(const std::type_index &) const; + template - Class *find_class() const; + Class *find_class() const { return static_cast *>(find_class(typeid(T))); } template Class &get_or_create_class(); @@ -109,14 +112,6 @@ inline std::vector>::const_iterator Reflector::lower_ return std::ranges::lower_bound(classes, type, {}, [](auto &c){ return c->get_type(); }); } -template -inline Class *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 *>(i->get()) : nullptr); -} - template inline Class &Reflector::get_or_create_class() {