diff -r 000000000000 -r 4e91876724a2 photosgallery/slideshow/utils/shwautoptr.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/photosgallery/slideshow/utils/shwautoptr.h Thu Dec 17 08:45:44 2009 +0200 @@ -0,0 +1,141 @@ +/* +* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Thin callback wrapper + * +*/ + + + + +// include guard for the whole file content +#ifndef __SHWAUTOPTR_H__ +#define __SHWAUTOPTR_H__ + +/** + * TShwAutoPtr, implementation of auto_ptr + */ +template< class T > +class TShwAutoPtr + { + public: + + /** + * Default constructor + */ + TShwAutoPtr() + : iPtr( NULL ) + {} + + /** + * Constructor + * @param aPtr the pointer to own + */ + TShwAutoPtr( T* aPtr = 0 ) + : iPtr( aPtr ) + {} + + /** + * Copy constructor, transfers ownership + * @param aPtr the pointer to transfer + */ + TShwAutoPtr( TShwAutoPtr< T >& aPtr ) + : iPtr( aPtr.Release() ) + {} + + /** + * Destructor, releases the pointer + */ + ~TShwAutoPtr() + { + delete iPtr; + } + + /** + * Dereference + */ + T& operator*() const + { + return *iPtr; + } + + /** + * Take address of pointed class + */ + T* operator &() + { + return iPtr; + } + + /** + * Dereference + */ + T* operator->() const + { + return iPtr; + } + + /** + * Gives the pointer to the caller, ownership stays + * @return the pointer held, ownership does not transfer + */ + T* Pointer() const + { + return iPtr; + } + + /** + * Assignment from one pointer to another, ownership transfers + * @param the auto pointer to hold + * @return reference to this so that assignments can be chained + */ + TShwAutoPtr& operator=( TShwAutoPtr& aCopy ) + { + if( this != &aCopy ) + { + // transfer the pointer + SetPointer( aCopy.Release() ); + } + return *this; + } + + /** + * Sets the pointer, ownership is taken + * @param the pointer to hold + */ + void SetPointer( T* aPointer ) + { + // release the old (possible) pointer + delete iPtr; + iPtr = aPointer; + } + + /** + * Release, returns the ownership to the caller + * @return the pointer held, ownership transfers + */ + T* Release() + { + T* temp = iPtr; + iPtr = 0; + return temp; + } + + private: + + /// Own: the pointer to hold + T* iPtr; + + }; + +#endif // __SHWAUTOPTR_H__