contentstorage/cautils/src/caentryattribute.cpp
changeset 85 7feec50967db
child 66 32469d7d46ff
equal deleted inserted replaced
4:1a2a00e78665 85:7feec50967db
       
     1 /*
       
     2  * Copyright (c) 2008 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: Definition of entry attribute
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <s32mem.h>
       
    20 #include "caarraycleanup.inl"
       
    21 #include "caentryattribute.h"
       
    22 
       
    23 // ================= MEMBER FUNCTIONS =======================
       
    24 
       
    25 // ---------------------------------------------------------
       
    26 // CCaEntryAttribute::~CMenuItemAttr
       
    27 // ---------------------------------------------------------
       
    28 //
       
    29 CCaEntryAttribute::~CCaEntryAttribute()
       
    30     {
       
    31     iName.Close();
       
    32     iValue.Close();
       
    33     }
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CCaEntryAttribute::NewL
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CCaEntryAttribute* CCaEntryAttribute::NewL( const TDesC& aName )
       
    40     {
       
    41     CCaEntryAttribute* attr = NewLC( aName );
       
    42     CleanupStack::Pop( attr );
       
    43     return attr;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CCaEntryAttribute::NewLC
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CCaEntryAttribute* CCaEntryAttribute::NewLC( const TDesC& aName )
       
    51     {
       
    52     CCaEntryAttribute* attr = new ( ELeave ) CCaEntryAttribute();
       
    53     CleanupStack::PushL( attr );
       
    54     attr->ConstructL( aName );
       
    55     return attr;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CCaEntryAttribute::ConstructL
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 void CCaEntryAttribute::ConstructL( const TDesC& aName )
       
    63     {
       
    64     iName.CreateL( aName );
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CCaEntryAttribute::ConstructL
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CCaEntryAttribute::SetValueL( const TDesC& aName )
       
    72     {
       
    73     if( iValue.Length() > 0 )
       
    74         {
       
    75         iValue.Close();
       
    76         }
       
    77     iValue.CreateL( aName );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CCaEntryAttribute::ExternalizeL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CCaEntryAttribute::ExternalizeL( RWriteStream& aStream ) const
       
    85     {
       
    86     aStream.WriteUint32L( iName.Length() );
       
    87     aStream.WriteL( iName, iName.Length() );
       
    88     aStream.WriteUint32L( iValue.Length() );
       
    89     aStream.WriteL( iValue, iValue.Length() );
       
    90     aStream.CommitL();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CCaEntryAttribute::InternalizeL
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CCaEntryAttribute::InternalizeL( RReadStream& aStream )
       
    98     {
       
    99     TUint length = aStream.ReadUint32L();
       
   100     iName.Close();
       
   101     iName.CreateL( length );
       
   102     aStream.ReadL( iName, length );
       
   103     length = aStream.ReadUint32L();
       
   104     iValue.Close();
       
   105     iValue.CreateL( length );
       
   106     aStream.ReadL( iValue, length );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // RMenuSrvAttrArray::Find
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TBool RCaEntryAttrArray::Find( const TDesC& aName, TDes& aAttrVal )
       
   114     {
       
   115     for( TInt i = 0; i < Count(); i++ )
       
   116         {
       
   117         if( aName.Compare( operator[]( i )->Name() ) == KErrNone )
       
   118             {
       
   119             aAttrVal = operator[]( i )->Value();
       
   120             return ETrue;
       
   121             }
       
   122         }
       
   123     return EFalse;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // RCaEntryAttrArray::Exist
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 EXPORT_C TBool RCaEntryAttrArray::Exist( const TDesC& aName )
       
   131     {
       
   132     for( TInt i = 0; i < Count(); i++ )
       
   133         {
       
   134         if( aName.Compare( operator[]( i )->Name() ) == KErrNone )
       
   135             {
       
   136             return ETrue;
       
   137             }
       
   138         }
       
   139     return EFalse;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // RCaEntryAttrArray::RemoveAttribute
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void RCaEntryAttrArray::RemoveAttribute( const TDesC& aAttrName )
       
   147     {
       
   148     for( TInt i = 0; i < Count(); i++ )
       
   149         {
       
   150         if( aAttrName == operator[]( i )->Name() )
       
   151             {
       
   152             delete operator[]( i );
       
   153             Remove( i );
       
   154             break;
       
   155             }
       
   156         }
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // RCaEntryAttrArray::ExternalizeL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void RCaEntryAttrArray::ExternalizeL( RWriteStream& aStream ) const
       
   164     {
       
   165     aStream.WriteUint16L( Count() );
       
   166     for( TInt i = 0; i < Count(); i++ )
       
   167         {
       
   168         operator[]( i )->ExternalizeL( aStream );
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // RCaEntryAttrArray::InternalizeL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void RCaEntryAttrArray::InternalizeL( RReadStream& aStream )
       
   177     {
       
   178     ResetAndDestroy();
       
   179     TUint count = aStream.ReadUint16L();
       
   180     for( TInt i = 0; i < count; i++ )
       
   181         {
       
   182         CCaEntryAttribute* attr = CCaEntryAttribute::NewLC( KNullDesC );
       
   183         attr->InternalizeL( aStream );
       
   184         AppendL( attr );
       
   185         CleanupStack::Pop( attr );
       
   186         }
       
   187     }
       
   188 
       
   189 //  End of File