Merge after pull from misc branch

This commit is contained in:
dean11 2013-11-28 23:22:50 +01:00
commit a3ae340a30
4 changed files with 122 additions and 66 deletions

View File

@ -152,6 +152,7 @@
<ClCompile Include="Resource\OResource.cpp" /> <ClCompile Include="Resource\OResource.cpp" />
<ClCompile Include="Thread\OysterMutex.cpp" /> <ClCompile Include="Thread\OysterMutex.cpp" />
<ClCompile Include="Thread\OysterThread_Impl.cpp" /> <ClCompile Include="Thread\OysterThread_Impl.cpp" />
<ClCompile Include="Thread\OysterThread_Impl.cpp" />
<ClCompile Include="Utilities.cpp" /> <ClCompile Include="Utilities.cpp" />
<ClCompile Include="WinTimer.cpp" /> <ClCompile Include="WinTimer.cpp" />
</ItemGroup> </ItemGroup>
@ -161,7 +162,8 @@
<ClInclude Include="Thread\IThreadObject.h" /> <ClInclude Include="Thread\IThreadObject.h" />
<ClInclude Include="Thread\OysterMutex.h" /> <ClInclude Include="Thread\OysterMutex.h" />
<ClInclude Include="Thread\OysterThread.h" /> <ClInclude Include="Thread\OysterThread.h" />
<ClInclude Include="Utilities-InlineImpl.h" /> <ClInclude Include="Thread\OysterThread.h" />
<ClInclude Include="Utilities-Impl.h" />
<ClInclude Include="Utilities.h" /> <ClInclude Include="Utilities.h" />
<ClInclude Include="WinTimer.h" /> <ClInclude Include="WinTimer.h" />
</ItemGroup> </ItemGroup>

View File

@ -27,6 +27,12 @@
<ClCompile Include="Resource\OResourceHandler.cpp"> <ClCompile Include="Resource\OResourceHandler.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Thread\OysterMutex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Thread\OysterThread_Impl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Resource\Loaders\ByteLoader.cpp"> <ClCompile Include="Resource\Loaders\ByteLoader.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@ -47,13 +53,22 @@
<ClInclude Include="WinTimer.h"> <ClInclude Include="WinTimer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Utilities-InlineImpl.h"> <ClInclude Include="Utilities-Impl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource\OResource.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Resource\OysterResource.h"> <ClInclude Include="Resource\OysterResource.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Resource\OResource.h"> <ClInclude Include="Thread\IThreadObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Thread\OysterMutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Thread\OysterThread.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Thread\IThreadObject.h"> <ClInclude Include="Thread\IThreadObject.h">

View File

