mpx/commonframework/common/inc/mpxfixedarray.inl
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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 "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:  Implementation of array of fixed size elements on global chunk
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // -----------------------------------------------------------------------------
       
    20 // RMPXFixedArrayBase::Close
       
    21 // -----------------------------------------------------------------------------
       
    22 //
       
    23 inline void RMPXFixedArrayBase::Close(TUint aClientHandle)
       
    24     {
       
    25     Reset(aClientHandle);
       
    26     }
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // RMPXFixedArrayBase::Buf
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 inline TAny* RMPXFixedArrayBase::Buf(TUint aClientHandle) const
       
    33     {
       
    34     return RMPXHeapManager::Ptr<TAny>(aClientHandle,iDataOffset);
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // RMPXFixedArrayBase::Count
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 inline TInt RMPXFixedArrayBase::Count() const
       
    42     {
       
    43     return iCount;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // RMPXFixedArray::RMPXFixedArray
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 template <class T>
       
    51 inline RMPXFixedArray<T>::RMPXFixedArray(const RMPXFixedArray<T>& aArray)
       
    52     : RMPXFixedArrayBase(aArray,sizeof(T))
       
    53     {      
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // RMPXFixedArray::RMPXFixedArray
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 template <class T>
       
    61 inline RMPXFixedArray<T>::RMPXFixedArray()
       
    62     : RMPXFixedArrayBase(sizeof(T))
       
    63     {    
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // RMPXFixedArray::Copy
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 template <class T>
       
    71 inline TInt RMPXFixedArray<T>::Copy(TUint aClientHandle,const TArray<T>& aArray)
       
    72     {   
       
    73     TInt n=aArray.Count();
       
    74     T* ptr=(T*)RMPXFixedArrayBase::Alloc(aClientHandle,n);
       
    75     if (ptr)
       
    76         {        
       
    77         for (TInt i=0;i<n;++i)
       
    78             {
       
    79             *ptr++=aArray[i];
       
    80             }
       
    81         }
       
    82     MPX_ASSERT(ptr);
       
    83     return ptr?KErrNone:KErrNoMemory; 
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // RMPXFixedArray::Array
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 template <class T>
       
    91 inline TArray<T> RMPXFixedArray<T>::Array(TUint aClientHandle) const
       
    92     {
       
    93     TInt thisOffset=RMPXHeapManager::Offset(aClientHandle,(TAny*)this);
       
    94     return TArray<T>(CountFunctionR,AtFunctionR,reinterpret_cast<const CBase*>(thisOffset));
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // RMPXFixedArray::CountFunctionR
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 template <class T>
       
   102 inline TInt RMPXFixedArray<T>::CountFunctionR(const CBase* aThis)
       
   103     {
       
   104     // Non-optimal, obtaining client handle every time count is accessed, however
       
   105     // there's no choice since the data could be shared by multiple threads and the
       
   106     // function signature does not allow the handle to be passed through
       
   107     //
       
   108     TInt offset=reinterpret_cast<TInt>(aThis);
       
   109     TInt ch=RMPXHeapManager::ClientHandle();    
       
   110     const RMPXFixedArrayBase* arr=RMPXHeapManager::Ptr<RMPXFixedArrayBase>(ch,offset);
       
   111     return arr->Count();
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // RMPXFixedArray::AtFunctionR
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 template <class T>
       
   119 inline const TAny* RMPXFixedArray<T>::AtFunctionR(const CBase* aThis,TInt aIndex)
       
   120     { 
       
   121     // Non-optimal, obtaining client handle every time data is accessed, however
       
   122     // there's no choice since the data could be shared by multiple threads and the
       
   123     // function signature does not allow the handle to be passed through
       
   124     //
       
   125     TInt offset=reinterpret_cast<TInt>(aThis);
       
   126     TInt ch=RMPXHeapManager::ClientHandle(); 
       
   127     const RMPXFixedArrayBase* arr=RMPXHeapManager::Ptr<RMPXFixedArrayBase>(ch,offset);   
       
   128     T* ptr=(T*)arr->Buf(ch);
       
   129     return &ptr[aIndex];
       
   130     }
       
   131 
       
   132 // End of file
       
   133