From 045cfe28fe8960808c39d008fb1fd03f1a9c910b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 15:45:09 +0100 Subject: [PATCH 1/3] Renamed Utilities-InlineImpl.h to Utilities-Impl.h Implied that only Inlines were implemented there. Contains template implementations as well. --- .../{Utilities-InlineImpl.h => Utilities-Impl.h} | 0 Code/Misc/Utilities.h | 12 +++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) rename Code/Misc/{Utilities-InlineImpl.h => Utilities-Impl.h} (100%) diff --git a/Code/Misc/Utilities-InlineImpl.h b/Code/Misc/Utilities-Impl.h similarity index 100% rename from Code/Misc/Utilities-InlineImpl.h rename to Code/Misc/Utilities-Impl.h diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index 2294918e..cdceb894 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -27,6 +27,9 @@ namespace Utility template struct UniquePointer { public: + //! Creates an empty UniquePointer. + //UniquePointer(); + //! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. UniquePointer( Type *assignedInstance = NULL ); @@ -40,7 +43,7 @@ namespace Utility //! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. - UniquePointer & operator = ( Type *assignedInstance ); + UniquePointer & operator = ( Type *assignedInstance ); // potential ambiguous //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. //! If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. @@ -81,6 +84,9 @@ namespace Utility struct UniqueArray { //! Wrapper to safely transfer dynamic ownership/responsibility public: + //! Creates an empty UniqueArray. + //UniqueArray(); + //! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. UniqueArray( Type assignedArray[] = NULL ); @@ -94,7 +100,7 @@ namespace Utility //! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. - UniqueArray & operator = ( Type assignedArray[] ); + UniqueArray & operator = ( Type assignedArray[] ); // potential ambiguous //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. //! If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. @@ -331,6 +337,6 @@ namespace Utility } } -#include "Utilities-InlineImpl.h" +#include "Utilities-Impl.h" #endif \ No newline at end of file From 036519f3f679efb7fd8c7e2cca33a396017e2c79 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 16:06:01 +0100 Subject: [PATCH 2/3] Fixed potential ambiguity bug Ambiguity in assignment operator with UniquePointer and UniqueArray --- Code/Misc/Misc.vcxproj | 11 ++++++++--- Code/Misc/Misc.vcxproj.filters | 23 +++++++++++++++++++---- Code/Misc/Utilities-Impl.h | 21 +++++---------------- Code/Misc/Utilities.h | 26 ++++++++------------------ 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index e2947725..c41ed349 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -148,15 +148,20 @@ - + + + - - + + + + + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 6eae993b..3f2d3b40 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -27,6 +27,12 @@ Source Files + + Source Files + + + Source Files + Source Files @@ -41,14 +47,23 @@ Header Files - - Header Files - - + Header Files Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Code/Misc/Utilities-Impl.h b/Code/Misc/Utilities-Impl.h index 50d13652..655f06c5 100644 --- a/Code/Misc/Utilities-Impl.h +++ b/Code/Misc/Utilities-Impl.h @@ -1,7 +1,11 @@ ///////////////////////////////////////////////////////////////////// // Inline and template implementations for // the Utility Collection of Miscellanious Handy Functions -// © Dan Andersson 2013 +// +// Created 2013 by Dan Andersson +// Edited 2013 by +// * Dan Andersson +// * Dennis Andersen ///////////////////////////////////////////////////////////////////// #ifndef UTILITIES_INLINE_IMPL_H @@ -51,14 +55,6 @@ namespace Utility SafeDeleteInstance( this->ownedInstance ); } - template - UniquePointer & UniquePointer::operator = ( Type *assignedInstance ) - { - SafeDeleteInstance( this->ownedInstance ); - this->ownedInstance = assignedInstance; - return *this; - } - template UniquePointer & UniquePointer::operator = ( const UniquePointer &donor ) { @@ -144,13 +140,6 @@ namespace Utility SafeDeleteArray( this->ownedArray ); } - template - UniqueArray & UniqueArray::operator = ( Type assignedArray[] ) - { - SafeDeleteArray( this->ownedArray ); - this->ownedArray = assignedArray; - } - template UniqueArray & UniqueArray::operator = ( const UniqueArray &donor ) { diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index cdceb894..abda0af5 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -1,7 +1,11 @@ -//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//! +///////////////////////////////////////////////////////////////////// // Utility Collection of Miscellanious Handy Functions -// © Dan Andersson 2013 -//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//! +// +// Created 2013 by Dan Andersson +// Edited 2013 by +// * Dan Andersson +// * Dennis Andersen +///////////////////////////////////////////////////////////////////// #ifndef UTILITIES_H #define UTILITIES_H @@ -27,12 +31,9 @@ namespace Utility template struct UniquePointer { public: - //! Creates an empty UniquePointer. - //UniquePointer(); - //! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. - UniquePointer( Type *assignedInstance = NULL ); + UniquePointer( Type *assignedInstance = NULL ); //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. //! If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. @@ -41,10 +42,6 @@ namespace Utility //! Will auto delete assigned dynamic instance. ~UniquePointer(); - //! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. - //! If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. - UniquePointer & operator = ( Type *assignedInstance ); // potential ambiguous - //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. //! If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. UniquePointer & operator = ( const UniquePointer &donor ); @@ -84,9 +81,6 @@ namespace Utility struct UniqueArray { //! Wrapper to safely transfer dynamic ownership/responsibility public: - //! Creates an empty UniqueArray. - //UniqueArray(); - //! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. //! If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. UniqueArray( Type assignedArray[] = NULL ); @@ -97,10 +91,6 @@ namespace Utility //! Will auto delete assigned dynamic array. ~UniqueArray(); - - //! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. - //! If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. - UniqueArray & operator = ( Type assignedArray[] ); // potential ambiguous //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. //! If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. From 9d92b292d91bd7721bf05a0a486126ea6de0a8ea Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 16:18:20 +0100 Subject: [PATCH 3/3] Improved documentation of UniquePointer and UniqueArray --- Code/Misc/Utilities.h | 122 ++++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 34 deletions(-) diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index abda0af5..6f5cf3ab 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -21,56 +21,87 @@ namespace Utility { namespace DynamicMemory { - //! If dynamicInstance is not NULL, then delete + /****************************************************************** + * If dynamicInstance is not NULL, then delete. + ******************************************************************/ template void SafeDeleteInstance( Type *dynamicInstance ); - //! If dynamicArray is not NULL, then delete [] + /****************************************************************** + * If dynamicArray is not NULL, then delete []. + ******************************************************************/ template void SafeDeleteArray( Type dynamicArray[] ); //! Wrapper to safely transfer dynamic ownership/responsibility template struct UniquePointer { public: - //! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. - //! If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. + /****************************************************************** + * Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted. + * If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer. + ******************************************************************/ UniquePointer( Type *assignedInstance = NULL ); - //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. - //! If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. + /****************************************************************** + * Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. + * If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. + ******************************************************************/ UniquePointer( const UniquePointer &donor ); - //! Will auto delete assigned dynamic instance. + /****************************************************************** + * Will auto delete assigned dynamic instance. + ******************************************************************/ ~UniquePointer(); - //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. - //! If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. + /****************************************************************** + * Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted. + * If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer. + ******************************************************************/ UniquePointer & operator = ( const UniquePointer &donor ); - //! Access the assigned dynamic instance. Will crash if nothing there + /****************************************************************** + * Access the assigned dynamic instance. Will crash if nothing there + ******************************************************************/ operator Type* (); - //! Access the assigned dynamic instance. Will crash if nothing there + /****************************************************************** + * Access the assigned dynamic instance. Will crash if nothing there + ******************************************************************/ operator const Type* () const; - //! Access members of the assigned dynamic instance. Will crash if nothing there + /****************************************************************** + * Access members of the assigned dynamic instance. Will crash if nothing there + ******************************************************************/ Type * operator -> (); - //! Access members of the assigned dynamic instance. Will crash if nothing there + /****************************************************************** + * Access members of the assigned dynamic instance. Will crash if nothing there + ******************************************************************/ const Type * operator -> () const; - //! If true, this UniquePointer have a current ownership/responsibility of a dynamic instance. + /****************************************************************** + * @return true if this UniquePointer have a current ownership/responsibility of a dynamic instance. + ******************************************************************/ operator bool () const; - //! @return true if this ownedInstance matches with stray + /****************************************************************** + * @return true if this ownedInstance matches with stray + ******************************************************************/ bool operator == ( Type *stray ) const; - //! @return false if this ownedInstance matches with stray + /****************************************************************** + * @return false if this ownedInstance matches with stray + ******************************************************************/ bool operator != ( Type *stray ) const; - //! This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete. + /****************************************************************** + * This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete. + ******************************************************************/ Type* Release(); - //! (inline) If true, this UniquePointer have a current ownership/responsibility of a dynamic instance. + /****************************************************************** + * @return true if this UniquePointer have a current ownership/responsibility of a dynamic instance. + * inline of @see operator bool () const + ******************************************************************/ bool HaveOwnership() const; private: @@ -81,42 +112,65 @@ namespace Utility struct UniqueArray { //! Wrapper to safely transfer dynamic ownership/responsibility public: - //! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. - //! If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. + /****************************************************************** + * Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted. + * If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray. + ******************************************************************/ UniqueArray( Type assignedArray[] = NULL ); - //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. - //! If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. + /****************************************************************** + * Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. + * If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. + ******************************************************************/ UniqueArray( const UniqueArray &donor ); - //! Will auto delete assigned dynamic array. + /****************************************************************** + * Will auto delete assigned dynamic array. + ******************************************************************/ ~UniqueArray(); - //! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. - //! If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. + /****************************************************************** + * Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted. + * If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray. + ******************************************************************/ UniqueArray & operator = ( const UniqueArray &donor ); - //! Accesses the instance at index i of this UniqeArray's owned dynamic array. - //! Will crash if out-of-bound or there is no assigned array. + /****************************************************************** + * Accesses the instance at index i of this UniqeArray's owned dynamic array. + * Will crash if out-of-bound or there is no assigned array. + ******************************************************************/ template Type & operator [] ( Index i ); - //! Accesses the instance at index i of this UniqeArray's owned dynamic array. - //! Will crash if out-of-bound or there is no assigned array. + /****************************************************************** + * Accesses the instance at index i of this UniqeArray's owned dynamic array. + * Will crash if out-of-bound or there is no assigned array. + ******************************************************************/ template const Type & operator [] ( Index i ) const; - //! If true, this UniqueArray have a current ownership/responsibility of a dynamic instance. + /****************************************************************** + * @return true if this UniqueArray have a current ownership/responsibility of a dynamic array. + ******************************************************************/ operator bool () const; - //! @return true if this ownedInstance matches with stray + /****************************************************************** + * @return true if this ownedInstance matches with stray. + ******************************************************************/ bool operator == ( Type *stray ) const; - //! @return false if this ownedInstance matches with stray + /****************************************************************** + * @return false if this ownedInstance matches with stray. + ******************************************************************/ bool operator != ( Type *stray ) const; - //! This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete. + /****************************************************************** + * This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete. + ******************************************************************/ Type* Release(); - //! (inline) If true, this UniqueArray have a current ownership/responsibility of a dynamic array. + /****************************************************************** + * @return true if this UniqueArray have a current ownership/responsibility of a dynamic array. + * inline of @see operator bool () const + ******************************************************************/ bool HaveOwnership() const; private: