]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/accessguard.h
Enforce correct access to buffered components
[libs/game.git] / source / game / accessguard.h
index c64efe75bee9de0ae04427f3b3589b295b8d6fdd..26bbb4e0e99b3d7bb896c6376e7e1d22f9fae827 100644 (file)
@@ -6,6 +6,7 @@
 #include <string>
 #include <vector>
 #include <msp/core/noncopyable.h>
+#include <msp/debug/demangle.h>
 
 namespace Msp::Game {
 
@@ -21,6 +22,8 @@ class AccessGuard
 public:
        struct Create { static std::string describe() { return "create"; } };
        struct Destroy { static std::string describe() { return "destroy"; } };
+       template<typename T> struct Read { static std::string describe(); };
+       template<typename T> struct Write { static std::string describe(); };
 
        template<typename T = void>
        struct BlockForScope: NonCopyable
@@ -94,6 +97,19 @@ template<>
 inline void AccessGuard::unblock<void>()
 { unblock_all(); }
 
+
+template<typename T>
+inline std::string AccessGuard::Read<T>::describe()
+{
+       return "read "+Debug::demangle(typeid(T).name());
+}
+
+template<typename T>
+inline std::string AccessGuard::Write<T>::describe()
+{
+       return "write "+Debug::demangle(typeid(T).name());
+}
+
 } // namespace Msp::Game
 
 #endif