X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Faccessguard.h;h=2d9a3053b8324a8e06abdb8713f8469bd5907d84;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=c64efe75bee9de0ae04427f3b3589b295b8d6fdd;hpb=48051ee2bab13f65e48c371e453b9ea65920921e;p=libs%2Fgame.git diff --git a/source/game/accessguard.h b/source/game/accessguard.h index c64efe7..2d9a305 100644 --- a/source/game/accessguard.h +++ b/source/game/accessguard.h @@ -6,21 +6,25 @@ #include #include #include +#include +#include "mspgame_api.h" namespace Msp::Game { -class invalid_access: public std::logic_error +class MSPGAME_API invalid_access: public std::logic_error { public: invalid_access(const std::string &w): logic_error(w) { } }; -class AccessGuard +class MSPGAME_API AccessGuard { public: struct Create { static std::string describe() { return "create"; } }; struct Destroy { static std::string describe() { return "destroy"; } }; + template struct Read { static std::string describe(); }; + template struct Write { static std::string describe(); }; template struct BlockForScope: NonCopyable @@ -66,7 +70,7 @@ public: void unblock() { get() = UNBLOCKED; } template - void check() { if(get()!=UNBLOCKED) throw invalid_access(T::describe()); } + void check(); }; @@ -94,6 +98,27 @@ template<> inline void AccessGuard::unblock() { unblock_all(); } +template +inline void AccessGuard::check() +{ + unsigned index = get_index(); + if((index +inline std::string AccessGuard::Read::describe() +{ + return "read "+Debug::demangle(typeid(T).name()); +} + +template +inline std::string AccessGuard::Write::describe() +{ + return "write "+Debug::demangle(typeid(T).name()); +} + } // namespace Msp::Game #endif