From 6f0567242e23759b26b7f1403f48082528f439e6 Mon Sep 17 00:00:00 2001 From: Shon Ferguson <shonferg@users.sourceforge.net> Date: Sun, 28 May 2006 03:31:14 +0000 Subject: [PATCH] Implemented Ref member functions. --- obj/NiObject.cpp | 34 ++------------------------- obj/NiObject.h | 34 ++------------------------- obj/Ref.cpp | 60 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 74 deletions(-) diff --git a/obj/NiObject.cpp b/obj/NiObject.cpp index 10d5dc56..be59a607 100644 --- a/obj/NiObject.cpp +++ b/obj/NiObject.cpp @@ -1,35 +1,5 @@ -/* Copyright (c) 2005, NIF File Format Library and Tools -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of the NIF File Format Library and Tools - project nor the names of its contributors may be used to endorse - or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. */ +/* Copyright (c) 2006, NIF File Format Library and Tools +All rights reserved. Please see niflib.h for licence. */ #include "NiObject.h" diff --git a/obj/NiObject.h b/obj/NiObject.h index 678b47ea..f46dd623 100644 --- a/obj/NiObject.h +++ b/obj/NiObject.h @@ -1,35 +1,5 @@ -/* Copyright (c) 2005, NIF File Format Library and Tools -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of the NIF File Format Library and Tools - project nor the names of its contributors may be used to endorse - or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. */ +/* Copyright (c) 2006, NIF File Format Library and Tools +All rights reserved. Please see niflib.h for licence. */ #ifndef _NIOBJECT_H_ #define _NIOBJECT_H_ diff --git a/obj/Ref.cpp b/obj/Ref.cpp index 348b9431..add4863c 100644 --- a/obj/Ref.cpp +++ b/obj/Ref.cpp @@ -8,32 +8,68 @@ 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> @@ -43,20 +79,24 @@ bool Ref<T>::operator<(const Ref & ref) const { 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 ); } -- GitLab