phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CVPbkSimContactBuf.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  A read-only sim contact buffer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CVPbkSimContactBuf.h"
       
    22 
       
    23 #include "VPbkSimStoreTemplateFunctions.h"
       
    24 #include "CVPbkSimCntField.h"
       
    25 #include "MVPbkSimCntStore.h"
       
    26 #include "VPbkSimStoreImplError.h"
       
    27 #include "CVPbkETelCntConverter.h"
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CVPbkSimContactBuf::CVPbkSimContactBuf
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CVPbkSimContactBuf::CVPbkSimContactBuf( MVPbkSimCntStore& aSimStore )
       
    38 :   CVPbkSimContactBase( aSimStore )
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CVPbkSimContactBuf::ConstructL
       
    44 // Symbian 2nd phase constructor can leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CVPbkSimContactBuf::ConstructL( const TDesC8* aETelContact )
       
    48     {
       
    49     if ( aETelContact )
       
    50         {
       
    51         iData = aETelContact->AllocL();
       
    52         }
       
    53     iCurrentField = CVPbkSimCntField::NewL( EVPbkSimUnknownType, *this );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CVPbkSimContactBuf::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CVPbkSimContactBuf* CVPbkSimContactBuf::NewL( 
       
    62     const TDesC8& aETelContact, MVPbkSimCntStore& aSimStore )
       
    63     {
       
    64     CVPbkSimContactBuf* self = NewLC( aETelContact, aSimStore );
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVPbkSimContactBuf::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CVPbkSimContactBuf* CVPbkSimContactBuf::NewL( 
       
    75     MVPbkSimCntStore& aSimStore )
       
    76     {
       
    77     CVPbkSimContactBuf* self = NewLC( aSimStore );
       
    78     CleanupStack::Pop();
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CVPbkSimContactBuf::NewLC
       
    84 // Two-phased constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CVPbkSimContactBuf* CVPbkSimContactBuf::NewLC( 
       
    88     const TDesC8& aETelContact, MVPbkSimCntStore& aSimStore )
       
    89     {
       
    90     CVPbkSimContactBuf* self = new( ELeave ) CVPbkSimContactBuf( aSimStore );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL( &aETelContact );
       
    93     return self;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CVPbkSimContactBuf::NewLC
       
    98 // Two-phased constructor.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C CVPbkSimContactBuf* CVPbkSimContactBuf::NewLC( 
       
   102     MVPbkSimCntStore& aSimStore )
       
   103     {
       
   104     CVPbkSimContactBuf* self = new( ELeave ) CVPbkSimContactBuf( aSimStore );
       
   105     CleanupStack::PushL( self );
       
   106     self->ConstructL( NULL );
       
   107     return self;
       
   108     }
       
   109 
       
   110 // Destructor
       
   111 CVPbkSimContactBuf::~CVPbkSimContactBuf()
       
   112     {
       
   113     delete iData;
       
   114     delete iCurrentField;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CVPbkSimContactBuf::ConstFieldAt
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 const CVPbkSimCntField& CVPbkSimContactBuf::ConstFieldAt( TInt aIndex ) const
       
   122     {
       
   123     if ( iData )
       
   124         {
       
   125         TPtr8 ptr( iData->Des() );
       
   126         iStore.ContactConverter().FieldAt( ptr, aIndex, *iCurrentField );
       
   127         }
       
   128     return *iCurrentField;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CVPbkSimContactBuf::FieldAt
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CVPbkSimContactBuf::FieldCount() const
       
   136     {
       
   137     if ( iData )
       
   138         {
       
   139         TPtr8 ptr( iData->Des() );
       
   140         TInt count = iStore.ContactConverter().FieldCount( ptr );
       
   141         __ASSERT_DEBUG( count >= 0, VPbkSimStoreImpl::Panic( 
       
   142             VPbkSimStoreImpl::EInvalidETelContactForFieldCount ) );
       
   143         return count;
       
   144         }
       
   145     // if data buffer is not allocated then there are no fields
       
   146     return 0;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CVPbkSimContactBuf::SimIndex
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 TInt CVPbkSimContactBuf::SimIndex() const
       
   154     {
       
   155     if ( iData )
       
   156         {
       
   157         TPtr8 ptr( iData->Des() );
       
   158         return iStore.ContactConverter().SimIndex( ptr );
       
   159         }
       
   160     return KVPbkSimStoreFirstFreeIndex;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CVPbkSimContactBuf::ETelContactL
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 const TDesC8& CVPbkSimContactBuf::ETelContactL() const
       
   168     {
       
   169     return *iData;
       
   170     }
       
   171   
       
   172 // -----------------------------------------------------------------------------
       
   173 // CVPbkSimContactBuf::SetL
       
   174 // -----------------------------------------------------------------------------
       
   175 // 
       
   176 void CVPbkSimContactBuf::SetL( const TDesC8& aETelContact )
       
   177     {
       
   178     TPtr8 ptr( NULL, 0 );
       
   179     VPbkSimStoreImpl::CheckAndUpdateBufferSizeL( iData, ptr, 
       
   180         aETelContact.Length() );
       
   181     ptr.Copy( aETelContact );
       
   182     }
       
   183 //  End of File