installationservices/swi/source/sisregistry/common/arrayutils.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Utility functions for copying and streaming RArrays. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @internalTechnology
       
    23 */
       
    24 
       
    25 #ifndef __ARRAYUTILS_H_
       
    26 #define __ARRAYUTILS_H_
       
    27 
       
    28 #include <e32std.h>
       
    29 #include <s32strm.h>
       
    30 
       
    31 namespace Swi
       
    32 {
       
    33 	
       
    34 /////////////////////////////////////////////////////////////////////
       
    35 // RPointerArray utilities
       
    36 /////////////////////////////////////////////////////////////////////
       
    37 
       
    38 template <class T>
       
    39 void CopyPointerArrayL(RPointerArray<T>& aNew, const RPointerArray<T>& aOld);
       
    40 
       
    41 template <class T>
       
    42 void ExternalizePointerArrayL(const RPointerArray<T>& aArray, RWriteStream& aStream);
       
    43 
       
    44 template <class T>
       
    45 void InternalizePointerArrayL(RPointerArray<T>& aArray, RReadStream& aStream);
       
    46 
       
    47 /////////////////////////////////////////////////////////////////////
       
    48 // RArray utilities
       
    49 /////////////////////////////////////////////////////////////////////
       
    50 
       
    51 template <class T>
       
    52 void CopyArrayL(RArray<T>& aNew, const RArray<T>& aOld);
       
    53 
       
    54 template <class T>
       
    55 void ExternalizeArrayL(const RArray<T>& aArray, RWriteStream& aStream);
       
    56 
       
    57 template <class T>
       
    58 void InternalizeArrayL(RArray<T>& aArray, RReadStream& aStream);
       
    59 
       
    60 /////////////////////////////////////////////////////////////////////
       
    61 // Traits classes - internally required by RPointerArray functions
       
    62 /////////////////////////////////////////////////////////////////////
       
    63 
       
    64 template <class T>
       
    65 class TTraits
       
    66 	{
       
    67 public:
       
    68 	static T* CopyLC(const T& aOther) { return T::NewLC(aOther);}
       
    69 	static T* ReadFromStreamLC(RReadStream& aStream) { return T::NewLC(aStream); }
       
    70 	static void WriteToStreamL(const T& aItem, RWriteStream& aStream) { aStream << aItem; }
       
    71 	};
       
    72 
       
    73 // Specialisation for HBufs
       
    74 template <>
       
    75 class TTraits<HBufC16>
       
    76 	{
       
    77 public:
       
    78 	static HBufC16* CopyLC(const HBufC16& aOther) { return aOther.AllocLC();}
       
    79 	static HBufC16* ReadFromStreamLC(RReadStream& aStream) { return HBufC16::NewLC(aStream, KMaxTInt); }
       
    80 	static void WriteToStreamL(const HBufC16& aItem, RWriteStream& aStream) { aStream << aItem; }
       
    81 	};
       
    82 		
       
    83 template <>
       
    84 class TTraits<HBufC8>
       
    85 	{
       
    86 public:
       
    87 	static HBufC8* CopyLC(const HBufC8& aOther) { return aOther.AllocLC();}
       
    88 	static HBufC8* ReadFromStreamLC(RReadStream& aStream) { return HBufC8::NewLC(aStream, KMaxTInt); }
       
    89 	static void WriteToStreamL(const HBufC8& aItem, RWriteStream& aStream) { aStream << aItem; }
       
    90 	};
       
    91 
       
    92 #include "arrayutils.inl"
       
    93 } // namespace Swi
       
    94 #endif  // __ARRAYUTILS_H_