menufw/hierarchynavigator/hnmetadatamodel/inc/hnxmlmodelcache.h
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef HNXMLMODELCACHE_H_
       
    20 #define HNXMLMODELCACHE_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32hashtab.h>
       
    24 #include <xmlengdom.h>
       
    25 #include <bautils.h>
       
    26 
       
    27 
       
    28 /**
       
    29  * Suites cache.
       
    30  * 
       
    31  * This class is designed to support caching xml documents which contain
       
    32  * suites definitions.
       
    33  * 
       
    34  * The cache is directlty used by the xml model provider (CHnXmlModelProvider)
       
    35  * and is transparent for other data model's classes.
       
    36  * 
       
    37  * The cache has a maksimum capacity which is equal to KXmlModelCacheMaxLength.
       
    38  * The cache works similarily to a shift register. When the maksimum size of
       
    39  * the cache is exceeded then the last element in the cache is removed.
       
    40  * On contrary, most often used xml documents are moved to the beggining
       
    41  * of the cache.
       
    42  * 
       
    43  * @since S60 5.0
       
    44  * @ingroup group_hnmetadatamodel
       
    45  */
       
    46 NONSHARABLE_CLASS( CHnXmlModelCache ) : public CBase
       
    47     {
       
    48 
       
    49 private:
       
    50     
       
    51     /**
       
    52      * Default constructor.
       
    53      * 
       
    54      * @since S60 5.0
       
    55      */
       
    56     CHnXmlModelCache();
       
    57     
       
    58     /**
       
    59      * Standard second phase constructor.
       
    60      * 
       
    61      * @since S60 5.0
       
    62      */
       
    63     void ConstructL();
       
    64     
       
    65     /**
       
    66      * Removes a xml document from the cache if the size of the cache
       
    67      * is exceeded.
       
    68      * 
       
    69      * @since S60 5.0
       
    70      */
       
    71     void RemoveUnused();
       
    72     
       
    73     /**
       
    74      * Moves the xml document (identified by a given name) to the top of the
       
    75      * cache.
       
    76      * 
       
    77      * @param aSuiteName A name of the xml document to be moved to the top
       
    78      *                   of the cache.
       
    79      * @since S60 5.0
       
    80      */
       
    81     void MoveToTopL( const TDesC & aSuiteName );
       
    82 
       
    83 public:
       
    84     
       
    85     /**
       
    86      * Two-phase constructor.
       
    87      * 
       
    88      * @since S60 5.0
       
    89      */
       
    90     static CHnXmlModelCache* NewLC();
       
    91     
       
    92     /**
       
    93      * Two-phase constructor.
       
    94      * 
       
    95      * 
       
    96      */
       
    97     static CHnXmlModelCache* NewL();
       
    98     
       
    99     /**
       
   100      * Adds a new xml document into the cache.
       
   101      * @param aSuiteName A name of the suite.
       
   102      * @param aDocument A xml document to be added to the cache.
       
   103      * 
       
   104      * @since S60 5.0
       
   105      */
       
   106     TInt AddL( const TDesC& aSuiteName, RXmlEngDocument& aDocument );
       
   107     
       
   108     /**
       
   109      * Checks if the xml document is stored in the cache.
       
   110      * 
       
   111      * @param aSuiteName The name of the suite to be checked.
       
   112      * @return ETrue if a suite of a given name is stored in the cache,
       
   113      *         otherwise - EFalse.
       
   114      *         
       
   115      * @since S60 5.0
       
   116      */
       
   117     TBool IsCachedL( const TDesC& aSuiteName );
       
   118     
       
   119     /**
       
   120      * Gets a xml document by a given name.
       
   121      * 
       
   122      * @param aSuiteName The name corresponding to the xml document to be
       
   123      *                   retrieved from the cache.
       
   124      * @param aDocument The reference to the xml document.
       
   125      * 
       
   126      * @since S60 5.0
       
   127      */
       
   128     void GetL( const TDesC& aSuiteName, RXmlEngDocument& aDocument );
       
   129     
       
   130     /**
       
   131      * Resets the cache - removes all stored xml documents.
       
   132      * 
       
   133      * @since S60 5.0
       
   134      */
       
   135     void Reset();
       
   136     
       
   137     /**
       
   138      * Standard C++ virtual destructor.
       
   139      * 
       
   140      * @since S60 5.0
       
   141      */
       
   142     virtual ~CHnXmlModelCache();
       
   143 
       
   144 private:
       
   145     
       
   146     /**
       
   147      * The hash map storing pairs: name of the suite, corresponding xml
       
   148      * document.
       
   149      * 
       
   150      * @since S60 5.0
       
   151      */
       
   152     RHashMap< HBufC*, RXmlEngDocument > iDocuments;
       
   153     
       
   154     /**
       
   155      * An auxilliary array storing the order of the xml document
       
   156      * in the cache.
       
   157      * 
       
   158      * @since S60 5.0
       
   159      */
       
   160     RPointerArray< HBufC > iOrder;
       
   161     
       
   162     };
       
   163 
       
   164 #endif /*HNXMLMODELCACHE_H_*/