diff -r 000000000000 -r ba25891c3a9e ncdengine/inc/catalogsutils.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ncdengine/inc/catalogsutils.inl Thu Dec 17 08:51:10 2009 +0200 @@ -0,0 +1,247 @@ +/* +* Copyright (c) 2006-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: Contains definition of catalogsutils functions +* +*/ + + +#include "catalogsdebug.h" + +// --------------------------------------------------------------------------- +// IntToDes16 +// 64-bit specialization is in catalogsutils.cpp +// --------------------------------------------------------------------------- +// +template +void IntToDes16( const T& aInt, TDes& aDes ) + { + DLTRACEIN(("aDes.MaxLength() = %d", aDes.MaxLength() )); + DASSERT( aDes.MaxLength() >= sizeof(T)/2 ); + *(( T* )aDes.Ptr()) = aInt; + } + + +// --------------------------------------------------------------------------- +// Des16ToInt +// 64-bit specialization is in catalogsutils.cpp +// --------------------------------------------------------------------------- +// +template +void Des16ToInt( const TDesC& aDes, T& aInt ) + { + DLTRACEIN(( _L("Des: %S"), &aDes )); + aInt = *(( T* )aDes.Ptr()); + DLTRACEOUT(( "Result: %d", aInt )); + } + + + + +// Template class CleanupResetAndDestroy +template +inline void CleanupResetAndDestroy::PushL(T& aRef) +/** +Creates a TCleanupItem for the specified object. + +The cleanup operation is the private static function Close() of this class. + +@param aRef The object for which a TCleanupItem is to be constructed. +*/ + {CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef));} + + + + +template +void CleanupResetAndDestroy::ResetAndDestroy(TAny *aPtr) +/** +The cleanup operation to be performed. + +@param aPtr A pointer to the object for which clean up is to be performed. + The implementation calls Close() on this object. +*/ + {(STATIC_CAST(T*,aPtr))->ResetAndDestroy();} + + + + +// See header file e32base.h for in-source comment. +template +inline void CleanupResetAndDestroyPushL(T& aRef) + {CleanupResetAndDestroy::PushL(aRef);} + + +// Template class CleanupInternalRelease +template +inline void CleanupInternalRelease::PushL(T& aRef) +/** +Creates a TCleanupItem for the specified object. + +The cleanup operation is the private static function Close() of this class. + +@param aRef The object for which a TCleanupItem is to be constructed. +*/ + {CleanupStack::PushL(TCleanupItem(&InternalRelease,&aRef));} + + +template +void CleanupInternalRelease::InternalRelease(TAny *aPtr) +/** +The cleanup operation to be performed. + +@param aPtr A pointer to the object for which clean up is to be performed. + The implementation calls Close() on this object. +*/ + {(STATIC_CAST(T*,aPtr))->InternalRelease();} + + +template +inline void CleanupInternalReleasePushL(T& aRef) + {CleanupInternalRelease::PushL(aRef);} + +template +void ResetAndCloseArray( RPointerArray& aArray ) + { + TInt count( aArray.Count() ); + while ( count-- ) + { + aArray[count]->Close(); + } + aArray.Reset(); + } + + +template +void ResetAndCloseArray( RArray& aArray ) + { + TInt count( aArray.Count() ); + while ( count-- ) + { + aArray[count].Close(); + } + aArray.Reset(); + } + + +template +void ResetAndDestroyWithCast( RPointerArray& aArray ) + { + TInt count = aArray.Count(); + for ( TInt i = 0; i < count; i++ ) + { + Casted* info = + static_cast( aArray[i] ); + delete info; + info = NULL; + } + aArray.Reset(); + } + + +template +void DeleteFromArray( RPointerArray& aArray, TInt aIndex ) + { + delete aArray[ aIndex ]; + aArray.Remove( aIndex ); + } + +template +void DeleteFromArray( RPointerArray& aArray, TInt aIndex ) + { + delete static_cast( aArray[ aIndex ] ); + aArray.Remove( aIndex ); + } + + +template +void InternalizeEnumL( EnumType& aTarget, RReadStream& aReadStream ) + { + aTarget = static_cast( aReadStream.ReadInt32L() ); + } + + +template +void ExternalizeEnumL( const EnumType& aSource, RWriteStream& aWriteStream ) + { + aWriteStream.WriteInt32L( aSource ); + } + + +template +TBool IsOneOf( + const T& aData, + const T& aComp1, + const T& aComp2 ) + { + return aData == aComp1 || + aData == aComp2; + } + + +template +TBool IsOneOf( + const T& aData, + const T& aComp1, + const T& aComp2, + const T& aComp3 ) + { + return IsOneOf( aData, aComp1, aComp2 ) || + aData == aComp3; + } + + +template +TBool IsOneOf( + const T& aData, + const T& aComp1, + const T& aComp2, + const T& aComp3, + const T& aComp4 ) + { + return aData == aComp1 || + aData == aComp2 || + aData == aComp3 || + aData == aComp4; + } + + +template +void ReleasePtr( T*& aObject ) + { + if ( aObject ) + { + aObject->Release(); + aObject = NULL; + } + } + + +template +void ClosePtr( T*& aObject ) + { + if ( aObject ) + { + aObject->Close(); + aObject = NULL; + } + } + + +template +void DeletePtr( T*& aObject ) + { + delete aObject; + aObject = NULL; + } +