homescreenpluginsrv/inc/hspsdomstringpool.h
branchRCL_3
changeset 114 a5a39a295112
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2005,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:  Flyweigth pattern implementation for dom strings.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef HSPS_DOM_STRING_POOL_H
       
    19 #define HSPS_DOM_STRING_POOL_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <s32strm.h>
       
    24 #include "hspsdomstringpooloptimizer.h"
       
    25 
       
    26 // CLASS DECLARATION
       
    27 
       
    28 /**
       
    29 *  @ingroup group_hspsdom
       
    30 *  Class utilize flyweight pattern. Dom strings are stored once 
       
    31 *  and referred with index. Class can be serialized.
       
    32 *
       
    33 *  @lib xndomdocument.lib
       
    34 *  @since Series 60 3.1
       
    35 */
       
    36 class ChspsDomStringPool : public CBase
       
    37     {
       
    38     public:  // Constructors and destructor
       
    39         
       
    40         /**
       
    41         * Two-phased constructor.
       
    42         * 
       
    43         * @param    aAllowDuplicates        ETrue if duplicates are to be allowed.
       
    44         *                                   Supported for legacy reasons. 
       
    45         */
       
    46         static ChspsDomStringPool* NewL( const TBool aAllowDuplicates = EFalse );
       
    47 
       
    48         /**
       
    49         * Two-phased stream constructor.
       
    50         * 
       
    51         * @param    aStream                 Stream where string pool is internalized.
       
    52         * @param    aAllowDuplicates        ETrue if duplicates are to be allowed.
       
    53         *                                   Supported for legacy reasons. 
       
    54         */
       
    55         static ChspsDomStringPool* NewL( RReadStream& aStream,
       
    56                 const TBool aAllowDuplicates = EFalse );
       
    57         
       
    58         /**
       
    59         * Destructor.
       
    60         */
       
    61         virtual ~ChspsDomStringPool();
       
    62         
       
    63    public: 
       
    64         /**
       
    65         * Make a copy from original StringPool.
       
    66         * @since Series 60 3.1
       
    67         * @return Pointer to a string pool. Ownership is transferred to a caller.
       
    68         */
       
    69         ChspsDomStringPool* CloneL(); 
       
    70         
       
    71         /**
       
    72         * Reset string pool to be reused.
       
    73         * 
       
    74         * @since Series 60 5.2
       
    75         */
       
    76         void Reset();         
       
    77         
       
    78    public: //Adding
       
    79         
       
    80         /**
       
    81         * Set dom string into string pool.
       
    82         * 
       
    83         * @param aString String to add to string pool
       
    84         * @return Index (reference) to string pool
       
    85         */
       
    86         IMPORT_C TInt AddStringL( const TDesC8& aString ); 
       
    87 
       
    88         /**
       
    89         * Set dom string into string pool.
       
    90         * 
       
    91         * @param aString String to add to string pool. OWNERSHIP TRANSFERRED!
       
    92         * @return Index (reference) to string pool
       
    93         */
       
    94         TInt AddStringL( HBufC8* aString );         
       
    95 
       
    96         /**
       
    97         * Add all string from another string pool.
       
    98         * 
       
    99         * @param aStringPool    Source string pool.
       
   100         */
       
   101         void AddAllL( ChspsDomStringPool& aStringPool );        
       
   102         
       
   103    public: //Accessing     
       
   104         /**
       
   105         * Get reference to string.
       
   106         * 
       
   107         * @param aMap Map object which has index to name string
       
   108         * @return Pointer to the name
       
   109         */
       
   110         const TDesC8& String( const TInt aStringRef ); 
       
   111         
       
   112         /**
       
   113         * Get object's data size in bytes.
       
   114         * 
       
   115         * @return Data size in bytes
       
   116         */
       
   117         TInt Size() const;
       
   118 
       
   119         /**
       
   120         * Get amount of strings.
       
   121         */
       
   122         TInt Count() const;        
       
   123         
       
   124         /**
       
   125         * Externalize object.
       
   126         * 
       
   127         * @param aStream Output stream
       
   128         */
       
   129         void ExternalizeL( RWriteStream& aStream ) const;
       
   130        
       
   131         /**
       
   132         * Internalize object.
       
   133         * 
       
   134         * @param aStream Input stream
       
   135         */
       
   136         void InternalizeL( RReadStream& aStream );          
       
   137         
       
   138    private:
       
   139 
       
   140         /**
       
   141         * C++ default constructor.
       
   142         * 
       
   143         * @param    aAllowDuplicates        ETrue if duplicates are to be allowed.
       
   144         *                                   Supported for legacy reasons.
       
   145         */
       
   146         ChspsDomStringPool( const TBool aAllowDuplicates );
       
   147 
       
   148         /**
       
   149         * By default Symbian 2nd phase constructor is private. 
       
   150         */
       
   151         void ConstructL();    
       
   152         
       
   153         /**
       
   154         * Add string to string pool and to optimizer also.
       
   155         * 
       
   156         * @param aNewString     String to be added. OWNERSHIP TRANSFERRED.
       
   157         * @param TInt           Index to added string.
       
   158         */
       
   159         TInt DoAddStringL( HBufC8* aNewString ) ;
       
   160         
       
   161     private:            
       
   162         //String pool
       
   163         RPointerArray<HBufC8>       iStringPool;
       
   164         
       
   165         /**
       
   166          * String pool optimizer.
       
   167          */
       
   168         ThspsDomStringPoolOptimizer iStringPoolOptimizer;
       
   169         
       
   170         /**
       
   171          * ETrue if string pool can contain duplicate entries. Must
       
   172          * be supported for legacy reasons while loading xuikon odts.
       
   173          */
       
   174         TBool iAllowDuplicates;
       
   175     };
       
   176 
       
   177 #endif      // HSPS_DOM_STRING_POOL_H  
       
   178             
       
   179 // End of File