///////////////////////////////////////////////////////////////////// // Inline and template implementations for // the Utility Collection of Miscellanious Handy Functions // © Dan Andersson 2013 ///////////////////////////////////////////////////////////////////// #ifndef UTILITIES_INLINE_IMPL_H #define UTILITIES_INLINE_IMPL_H #include "Utilities.h" namespace Utility { namespace DynamicMemory { template inline void SafeDeleteInstance( Type *dynamicInstance ) { if( dynamicInstance ) { delete dynamicInstance; } } template void SafeDeleteArray( Type dynamicArray[] ) { if( dynamicArray ) { delete [] dynamicArray; } } template UniquePointer::UniquePointer( Type *assignedInstance ) { this->ownedInstance = assignedInstance; } template UniquePointer::~UniquePointer() { SafeDeleteInstance( this->ownedInstance ); } template UniquePointer & UniquePointer::operator = ( Type *assignedInstance ) { SafeDeleteInstance( this->ownedInstance ); this->ownedInstance = assignedInstance; return *this; } template UniquePointer & UniquePointer::operator = ( const UniquePointer &donor ) { SafeDeleteInstance( this->ownedInstance ); this->ownedInstance = donor.ownedInstance; donor.ownedInstance = NULL; return *this; } template UniquePointer::operator Type* () { return this->ownedInstance; } template UniquePointer::operator const Type* () const { return this->ownedInstance; } template Type * UniquePointer::operator -> () { return this->ownedInstance; } template const Type * UniquePointer::operator -> () const { return this->ownedInstance; } template UniquePointer::operator bool() const { return this->ownedInstance != NULL; } template Type* UniquePointer::Release() { Type *copy = this->ownedInstance; this->ownedInstance = NULL; return copy; } template inline bool UniquePointer::HaveOwnership() const { return this->operator bool(); } template UniqueArray::UniqueArray( Type assignedArray[] ) { this->ownedArray = assignedArray; } template UniqueArray::~UniqueArray() { SafeDeleteArray( this->ownedArray ); } template UniqueArray & UniqueArray::operator = ( Type assignedArray[] ) { SafeDeleteArray( this->ownedArray ); this->ownedArray = assignedArray; } template UniqueArray & UniqueArray::operator = ( const UniqueArray &donor ) { SafeDeleteArray( this->ownedArray ); this->ownedArray = donor.ownedInstance; donor.owned = NULL; } template template Type & UniqueArray::operator [] ( Index i ) { return this->ownedArray[i]; } template template const Type & UniqueArray::operator [] ( Index i ) const { return this->ownedArray[i]; } template UniqueArray::operator bool () const { return this->ownedArray != NULL; } template Type* UniqueArray::Release() { Type *copy = this->ownedArray; this->ownedArray = NULL; return copy; } template inline bool UniqueArray::HaveOwnership() const { return this->operator bool(); } } } #endif