photosgallery/collectionframework/datasource/manager/inc/glxstringcache.h
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    This class caches resource strings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef _GLXSTRINGCACHE_H_
       
    22 #define _GLXSTRINGCACHE_H_
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32cmn.h>
       
    26 #include <e32std.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 /**
       
    32  *  CGlxStringCache class 
       
    33  *
       
    34  *  This class caches resource strings.
       
    35  *  It maintains a mapping between the resource id and the string
       
    36  *  @author Rowland Cook
       
    37  */
       
    38 NONSHARABLE_CLASS(CGlxStringCache) : public CBase
       
    39     {
       
    40 public:
       
    41 	/** 
       
    42 	 * Two-phase constructor
       
    43 	*/
       
    44 	static IMPORT_C CGlxStringCache* NewL();	
       
    45     
       
    46 	/**
       
    47 	 * destructor
       
    48 	 */
       
    49     ~CGlxStringCache();    
       
    50 	
       
    51     /**
       
    52 	 * Loads a string from a resurce file
       
    53 	 *
       
    54 	 * @param aResourceFile - name of the resource file (does not contain the path).
       
    55 	 * @param aResourceId - Id of the string to be loaded
       
    56 	 * @return HBufC* containing the required string.
       
    57 	 */	
       
    58     IMPORT_C HBufC* LoadLocalizedStringLC(const TDesC& aResourceFile, const TInt aResourceId);
       
    59     
       
    60 private:
       
    61     /**
       
    62      *  CGlxStringItem class 
       
    63      *
       
    64      *  This class encapsulates a resource id and it's associated string.
       
    65      */
       
    66     NONSHARABLE_CLASS(CGlxStringItem) : public CBase
       
    67         {
       
    68     public:
       
    69     	/**
       
    70     	 * NewL
       
    71     	 * @param the resource id
       
    72     	 * @param the string
       
    73     	 * use this constructor prior to calling InsertL() (Above).
       
    74     	 */
       
    75         static CGlxStringItem* NewL(TInt aId, HBufC* aString);
       
    76         
       
    77     	/**
       
    78     	 * Constructor
       
    79     	 * @param the resource id
       
    80     	 * use this constructor directly to create a dummy class typically used before calling Find() (Above).
       
    81     	 */
       
    82         CGlxStringItem(TInt aId);
       
    83         
       
    84     	/**
       
    85     	 * destructor
       
    86     	 */
       
    87         ~CGlxStringItem();
       
    88         
       
    89     	/**
       
    90     	 * GetId
       
    91     	 * @return the Id
       
    92     	 */
       
    93         TInt GetId() const;
       
    94         
       
    95     	/**
       
    96     	 * GetString
       
    97     	 * @return HBufC* to the string
       
    98     	 */
       
    99         HBufC* GetString();
       
   100         
       
   101     private:    
       
   102     	/**
       
   103     	 * 2nd Phase constructor
       
   104     	 * @param the string. Creates own copy of string
       
   105     	 */
       
   106         
       
   107         void ConstructL(HBufC* aString);
       
   108 
       
   109 
       
   110     private:
       
   111         /// The resource id of the string
       
   112         TInt    iId;
       
   113         
       
   114         /// HBufC containing the string (Owned)
       
   115         HBufC*  iString;
       
   116         };
       
   117 private:
       
   118 	/**
       
   119 	 * Default Constructor
       
   120 	 */
       
   121     CGlxStringCache();
       
   122     
       
   123 	/**
       
   124 	 * Searches for a string given the resource id
       
   125 	 * @param - resource id
       
   126 	 * @return - an HBufC* to the string. NULL if not found. Ownership of string passed to caller.
       
   127 	 */
       
   128     HBufC* FindL(TInt aId);
       
   129     
       
   130 	/**
       
   131 	 * Inserts a string and resource id into the cache
       
   132 	 * @param - resource id
       
   133 	 * @return - an HBufC* to the string. NULL if not found. Ownership of string passed to caller.
       
   134 	 */    
       
   135     void InsertL(TInt aId, HBufC* aString);
       
   136     /**
       
   137      * Count
       
   138      * @return number of elements in array
       
   139      */ 
       
   140     TInt Count();
       
   141     
       
   142     /**
       
   143      * This method is a callback passed to RPointerArray.InsertInOrder
       
   144      * @ref see TLinearOrder.
       
   145      * @param first item to be compared
       
   146      * @param second item to be compared
       
   147      * @return a negative value is Item1 is less than Item2. Zero if Equal, otherwise a positive value
       
   148      */
       
   149     static TInt OrderById(const CGlxStringCache::CGlxStringItem& aItem1, const CGlxStringCache::CGlxStringItem& aItem2);
       
   150 
       
   151     /**
       
   152      * This method is a callback passed to RPointerArray.Find
       
   153      * @ref see TIdentityRelation.
       
   154      * @param first item to be compared
       
   155      * @param second item to be compared
       
   156      * @return ETrue id Item1 matches Item2, otherwise EFalse
       
   157      */
       
   158     static TBool MatchById(const CGlxStringCache::CGlxStringItem& aItem1, const CGlxStringCache::CGlxStringItem& aItem2);
       
   159     
       
   160     /**
       
   161 	 * Loads a string from a resurce file
       
   162 	 *
       
   163 	 * @param aResourceFile - name of the resource file (does not contain the path).
       
   164 	 * @param aResourceId - Id of the string to be loaded
       
   165 	 * @return HBufC* containing the required string.
       
   166 	 */	
       
   167 	HBufC* LoadLocalizedStringFromDriveL(const TDesC& aResourceFile, const TInt aResourceId);
       
   168 
       
   169 private:
       
   170     /// Array of CGlxStringItems
       
   171     RPointerArray<CGlxStringItem>   iStringCache;
       
   172     
       
   173     // remembers the valid resource file name
       
   174     TFileName           iResourceFileName;
       
   175     };
       
   176 
       
   177 
       
   178 #endif