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