mpx/commonframework/common/src/mpxfixedarray.cpp
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 #include "mpxfixedarray.h"
       
    19 #include "mpxheapmanager.h"
       
    20 
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // RMPXFixedArrayBase::RMPXFixedArrayBase
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 RMPXFixedArrayBase::RMPXFixedArrayBase()
       
    27     {    
       
    28     }
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // RMPXFixedArrayBase::RMPXFixedArrayBase
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 RMPXFixedArrayBase::RMPXFixedArrayBase(const RMPXFixedArrayBase& aArray)
       
    35      : iCount(0),iDataOffset(0),iElementSize(aArray.iElementSize)
       
    36     {     
       
    37     (void)Copy(RMPXHeapManager::ClientHandle(),aArray);
       
    38     }
       
    39     
       
    40 // -----------------------------------------------------------------------------
       
    41 // RMPXFixedArrayBase::Set
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 TInt RMPXFixedArrayBase::Copy(TUint aClientHandle,const RMPXFixedArrayBase& aArray)
       
    45     {  
       
    46     MPX_ASSERT(aArray.iElementSize&&aArray.iCount&&aArray.iDataOffset&&aClientHandle);  
       
    47     // 
       
    48     Reset(aClientHandle); // Clears any current values
       
    49     TInt size=aArray.iElementSize*aArray.iCount;
       
    50     RMPXHeapManager& m=RMPXHeapManager::HeapManager(aClientHandle);
       
    51     TInt r=m.Copy(aClientHandle,aArray.iDataOffset,size);    
       
    52     if (r>0) // Its an offset
       
    53         {
       
    54         iDataOffset=r;
       
    55         iCount=aArray.iCount;
       
    56         iElementSize=aArray.iElementSize; 
       
    57         }
       
    58     // else the members are zero from Reset()
       
    59     return iDataOffset?KErrNone:KErrNoMemory; 
       
    60     }    
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // RMPXFixedArrayBase::RMPXFixedArrayBase
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 RMPXFixedArrayBase::RMPXFixedArrayBase(TInt aElementSize)
       
    67     : iCount(0),iDataOffset(0),iElementSize(aElementSize)
       
    68     {    
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // RMPXFixedArrayBase::Reset
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void RMPXFixedArrayBase::Reset(TUint aClientHandle)
       
    76     {
       
    77     if (iDataOffset)
       
    78         {
       
    79         TAny* buf=RMPXHeapManager::Ptr<TAny>(aClientHandle,iDataOffset);
       
    80         RMPXHeapManager::HeapManager(aClientHandle).Free(aClientHandle,buf);
       
    81         iDataOffset=0;
       
    82         iCount=0;
       
    83         }
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // RMPXFixedArrayBase::Alloc
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TAny* RMPXFixedArrayBase::Alloc(TUint aClientHandle,TInt aCount)
       
    91     {
       
    92     Reset(aClientHandle); // Clear previous values
       
    93     TInt size=iElementSize*aCount;
       
    94     TAny* ptr=RMPXHeapManager::HeapManager(aClientHandle).Alloc(aClientHandle,size);
       
    95     if (ptr)
       
    96         {
       
    97         iDataOffset=RMPXHeapManager::Offset(aClientHandle,ptr);
       
    98         iCount=aCount;
       
    99         }    
       
   100     return ptr;
       
   101     }
       
   102 
       
   103 // End of file