aboutsummaryrefslogtreecommitdiff
path: root/src/lua/common/Reference.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/common/Reference.hpp
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/common/Reference.hpp')
-rw-r--r--src/lua/common/Reference.hpp144
1 files changed, 77 insertions, 67 deletions
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 T>
- 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 T>
+ 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<T>& ref);
-
- };
-
-}
+ public:
+ Ref(T* obj, const char* type)
+ : RefBase(obj, type)
+ {
+ }
+
+ ~Ref()
+ {
+ T* obj = static_cast<T*>(object);
+ delete obj;
+ }
+
+ T* operator->()
+ {
+ return (T*)object;
+ }
+
+ T* getObject()
+ {
+ return (T*)object;
+ }
+
+ private:
+ Ref(const Ref<T>& ref);
+
+ };
+
+ }
}
#endif \ No newline at end of file