Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class NiPointer
- {
- public:
- T * m_pObject;
- inline NiPointer(T* pObject)
- {
- m_pObject = pObject;
- if (m_pObject)
- m_pObject->IncRef();
- };
- inline ~NiPointer()
- {
- if (m_pObject)
- m_pObject->DecRef();
- };
- inline operator T*() const
- {
- return m_pObject;
- };
- inline T& operator*() const
- {
- return *m_pObject;
- };
- inline T* operator->() const
- {
- return m_pObject;
- };
- inline NiPointer<T>& operator=(const NiPointer& ptr)
- {
- if (m_pObject != ptr.m_pObject)
- {
- if (m_pObject)
- m_pObject->DecRef();
- m_pObject = ptr.m_pObject;
- if (m_pObject)
- m_pObject->IncRef();
- }
- return *this;
- };
- inline NiPointer<T>& operator=(T* pObject)
- {
- if (m_pObject != pObject)
- {
- if (m_pObject)
- m_pObject->DecRef();
- m_pObject = pObject;
- if (m_pObject)
- m_pObject->IncRef();
- }
- return *this;
- };
- inline bool operator==(T* pObject) const
- {
- return (m_pObject == pObject);
- };
- inline bool operator!=(T* pObject) const
- {
- return (m_pObject != pObject);
- };
- inline bool operator==(const NiPointer& ptr) const
- {
- return (m_pObject == ptr.m_pObject);
- };
- inline bool operator!=(const NiPointer& ptr) const
- {
- return (m_pObject != ptr.m_pObject);
- };
- };
- #define NiSmartPointer(classname) \
- class classname; \
- typedef NiPointer<classname> classname##Ptr
- #define NiSmartPointerCast(type, smartptr) ((type*) (void*) (smartptr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement