ncdengine/engine/src/catalogskeyvaluepair.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 #include <utf.h>
       
    21 
       
    22 #include "catalogskeyvaluepair.h"
       
    23 #include "catalogsutils.h"
       
    24 #include "catalogsdebug.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Creator
       
    30 // ---------------------------------------------------------------------------
       
    31 //	
       
    32 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewL( const TDesC16& aKey, 
       
    33     const TDesC16& aValue )
       
    34     {
       
    35     CCatalogsKeyValuePair* self = NewLC( aKey, aValue );
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Creator
       
    43 // ---------------------------------------------------------------------------
       
    44 //	
       
    45 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewLC( const TDesC16& aKey, 
       
    46     const TDesC16& aValue )
       
    47     {
       
    48     CCatalogsKeyValuePair* self = new ( ELeave ) CCatalogsKeyValuePair();
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL( aKey, aValue );
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Creator
       
    58 // ---------------------------------------------------------------------------
       
    59 //	
       
    60 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewL( const TDesC8& aKey, 
       
    61     const TDesC8& aValue )
       
    62     {
       
    63     CCatalogsKeyValuePair* self = NewLC( aKey, aValue );
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Creator
       
    71 // ---------------------------------------------------------------------------
       
    72 //	
       
    73 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewLC( const TDesC8& aKey, 
       
    74     const TDesC8& aValue )
       
    75     {
       
    76     CCatalogsKeyValuePair* self = new ( ELeave ) CCatalogsKeyValuePair();
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aKey, aValue );
       
    79 
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Copy creator
       
    86 // ---------------------------------------------------------------------------
       
    87 //	
       
    88 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewL( 
       
    89     const CCatalogsKeyValuePair& aOther )
       
    90     {
       
    91     CCatalogsKeyValuePair* self = NewLC( aOther );
       
    92     CleanupStack::Pop( self );
       
    93     return self;
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Copy creator
       
    99 // ---------------------------------------------------------------------------
       
   100 //	
       
   101 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewLC( 
       
   102     const CCatalogsKeyValuePair& aOther )
       
   103     {
       
   104     // Using normal constructor
       
   105     CCatalogsKeyValuePair* self = new ( ELeave ) CCatalogsKeyValuePair();
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL( aOther.Key(), aOther.Value() );
       
   108     return self;
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Creator
       
   114 // ---------------------------------------------------------------------------
       
   115 //	
       
   116 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewL( 
       
   117     RReadStream& aStream )
       
   118     {
       
   119     CCatalogsKeyValuePair* self = CCatalogsKeyValuePair::NewLC( aStream );
       
   120     CleanupStack::Pop( self );
       
   121     return self;    
       
   122     }
       
   123     
       
   124 // ---------------------------------------------------------------------------
       
   125 // Creator
       
   126 // ---------------------------------------------------------------------------
       
   127 //	
       
   128 CCatalogsKeyValuePair* CCatalogsKeyValuePair::NewLC( 
       
   129     RReadStream& aStream )
       
   130     {
       
   131     CCatalogsKeyValuePair* self = new ( ELeave ) CCatalogsKeyValuePair();
       
   132     CleanupStack::PushL( self );
       
   133     self->InternalizeL( aStream );
       
   134     return self;    
       
   135     }
       
   136     
       
   137     
       
   138 // ---------------------------------------------------------------------------
       
   139 // Constructor
       
   140 // ---------------------------------------------------------------------------
       
   141 //	
       
   142 CCatalogsKeyValuePair::CCatalogsKeyValuePair()
       
   143     {
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Destructor
       
   149 // ---------------------------------------------------------------------------
       
   150 //	
       
   151 CCatalogsKeyValuePair::~CCatalogsKeyValuePair()
       
   152     {
       
   153     delete iKey;
       
   154     delete iValue;    
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // 2nd phase constructor
       
   160 // ---------------------------------------------------------------------------
       
   161 //	
       
   162 void CCatalogsKeyValuePair::ConstructL( const TDesC16& aKey, 
       
   163     const TDesC16& aValue )
       
   164     {
       
   165     iKey = ConvertUnicodeToUtf8L( aKey );
       
   166     iValue = ConvertUnicodeToUtf8L( aValue );
       
   167     }
       
   168 
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // 2nd phase constructor
       
   172 // ---------------------------------------------------------------------------
       
   173 //	
       
   174 void CCatalogsKeyValuePair::ConstructL( const TDesC8& aKey, 
       
   175     const TDesC8& aValue )
       
   176     {
       
   177     iKey = aKey.AllocL();
       
   178     iValue = aValue.AllocL();    
       
   179     }
       
   180 
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Key getter
       
   184 // ---------------------------------------------------------------------------
       
   185 //	
       
   186 const TDesC8& CCatalogsKeyValuePair::Key() const
       
   187     {
       
   188     if ( iKey )
       
   189         {
       
   190         return *iKey;
       
   191         }
       
   192 
       
   193     return KNullDesC8;
       
   194     }
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // Value getter
       
   199 // ---------------------------------------------------------------------------
       
   200 //	
       
   201 const TDesC8& CCatalogsKeyValuePair::Value() const
       
   202     {
       
   203     if ( iValue )
       
   204         {
       
   205         return *iValue;
       
   206         }
       
   207 
       
   208     return KNullDesC8;
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Key getter
       
   214 // ---------------------------------------------------------------------------
       
   215 //	
       
   216 HBufC* CCatalogsKeyValuePair::KeyLC() const
       
   217     {    
       
   218     if( iKey ) 
       
   219         {            
       
   220         #ifdef _UNICODE
       
   221             HBufC* key = ConvertUtf8ToUnicodeL( *iKey );
       
   222             CleanupStack::PushL( key );
       
   223         #else
       
   224             HBufC* key = iKey->AllocLC();
       
   225         #endif
       
   226         
       
   227         return key;
       
   228         }
       
   229     return KNullDesC().AllocLC();
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // Key getter
       
   235 // ---------------------------------------------------------------------------
       
   236 //	
       
   237 HBufC* CCatalogsKeyValuePair::KeyL() const
       
   238     {    
       
   239     if( iKey ) 
       
   240         {            
       
   241         #ifdef _UNICODE
       
   242             HBufC* key = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *iKey );
       
   243         #else
       
   244             HBufC* key = iKey->AllocL();
       
   245         #endif
       
   246         
       
   247         return key;
       
   248         }
       
   249     return KNullDesC().AllocL();
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // Value getter
       
   255 // ---------------------------------------------------------------------------
       
   256 //	
       
   257 HBufC* CCatalogsKeyValuePair::ValueLC() const
       
   258     {
       
   259     if ( iValue )
       
   260         {
       
   261         #ifdef _UNICODE
       
   262             HBufC* value = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *iValue );
       
   263             CleanupStack::PushL( value );
       
   264         #else
       
   265             HBufC* value = iValue->AllocLC();
       
   266         #endif
       
   267         
       
   268         return value;
       
   269         }
       
   270 
       
   271     return KNullDesC().AllocLC();
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Value getter
       
   277 // ---------------------------------------------------------------------------
       
   278 //	
       
   279 HBufC* CCatalogsKeyValuePair::ValueL() const
       
   280     {
       
   281     if ( iValue )
       
   282         {
       
   283         #ifdef _UNICODE
       
   284             HBufC* value = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *iValue );
       
   285         #else
       
   286             HBufC* value = iValue->AllocL();
       
   287         #endif
       
   288         
       
   289         return value;
       
   290         }
       
   291 
       
   292     return KNullDesC().AllocL();
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // Matcher
       
   298 // ---------------------------------------------------------------------------
       
   299 //	
       
   300 TBool CCatalogsKeyValuePair::MatchByKey( const CCatalogsKeyValuePair& aFirst, 
       
   301     const CCatalogsKeyValuePair& aSecond )
       
   302     {
       
   303     return ( aFirst.Key().Compare( aSecond.Key() ) == 0 );
       
   304     }
       
   305 
       
   306 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // ExternalizeL
       
   310 // ---------------------------------------------------------------------------
       
   311 //	
       
   312 void CCatalogsKeyValuePair::ExternalizeL( RWriteStream& aStream ) const
       
   313     {
       
   314     ExternalizeDesL( *iKey, aStream );
       
   315     ExternalizeDesL( *iValue, aStream );
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // Internalize
       
   320 // ---------------------------------------------------------------------------
       
   321 //	
       
   322 void CCatalogsKeyValuePair::InternalizeL( RReadStream& aStream )
       
   323     {
       
   324     HBufC8* key = NULL;
       
   325     InternalizeDesL( key, aStream );
       
   326     CleanupStack::PushL( key );
       
   327     
       
   328     HBufC8* value = NULL;
       
   329     InternalizeDesL( value, aStream );
       
   330     
       
   331     CleanupStack::Pop( key );
       
   332     delete iKey;
       
   333     iKey = key;
       
   334     
       
   335     delete iValue;
       
   336     iValue = value;
       
   337     }