@ -1,7 +1,11 @@
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// Inline and template implementations for // Inline and template implementations for
// the Utility Collection of Miscellanious Handy Functions // 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 #ifndef UTILITIES_INLINE_IMPL_H
@ -51,14 +55,6 @@ namespace Utility
SafeDeleteInstance( this->ownedInstance ); SafeDeleteInstance( this->ownedInstance );
} }
template<typename Type>
UniquePointer<Type> & UniquePointer<Type>::operator = ( Type *assignedInstance )
{
SafeDeleteInstance( this->ownedInstance );
this->ownedInstance = assignedInstance;
return *this;
}
template<typename Type> template<typename Type>
UniquePointer<Type> & UniquePointer<Type>::operator = ( const UniquePointer<Type> &donor ) UniquePointer<Type> & UniquePointer<Type>::operator = ( const UniquePointer<Type> &donor )
{ {
@ -144,13 +140,6 @@ namespace Utility
SafeDeleteArray( this->ownedArray ); SafeDeleteArray( this->ownedArray );
} }
template<typename Type>
UniqueArray<Type> & UniqueArray<Type>::operator = ( Type assignedArray[] )
{
SafeDeleteArray( this->ownedArray );
this->ownedArray = assignedArray;
}
template<typename Type> template<typename Type>
UniqueArray<Type> & UniqueArray<Type>::operator = ( const UniqueArray<Type> &donor ) UniqueArray<Type> & UniqueArray<Type>::operator = ( const UniqueArray<Type> &donor )
{ {

View File

@ -1,7 +1,11 @@
//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//! /////////////////////////////////////////////////////////////////////
// Utility Collection of Miscellanious Handy Functions // Utility Collection of Miscellanious Handy Functions
// © Dan Andersson 2013 //
//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//! // Created 2013 by Dan Andersson
// Edited 2013 by
// * Dan Andersson
// * Dennis Andersen
/////////////////////////////////////////////////////////////////////
#ifndef UTILITIES_H #ifndef UTILITIES_H
#define UTILITIES_H #define UTILITIES_H
@ -17,60 +21,87 @@ namespace Utility
{ {
namespace DynamicMemory namespace DynamicMemory
{ {
//! If dynamicInstance is not NULL, then delete /******************************************************************
* If dynamicInstance is not NULL, then delete.
******************************************************************/
template<typename Type> void SafeDeleteInstance( Type *dynamicInstance ); template<typename Type> void SafeDeleteInstance( Type *dynamicInstance );
//! If dynamicArray is not NULL, then delete [] /******************************************************************
* If dynamicArray is not NULL, then delete [].
******************************************************************/
template<typename Type> void SafeDeleteArray( Type dynamicArray[] ); template<typename Type> void SafeDeleteArray( Type dynamicArray[] );
//! Wrapper to safely transfer dynamic ownership/responsibility //! Wrapper to safely transfer dynamic ownership/responsibility
template<typename Type> struct UniquePointer template<typename Type> struct UniquePointer
{ {
public: 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.
UniquePointer( Type *assignedInstance = NULL ); * 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<Type> &donor ); UniquePointer( const UniquePointer<Type> &donor );
//! Will auto delete assigned dynamic instance. /******************************************************************
* Will auto delete assigned dynamic instance.
******************************************************************/
~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. * Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
UniquePointer<Type> & operator = ( Type *assignedInstance ); * 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<Type> & operator = ( const UniquePointer<Type> &donor ); UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor );
//! Access the assigned dynamic instance. Will crash if nothing there /******************************************************************
* Access the assigned dynamic instance. Will crash if nothing there
******************************************************************/
operator Type* (); 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; 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 -> (); 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; 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; operator bool () const;
//! @return true if this ownedInstance matches with stray /******************************************************************
* @return true if this ownedInstance matches with stray
******************************************************************/
bool operator == ( Type *stray ) const; 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; 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(); 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; bool HaveOwnership() const;
private: private:
@ -81,46 +112,65 @@ namespace Utility
struct UniqueArray struct UniqueArray
{ //! Wrapper to safely transfer dynamic ownership/responsibility { //! Wrapper to safely transfer dynamic ownership/responsibility
public: 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 ); 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<Type> &donor ); UniqueArray( const UniqueArray<Type> &donor );
//! Will auto delete assigned dynamic array. /******************************************************************
* Will auto delete assigned dynamic array.
******************************************************************/
~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> & operator = ( Type assignedArray[] );
//! 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<Type> & operator = ( const UniqueArray<Type> &donor ); UniqueArray<Type> & operator = ( const UniqueArray<Type> &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<typename Index> Type & operator [] ( Index i ); template<typename Index> 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<typename Index> const Type & operator [] ( Index i ) const; template<typename Index> 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; operator bool () const;
//! @return true if this ownedInstance matches with stray /******************************************************************
* @return true if this ownedInstance matches with stray.
******************************************************************/
bool operator == ( Type *stray ) const; 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; 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(); 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; bool HaveOwnership() const;
private: private:
@ -331,6 +381,6 @@ namespace Utility
} }
} }
#include "Utilities-InlineImpl.h" #include "Utilities-Impl.h"
#endif #endif