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

Realized that Ref's functions need to be in the header file because it is a template.

parent f7788085
No related branches found
No related tags found
No related merge requests found
...@@ -785,9 +785,6 @@ ...@@ -785,9 +785,6 @@
<File <File
RelativePath=".\obj\NiZBufferProperty.cpp"> RelativePath=".\obj\NiZBufferProperty.cpp">
</File> </File>
<File
RelativePath=".\obj\Ref.cpp">
</File>
<File <File
RelativePath=".\obj\RootCollisionNode.cpp"> RelativePath=".\obj\RootCollisionNode.cpp">
</File> </File>
......
/* 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 );
}
...@@ -31,4 +31,108 @@ protected: ...@@ -31,4 +31,108 @@ protected:
T* _object; 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 #endif
\ No newline at end of file
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