Skip to content
Snippets Groups Projects
Commit e9321fc4 authored by Shon Ferguson's avatar Shon Ferguson
Browse files

Added default constructor to Ref which initializes pointer to NULL.

Added destructor which decrements reference count on any referenced object.
parent feb96f1e
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,10 @@ All rights reserved. Please see niflib.h for licence. */ ...@@ -9,8 +9,10 @@ All rights reserved. Please see niflib.h for licence. */
*/ */
template <class T> class Ref { template <class T> class Ref {
public: public:
Ref();
Ref( T * object = NULL ); Ref( T * object = NULL );
Ref(const Ref & ref_to_copy ); Ref(const Ref & ref_to_copy );
~Ref();
operator T*() const; operator T*() const;
T& operator*() const; T& operator*() const;
...@@ -31,6 +33,9 @@ protected: ...@@ -31,6 +33,9 @@ protected:
T* _object; T* _object;
}; };
template <class T>
Ref<T>::Ref() : _object(NULL) {}
template <class T> template <class T>
Ref<T>::Ref( T * object ) : _object(object) {} Ref<T>::Ref( T * object ) : _object(object) {}
...@@ -43,6 +48,14 @@ Ref<T>::Ref(const Ref & ref_to_copy ) { ...@@ -43,6 +48,14 @@ Ref<T>::Ref(const Ref & ref_to_copy ) {
} }
} }
template <class T>
Ref<T>::~Ref() {
//if object insn't null, decrement reference count
if ( _object != NULL ) {
_object->SubtractRef();
}
}
template <class T> template <class T>
Ref<T>::operator T*() const { Ref<T>::operator T*() const {
return _object; return _object;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment