upnpharvester/common/cmlibrary/src/cmsqlpropertycontainer.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 propety item objects
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <s32mem.h>
       
    26 #include "cmsqlpropertyitem.h"
       
    27 #include "cmsqlpropertycontainer.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 CCmSqlPropertyContainer* CCmSqlPropertyContainer::NewL()
       
    39     {
       
    40     CCmSqlPropertyContainer* self = CCmSqlPropertyContainer::NewLC();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // NewLC
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CCmSqlPropertyContainer* CCmSqlPropertyContainer::NewLC()
       
    50     {
       
    51     CCmSqlPropertyContainer* self = new ( ELeave ) CCmSqlPropertyContainer();
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Destructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CCmSqlPropertyContainer::~CCmSqlPropertyContainer()
       
    62     {
       
    63     iPropertyItems.ResetAndDestroy();
       
    64     iPropertyItems.Close();
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CCmSqlPropertyContainer::AddPropertyItemL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CCmSqlPropertyContainer::AddPropertyItemL(
       
    72     CCmSqlPropertyItem* aItem )
       
    73     {
       
    74     iPropertyItems.AppendL( aItem );
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CCmSqlPropertyContainer::DeletePropertyItem
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CCmSqlPropertyContainer::DeletePropertyItem( TInt aIndex )
       
    82     {
       
    83     if( iPropertyItems.Count() > aIndex )
       
    84         {
       
    85         delete iPropertyItems[aIndex];
       
    86         iPropertyItems.Remove(aIndex);
       
    87         iPropertyItems.Compress();
       
    88         }
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CCmSqlPropertyContainer::PropertyItem
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C CCmSqlPropertyItem* CCmSqlPropertyContainer::PropertyItem(
       
    96     TInt aIndex )
       
    97     {
       
    98     return iPropertyItems[aIndex];
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CCmSqlPropertyContainer::PropertyItemCount
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C TInt CCmSqlPropertyContainer::PropertyItemCount() const
       
   106     {
       
   107     return iPropertyItems.Count();
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCmSqlPropertyContainer::SetType
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CCmSqlPropertyContainer::SetType( TCmMetadataField aType )
       
   115     {
       
   116     iType = aType;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CCmSqlPropertyContainer::Type
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TCmMetadataField CCmSqlPropertyContainer::Type( )
       
   124     {
       
   125     return iType;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CCmSqlPropertyContainer::IsDuplicate
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C TBool CCmSqlPropertyContainer::IsDuplicate(
       
   133     CCmSqlPropertyItem& aItem )
       
   134     {
       
   135     TBool ret( EFalse );
       
   136     TInt64 id( aItem.Id() );
       
   137     TInt count( iPropertyItems.Count() );
       
   138     for( TInt i = 0; i < count; i++ )
       
   139         {
       
   140         if( id == iPropertyItems[i]->Id() )
       
   141             {
       
   142             ret = ETrue;
       
   143             // Duplicate found => end loop
       
   144             i = count;
       
   145             }
       
   146         }
       
   147     return ret;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CCmSqlPropertyContainer::ExternalizeL
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C void CCmSqlPropertyContainer::ExternalizeL(
       
   155     RWriteStream& aStream ) const
       
   156     {
       
   157     // Let's write the count of fill rules to stream first
       
   158     aStream.WriteInt16L( iPropertyItems.Count() );
       
   159     aStream.WriteUint8L( iType );
       
   160     for ( TInt index = 0; index < iPropertyItems.Count(); index++ )
       
   161         {
       
   162         CCmSqlPropertyItem* item = iPropertyItems[index];
       
   163         // Then the object itself
       
   164         item->ExternalizeL( aStream );
       
   165         }
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CCmSqlPropertyContainer::InternalizeL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CCmSqlPropertyContainer::InternalizeL( RReadStream& aStream )
       
   173     {
       
   174     // Then internalize the objects
       
   175     if ( iPropertyItems.Count() > KErrNone )
       
   176         {
       
   177         iPropertyItems.ResetAndDestroy();
       
   178         }
       
   179     // First the count of fill rules
       
   180     TInt itemCount = aStream.ReadInt16L();
       
   181     iType = (TCmMetadataField)aStream.ReadInt8L();
       
   182     // Then internalize them from the stream one by one
       
   183     for (TInt index = 0; index < itemCount; index++ )
       
   184         {
       
   185         CCmSqlPropertyItem* newItem = CCmSqlPropertyItem::NewL();
       
   186         CleanupStack::PushL( newItem );
       
   187         newItem->InternalizeL( aStream );
       
   188         AddPropertyItemL( newItem );
       
   189         CleanupStack::Pop( newItem );
       
   190         newItem = NULL;
       
   191         }
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CCmSqlPropertyContainer::SortPropertyItem
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C void CCmSqlPropertyContainer::SortPropertyItem( )
       
   200     {
       
   201     if( ( ECmArtist == iType ) || ( ECmAlbum == iType )
       
   202                || ( ECmGenre == iType ) || ( ECmTitle == iType ) )
       
   203         {
       
   204         if( iPropertyItems.Count() > 0 )
       
   205             {
       
   206             iPropertyItems.Sort( TLinearOrder<CCmSqlPropertyItem>
       
   207                                 ( CCmSqlPropertyContainer::CompareItem ) );
       
   208             }
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Default constructor
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 CCmSqlPropertyContainer::CCmSqlPropertyContainer() :
       
   217     iPropertyItems( KArrayGranularity )
       
   218     {
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // ConstructL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CCmSqlPropertyContainer::ConstructL()
       
   226     {
       
   227     }
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCmSqlPropertyContainer::CompareItem
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CCmSqlPropertyContainer::CompareItem(
       
   235     const CCmSqlPropertyItem& aItemOne,const CCmSqlPropertyItem& aItemTwo )
       
   236     {
       
   237     TInt ret = 0;
       
   238     ret = ( aItemOne.Name() ).CompareC( aItemTwo.Name() );
       
   239     return ret;
       
   240     }
       
   241 
       
   242 // End of file