upnpharvester/common/cmlibrary/src/cmsqlpropertycollector.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 property container objects
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <s32mem.h>
       
    26 #include "cmsqlpropertycontainer.h"
       
    27 #include "cmsqlpropertycollector.h"
       
    28 #include "msdebug.h"
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KArrayGranularity = 16;
       
    32 
       
    33 // ======== LOCAL FUNCTIONS ========
       
    34 // --------------------------------------------------------------------------
       
    35 // NewL
       
    36 // --------------------------------------------------------------------------
       
    37 //
       
    38 EXPORT_C CCmSqlPropertyCollector* CCmSqlPropertyCollector::NewL()
       
    39     {
       
    40     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::NewL"));
       
    41     
       
    42     CCmSqlPropertyCollector* self = CCmSqlPropertyCollector::NewLC();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // --------------------------------------------------------------------------
       
    48 // NewLC
       
    49 // --------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CCmSqlPropertyCollector* CCmSqlPropertyCollector::NewLC()
       
    52     {
       
    53     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::NewLC"));
       
    54     
       
    55     CCmSqlPropertyCollector* self = new ( ELeave ) CCmSqlPropertyCollector();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     return self;
       
    59     }
       
    60 
       
    61 // --------------------------------------------------------------------------
       
    62 // Destructor
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CCmSqlPropertyCollector::~CCmSqlPropertyCollector()
       
    66     {
       
    67     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::\
       
    68     ~CCmSqlPropertyCollector"));
       
    69     
       
    70     iPropertyContainers.ResetAndDestroy();
       
    71     iPropertyContainers.Close();
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------
       
    75 // CCmSqlPropertyCollector::AddPropertyContainerL
       
    76 // --------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C TInt CCmSqlPropertyCollector::AddPropertyContainerL(
       
    79     CCmSqlPropertyContainer* aContainer )
       
    80     {
       
    81     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::AddPropertyContainerL"));
       
    82     
       
    83     iPropertyContainers.AppendL( aContainer );
       
    84     TInt index = iPropertyContainers.Count() - 1;
       
    85     return index;
       
    86     }
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CCmSqlPropertyCollector::DeletePropertyContainer
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C void CCmSqlPropertyCollector::DeletePropertyContainer( TInt aIndex )
       
    93     {
       
    94     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::\
       
    95     DeletePropertyContainer"));
       
    96     
       
    97     if( iPropertyContainers.Count() > aIndex )
       
    98         {
       
    99         delete iPropertyContainers[aIndex];
       
   100         iPropertyContainers.Remove(aIndex);
       
   101         iPropertyContainers.Compress();
       
   102         }
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CCCmSqlPropertyCollector::PropertyContainer
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C CCmSqlPropertyContainer*
       
   110                 CCmSqlPropertyCollector::PropertyContainer( TInt aIndex )
       
   111     {
       
   112     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::PropertyContainer"));
       
   113     
       
   114     return iPropertyContainers[aIndex];
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------
       
   118 // CCmSqlPropertyCollector::PropertyContainerCount
       
   119 // --------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C TInt CCmSqlPropertyCollector::PropertyContainerCount() const
       
   122     {
       
   123     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::PropertyContainerCount"));
       
   124     
       
   125     return iPropertyContainers.Count();
       
   126     }
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CCmSqlPropertyCollector::ExternalizeL
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C void CCmSqlPropertyCollector::ExternalizeL(
       
   133     RWriteStream& aStream ) const
       
   134     {
       
   135     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::ExternalizeL"));
       
   136     
       
   137     // Let's write the count of fill rules to stream first
       
   138     aStream.WriteInt16L( iPropertyContainers.Count() );
       
   139     for ( TInt index = 0; index < iPropertyContainers.Count(); index++ )
       
   140         {
       
   141         CCmSqlPropertyContainer* container = iPropertyContainers[index];
       
   142         // Then the object itself
       
   143         container->ExternalizeL( aStream );
       
   144         }
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CCmSqlPropertyCollector::InternalizeL
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CCmSqlPropertyCollector::InternalizeL( RReadStream& aStream )
       
   152     {
       
   153     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::InternalizeL"));
       
   154     
       
   155     // Then internalize the objects
       
   156     if ( iPropertyContainers.Count() > KErrNone )
       
   157         {
       
   158         iPropertyContainers.ResetAndDestroy();
       
   159         }
       
   160     // First the count of fill rules
       
   161     TInt itemCount = aStream.ReadInt16L();
       
   162 
       
   163     // Then internalize them from the stream one by one
       
   164     for (TInt index = 0; index < itemCount; index++ )
       
   165         {
       
   166         CCmSqlPropertyContainer* newContainer =
       
   167                                 CCmSqlPropertyContainer::NewL();
       
   168         CleanupStack::PushL( newContainer );
       
   169         newContainer->InternalizeL( aStream );
       
   170         AddPropertyContainerL( newContainer );
       
   171         CleanupStack::Pop( newContainer );
       
   172         newContainer = NULL;
       
   173         }
       
   174     }
       
   175 
       
   176 // --------------------------------------------------------------------------
       
   177 // Default constructor
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180 CCmSqlPropertyCollector::CCmSqlPropertyCollector() :
       
   181     iPropertyContainers( KArrayGranularity )
       
   182     {
       
   183     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::\
       
   184     CCmSqlPropertyCollector"));
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // ConstructL
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 void CCmSqlPropertyCollector::ConstructL()
       
   192     {
       
   193     LOG(_L("[CmLibrary]\t CCmSqlPropertyCollector::ConstructL"));
       
   194     }
       
   195 
       
   196 // End of file
       
   197