upnpharvester/common/cmlibrary/src/cmstorerulecontainer.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-2007 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:      Capsulating fill rules
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <s32mem.h>
       
    26 #include "cmstorerulecontainer.h"
       
    27 #include "cmstorerule.h"
       
    28 #include "msdebug.h"
       
    29  
       
    30 // CONSTANTS
       
    31 const TInt KStoreRuleArrayGranularity = 16;
       
    32  
       
    33 // ======== LOCAL FUNCTIONS ========
       
    34 // ---------------------------------------------------------------------------
       
    35 // NewL
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 EXPORT_C CCmStoreRuleContainer* CCmStoreRuleContainer::NewL()
       
    39     {
       
    40     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::NewL() start")));    
       
    41     CCmStoreRuleContainer* self = CCmStoreRuleContainer::NewLC();
       
    42     CleanupStack::Pop( self );
       
    43     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::NewL() end"))); 
       
    44     return self;
       
    45     }
       
    46  
       
    47 // ---------------------------------------------------------------------------
       
    48 // NewLC
       
    49 // ---------------------------------------------------------------------------
       
    50 //    
       
    51 EXPORT_C CCmStoreRuleContainer* CCmStoreRuleContainer::NewLC()
       
    52     {
       
    53     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::NewLC() start")));    
       
    54     CCmStoreRuleContainer* self = new ( ELeave ) CCmStoreRuleContainer();
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::NewLC() end"))); 
       
    58     return self;  
       
    59     }    
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Destructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CCmStoreRuleContainer::~CCmStoreRuleContainer()
       
    66     {
       
    67     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::\
       
    68         ~CCmStoreRuleContainer() start")));
       
    69     iStoreRuleArray.ResetAndDestroy();
       
    70     iStoreRuleArray.Close();
       
    71     TRACE(Print(_L("[COMMON]\t CCmStoreRuleContainer::\
       
    72         ~CCmStoreRuleContainer() end")));     
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Add new rule into store rule
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C TInt CCmStoreRuleContainer::AddStoreRuleL( CCmStoreRule* aRule )
       
    80     {
       
    81     iStoreRuleArray.AppendL( aRule );
       
    82     TInt index = iStoreRuleArray.Count() - 1;    
       
    83     return index;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Deletes store rule with the given index
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C void CCmStoreRuleContainer::DeleteStoreRule( TInt aIndex )
       
    91     {
       
    92     if( iStoreRuleArray.Count() > aIndex )
       
    93         {
       
    94         delete iStoreRuleArray[aIndex];
       
    95         iStoreRuleArray.Remove(aIndex);
       
    96         iStoreRuleArray.Compress();
       
    97         }
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // Get rule
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 EXPORT_C CCmStoreRule* CCmStoreRuleContainer::StoreRule( TInt aIndex )
       
   105     {
       
   106     return iStoreRuleArray[aIndex];
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Returns count of rules
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TInt CCmStoreRuleContainer::StoreRuleCount() const
       
   114     {
       
   115     return iStoreRuleArray.Count();
       
   116     }    
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CCmFillRuleContainer::ExternalizeL
       
   120 // Writes the content to stream.
       
   121 // (other items were commented in a header).
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C void CCmStoreRuleContainer::ExternalizeL( 
       
   125     RWriteStream& aStream ) const
       
   126     {
       
   127     // Let's write the count of fill rules to stream first
       
   128     aStream.WriteInt16L( iStoreRuleArray.Count() );
       
   129     for ( TInt index = 0; index < iStoreRuleArray.Count(); index++ )
       
   130         {
       
   131         CCmStoreRule* rule = iStoreRuleArray[index];    
       
   132         // Then the object itself
       
   133         rule->ExternalizeL( aStream );
       
   134         }
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CUPnPContainer::InternalizeL
       
   139 // Fills container information from stream
       
   140 // (other items were commented in a header).
       
   141 // ---------------------------------------------------------------------------
       
   142 //    
       
   143 EXPORT_C void CCmStoreRuleContainer::InternalizeL( RReadStream& aStream )
       
   144     {
       
   145     // Then internalize the objects
       
   146     if ( iStoreRuleArray.Count() > KErrNone )
       
   147         {
       
   148         iStoreRuleArray.ResetAndDestroy();
       
   149         }
       
   150     // First the count of fill rules
       
   151     TInt ruleCount = aStream.ReadInt16L();
       
   152     
       
   153     // Then internalize them from the stream one by one
       
   154     for (TInt index = 0; index < ruleCount; index++ )
       
   155         {
       
   156         CCmStoreRule* newItem = CCmStoreRule::NewL();
       
   157         CleanupStack::PushL( newItem );
       
   158         newItem->InternalizeL( aStream );
       
   159         AddStoreRuleL( newItem );
       
   160         CleanupStack::Pop( newItem ); 
       
   161         newItem = NULL;
       
   162         }
       
   163     }
       
   164                     
       
   165 // ---------------------------------------------------------------------------
       
   166 // Default constructor
       
   167 // ---------------------------------------------------------------------------
       
   168 //    
       
   169 CCmStoreRuleContainer::CCmStoreRuleContainer() : 
       
   170     iStoreRuleArray( KStoreRuleArrayGranularity )
       
   171     {
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // ConstructL
       
   176 // ---------------------------------------------------------------------------
       
   177 //    
       
   178 void CCmStoreRuleContainer::ConstructL()
       
   179     {
       
   180     }    
       
   181 
       
   182 // End of file
       
   183