From 40fc27154fe754181934dc7ee31375e6bdfb33fc Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 23 Oct 2018 12:23:58 +0800 Subject: *merge from minimal --- src/lua/common/Reference.hpp | 144 +++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 67 deletions(-) (limited to 'src/lua/common/Reference.hpp') diff --git a/src/lua/common/Reference.hpp b/src/lua/common/Reference.hpp index feb96bb..ba918bb 100644 --- a/src/lua/common/Reference.hpp +++ b/src/lua/common/Reference.hpp @@ -1,78 +1,88 @@ #ifndef __JIN_COMMON_REFERENCE_H #define __JIN_COMMON_REFERENCE_H -namespace jin +namespace JinEngine { -namespace lua -{ - - /*abstract*/class RefBase + namespace Lua { - public: - void retain() - { - ++count; - } - void release() + /*abstract*/class RefBase { - if (--count <= 0) - delete this; - } - - // object type string - const char* const type; - - protected: - RefBase(void* obj, const char* t) - : count(1) - , object(obj) - , type(t) - { - } - - RefBase(const RefBase&); - - virtual ~RefBase() - { - } - - void* object; - int count; - - }; - - template - class Ref : public RefBase - { - public: - Ref(T* obj, const char* type) - : RefBase(obj, type) + public: + void retain() + { + ++count; + } + + void release() + { + if (--count <= 0) + delete this; + } + + // object type string + const char* const type; + + void setUserdata(void* data) + { + userdata = data; + } + + void* getUserdata() + { + return userdata; + } + + protected: + RefBase(void* obj, const char* t) + : count(1) + , object(obj) + , type(t) + { + } + + RefBase(const RefBase&); + + virtual ~RefBase() + { + } + + void* object; + int count; + void* userdata; + }; + + template + class Ref : public RefBase { - } - - ~Ref() - { - T* obj = (T*)object; - delete obj; - } - - T* operator->() - { - return (T*)object; - } - - T* getObject() - { - return (T*)object; - } - - private: - Ref(const Ref& ref); - - }; - -} + public: + Ref(T* obj, const char* type) + : RefBase(obj, type) + { + } + + ~Ref() + { + T* obj = static_cast(object); + delete obj; + } + + T* operator->() + { + return (T*)object; + } + + T* getObject() + { + return (T*)object; + } + + private: + Ref(const Ref& ref); + + }; + + } } #endif \ No newline at end of file -- cgit v1.1-26-g67d0