diff --git a/niflib.vcproj b/niflib.vcproj index 2cebf6641cb748e82c06f687514149c1445a439b..fb648bef383ea19af4931a1f889aefa5903ebb6a 100644 --- a/niflib.vcproj +++ b/niflib.vcproj @@ -785,9 +785,6 @@ <File RelativePath=".\obj\NiZBufferProperty.cpp"> </File> - <File - RelativePath=".\obj\Ref.cpp"> - </File> <File RelativePath=".\obj\RootCollisionNode.cpp"> </File> diff --git a/obj/Ref.cpp b/obj/Ref.cpp deleted file mode 100644 index add4863c1e231fce3b4122f2471c8ab2b3be0932..0000000000000000000000000000000000000000 --- a/obj/Ref.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (c) 2006, NIF File Format Library and Tools -All rights reserved. Please see niflib.h for licence. */ - -#include "Ref.h" - -template <class T> -Ref<T>::Ref( T * object = NULL ) : _object(object) {} - -template <class T> -Ref<T>::Ref(const Ref & ref_to_copy ) { - _object = ref_to_copy._object; - //If object isn't null, increment reference count - if ( _object != NULL ) { - _object->AddRef(); - } -} - -template <class T> -Ref<T>::operator T*() const { - return _object; -} - -template <class T> -T& Ref<T>::operator*() const { - return _object; -} - -template <class T> -T* Ref<T>::operator->() const { - return _object; -} - -template <class T> -Ref<T> & Ref<T>::operator=( T * object ) { - //Check if referenced objects are already the same - if ( _object == object ) { - return this; //Do nothing - } - - //Decriment reference count on previously referenced object, if any - if ( _object != NULL ) { - _object->SubtractRef(); - } - - //Change reference to new object - _object = object; - - //Increment reerence count on new object if it is not NULL - if ( _object != NULL ) { - _object->AddRef(); - } -} - -template <class T> -Ref<T> & Ref<T>::operator=( const Ref & ref ) { - //Check if referenced objects are already the same - if ( _object == ref._object ) { - return this; //Do nothing - } - - //Decriment reference count on previously referenced object, if any - if ( _object != NULL ) { - _object->SubtractRef(); - } - - //Change reference to new object - _object = ref._object; - - //Increment reerence count on new object if it is not NULL - if ( _object != NULL ) { - _object->AddRef(); - } -} - -template <class T> -bool Ref<T>::operator<(const Ref & ref) const { - return (_object < ref._object); -} - -template <class T> -bool Ref<T>::operator==(T * object) const { - //Compare pointer values of referenced objects - return ( _object == object ); -} - -template <class T> -bool Ref<T>::operator!=(T * object) const { - //Compare pointer values of referenced objects - return ( _object != object ); -} - -template <class T> -bool Ref<T>::operator==(const Ref & ref) const { - //Compare pointer values of referenced objects - return ( _object == ref._object ); -} - -template <class T> -bool Ref<T>::operator!=(const Ref & ref) const { - //Compare pointer values of referenced objects - return ( _object != ref._object ); -} diff --git a/obj/Ref.h b/obj/Ref.h index e6767f3de30e23248d25fbd9fdee602598e1e238..22262137bf07b96db3dd380ed3d94d1fbdf15677 100644 --- a/obj/Ref.h +++ b/obj/Ref.h @@ -31,4 +31,108 @@ protected: T* _object; }; +template <class T> +Ref<T>::Ref( T * object = NULL ) : _object(object) {} + +template <class T> +Ref<T>::Ref(const Ref & ref_to_copy ) { + _object = ref_to_copy._object; + //If object isn't null, increment reference count + if ( _object != NULL ) { + _object->AddRef(); + } +} + +template <class T> +Ref<T>::operator T*() const { + return _object; +} + +template <class T> +T& Ref<T>::operator*() const { + return _object; +} + +template <class T> +T* Ref<T>::operator->() const { + return _object; +} + +template <class T> +Ref<T> & Ref<T>::operator=( T * object ) { + //Check if referenced objects are already the same + if ( _object == object ) { + return *this; //Do nothing + } + + //Decriment reference count on previously referenced object, if any + if ( _object != NULL ) { + _object->SubtractRef(); + } + + //Change reference to new object + _object = object; + + //Increment reerence count on new object if it is not NULL + if ( _object != NULL ) { + _object->AddRef(); + } + + return *this; +} + +template <class T> +Ref<T> & Ref<T>::operator=( const Ref & ref ) { + //Check if referenced objects are already the same + if ( _object == ref._object ) { + return *this; //Do nothing + } + + //Decriment reference count on previously referenced object, if any + if ( _object != NULL ) { + _object->SubtractRef(); + } + + //Change reference to new object + _object = ref._object; + + //Increment reerence count on new object if it is not NULL + if ( _object != NULL ) { + _object->AddRef(); + } + + return *this; +} + +//Template functions must be in the header file + +template <class T> +bool Ref<T>::operator<(const Ref & ref) const { + return (_object < ref._object); +} + +template <class T> +bool Ref<T>::operator==(T * object) const { + //Compare pointer values of referenced objects + return ( _object == object ); +} + +template <class T> +bool Ref<T>::operator!=(T * object) const { + //Compare pointer values of referenced objects + return ( _object != object ); +} + +template <class T> +bool Ref<T>::operator==(const Ref & ref) const { + //Compare pointer values of referenced objects + return ( _object == ref._object ); +} + +template <class T> +bool Ref<T>::operator!=(const Ref & ref) const { + //Compare pointer values of referenced objects + return ( _object != ref._object ); +} + #endif \ No newline at end of file