ncdengine/engine/inc/catalogsrefstring.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-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:   Contains CCatalogsRefString
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CATALOGSREFSTRING_H
       
    20 #define C_CATALOGSREFSTRING_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "catalogsreferencebase.h"
       
    24 
       
    25 class CCatalogsRefString : public CCatalogsReferenceBase<CBase>
       
    26     {
       
    27 public:
       
    28 
       
    29     static TInt Order( 
       
    30         const CCatalogsRefString& aFirst,
       
    31         const CCatalogsRefString& aSecond ) 
       
    32         {
       
    33         return aFirst.String().Compare( aSecond.String() );        
       
    34         }
       
    35 
       
    36 public:
       
    37     
       
    38     /**
       
    39      * Creates a new CCatalogsRefString
       
    40      *
       
    41      * @param aString Ownership is transferred. If a leave occurs, aString is
       
    42      * delete automatically so it MUST NOT be in cleanupstack
       
    43      */
       
    44     static CCatalogsRefString* NewLC( HBufC* aString )
       
    45         {
       
    46         // This ensures that aString is deleted if new( ELeave ) leaves
       
    47         CleanupStack::PushL( aString );
       
    48         CCatalogsRefString* self = new( ELeave ) CCatalogsRefString( aString );
       
    49         CleanupStack::Pop( aString );
       
    50         CleanupReleasePushL( *self );    
       
    51         return self;
       
    52         }
       
    53         
       
    54     virtual const TDesC& String() const 
       
    55         {
       
    56         return *iString;
       
    57         }
       
    58         
       
    59     operator const TDesC&() const 
       
    60         {
       
    61         return *iString;
       
    62         }
       
    63         
       
    64 protected:
       
    65 
       
    66     CCatalogsRefString( HBufC* aString ) : iString( aString )
       
    67         {
       
    68         }
       
    69     
       
    70     virtual ~CCatalogsRefString() 
       
    71         {
       
    72         delete iString;
       
    73         }
       
    74 
       
    75 private:
       
    76 
       
    77     CCatalogsRefString( const CCatalogsRefString& );
       
    78     CCatalogsRefString& operator=( const CCatalogsRefString& );
       
    79     
       
    80 private:
       
    81 
       
    82     HBufC* iString;        
       
    83     };
       
    84 
       
    85 
       
    86 /**
       
    87  * One ugly trick
       
    88  *
       
    89  * Used for searching in arrays without need to create a copy of the
       
    90  * search string
       
    91  */
       
    92 class CCatalogsRefSearchString : public CCatalogsRefString
       
    93     {
       
    94 public:
       
    95 
       
    96     explicit CCatalogsRefSearchString( const TDesC& aString ) :
       
    97         CCatalogsRefString( NULL ),
       
    98         iSearchString( &aString )
       
    99         {
       
   100         }
       
   101 
       
   102     const TDesC& String() const 
       
   103         {
       
   104         return *iSearchString;
       
   105         }
       
   106 
       
   107     void SetString( const TDesC& aString ) 
       
   108         {
       
   109         iSearchString = &aString;
       
   110         }
       
   111         
       
   112     ~CCatalogsRefSearchString() 
       
   113         {
       
   114         }
       
   115         
       
   116 private:
       
   117         
       
   118     const TDesC* iSearchString;
       
   119     };
       
   120 
       
   121     
       
   122 #endif // C_CATALOGSREFSTRING_H
       
   123