traceservices/tracefw/ulogger/inc/uloggertools.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // ULogger plug-in base class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21  @prototype
       
    22 */
       
    23 
       
    24 #ifndef __ULOGGERTOOLS_H__
       
    25 #define __ULOGGERTOOLS_H__
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <s32mem.h>
       
    29 
       
    30 namespace Ulogger
       
    31 {
       
    32 
       
    33 //utility templates
       
    34 /*!Externilize T array to HBufC8 stream.
       
    35 This is for internal use only.
       
    36 */
       
    37 template<class T> HBufC8* ExternalizeToBufL(const T& aArray, TInt aElementSize)
       
    38 	{
       
    39 	CBufFlat* buf = CBufFlat::NewL(1 + aArray.Count()*aElementSize);
       
    40 	CleanupStack::PushL(buf);
       
    41 	RBufWriteStream stream(*buf);
       
    42 	CleanupClosePushL(stream);
       
    43 
       
    44 	for (TInt i=0; i<aArray.Count(); ++i)
       
    45 		stream << aArray[i];
       
    46 
       
    47 	CleanupStack::PopAndDestroy(&stream); //close
       
    48 	
       
    49 	HBufC8* des = HBufC8::NewL(buf->Size());
       
    50 	TPtr8 ptr(des->Des());
       
    51 	buf->Read(0, ptr, buf->Size());
       
    52 
       
    53 	CleanupStack::PopAndDestroy(buf);
       
    54 	return des;
       
    55 	}	
       
    56 	
       
    57 	
       
    58 	
       
    59 /*!Internalize stream to array.
       
    60 This is for internal use only.
       
    61 */
       
    62 
       
    63 template<class T, class T2> void InternalizeFromBufL(const TDesC8& aBuf, T& aArray, T2 aArrayMember)
       
    64 	{
       
    65 	TInt elements = (TInt)aBuf.Length()/sizeof(T2);
       
    66 	RDesReadStream stream(aBuf);
       
    67 	CleanupClosePushL(stream);
       
    68 	for(TInt i=0; i<elements; ++i)
       
    69 		{
       
    70 		stream >> aArrayMember;
       
    71 		aArray.AppendL(aArrayMember);
       
    72 		}
       
    73 	CleanupStack::PopAndDestroy(&stream); //close
       
    74 	}
       
    75 
       
    76 void ResetAndDestroyPtrArray(TAny* aPtr)
       
    77 	{
       
    78 	(STATIC_CAST(RPointerArray<HBufC>*,aPtr))->ResetAndDestroy();
       
    79 	(STATIC_CAST(RPointerArray<HBufC>*,aPtr))->Close();
       
    80 	}
       
    81 
       
    82 }
       
    83 
       
    84 #endif //__ULOGGERTOOLS_H__