2013-11-13 12:07:21 +01:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Inline and template implementations for
|
|
|
|
|
// the Utility Collection of Miscellanious Handy Functions
|
|
|
|
|
// <20> Dan Andersson 2013
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#ifndef UTILITIES_INLINE_IMPL_H
|
|
|
|
|
#define UTILITIES_INLINE_IMPL_H
|
|
|
|
|
|
|
|
|
|
#include "Utilities.h"
|
|
|
|
|
|
|
|
|
|
namespace Utility
|
|
|
|
|
{
|
|
|
|
|
namespace DynamicMemory
|
|
|
|
|
{
|
|
|
|
|
template<typename Type>
|
|
|
|
|
inline void SafeDeleteInstance( Type *dynamicInstance )
|
|
|
|
|
{
|
|
|
|
|
if( dynamicInstance )
|
|
|
|
|
{
|
|
|
|
|
delete dynamicInstance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
void SafeDeleteArray( Type dynamicArray[] )
|
|
|
|
|
{
|
|
|
|
|
if( dynamicArray )
|
|
|
|
|
{
|
|
|
|
|
delete [] dynamicArray;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::UniquePointer( Type *assignedInstance )
|
|
|
|
|
{
|
|
|
|
|
this->ownedInstance = assignedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 09:16:51 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::UniquePointer( const UniquePointer<Type> &donor )
|
|
|
|
|
{
|
|
|
|
|
this->ownedInstance = donor.ownedInstance;
|
|
|
|
|
donor.ownedInstance = NULL;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 12:07:21 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::~UniquePointer()
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteInstance( this->ownedInstance );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type> & UniquePointer<Type>::operator = ( Type *assignedInstance )
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteInstance( this->ownedInstance );
|
|
|
|
|
this->ownedInstance = assignedInstance;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type> & UniquePointer<Type>::operator = ( const UniquePointer<Type> &donor )
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteInstance( this->ownedInstance );
|
|
|
|
|
this->ownedInstance = donor.ownedInstance;
|
|
|
|
|
donor.ownedInstance = NULL;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::operator Type* ()
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::operator const Type* () const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
Type * UniquePointer<Type>::operator -> ()
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
const Type * UniquePointer<Type>::operator -> () const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniquePointer<Type>::operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-28 11:15:25 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
bool UniquePointer<Type>::operator == ( Type *stray ) const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance == stray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
bool UniquePointer<Type>::operator != ( Type *stray ) const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedInstance != stray;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 12:07:21 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
Type* UniquePointer<Type>::Release()
|
|
|
|
|
{
|
|
|
|
|
Type *copy = this->ownedInstance;
|
|
|
|
|
this->ownedInstance = NULL;
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
inline bool UniquePointer<Type>::HaveOwnership() const
|
|
|
|
|
{
|
|
|
|
|
return this->operator bool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniqueArray<Type>::UniqueArray( Type assignedArray[] )
|
|
|
|
|
{
|
|
|
|
|
this->ownedArray = assignedArray;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 09:16:51 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
UniqueArray<Type>::UniqueArray( const UniqueArray<Type> &donor )
|
|
|
|
|
{
|
|
|
|
|
this->ownedArray = donor.ownedArray;
|
|
|
|
|
donor.ownedArray = NULL;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 12:07:21 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
UniqueArray<Type>::~UniqueArray()
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteArray( this->ownedArray );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniqueArray<Type> & UniqueArray<Type>::operator = ( Type assignedArray[] )
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteArray( this->ownedArray );
|
|
|
|
|
this->ownedArray = assignedArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
2013-11-13 14:48:24 +01:00
|
|
|
|
UniqueArray<Type> & UniqueArray<Type>::operator = ( const UniqueArray<Type> &donor )
|
2013-11-13 12:07:21 +01:00
|
|
|
|
{
|
|
|
|
|
SafeDeleteArray( this->ownedArray );
|
|
|
|
|
this->ownedArray = donor.ownedInstance;
|
|
|
|
|
donor.owned = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type> template<typename Index>
|
2013-11-13 14:48:24 +01:00
|
|
|
|
Type & UniqueArray<Type>::operator [] ( Index i )
|
2013-11-13 12:07:21 +01:00
|
|
|
|
{
|
|
|
|
|
return this->ownedArray[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type> template<typename Index>
|
2013-11-13 14:48:24 +01:00
|
|
|
|
const Type & UniqueArray<Type>::operator [] ( Index i ) const
|
2013-11-13 12:07:21 +01:00
|
|
|
|
{
|
|
|
|
|
return this->ownedArray[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
UniqueArray<Type>::operator bool () const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedArray != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-28 11:15:25 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
bool UniqueArray<Type>::operator == ( Type *stray ) const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedArray == stray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
bool UniqueArray<Type>::operator != ( Type *stray ) const
|
|
|
|
|
{
|
|
|
|
|
return this->ownedArray != stray;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 12:07:21 +01:00
|
|
|
|
template<typename Type>
|
|
|
|
|
Type* UniqueArray<Type>::Release()
|
|
|
|
|
{
|
|
|
|
|
Type *copy = this->ownedArray;
|
|
|
|
|
this->ownedArray = NULL;
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
|
inline bool UniqueArray<Type>::HaveOwnership() const
|
|
|
|
|
{
|
|
|
|
|
return this->operator bool();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|