memspy/Engine/Source/Sink/MemSpyEngineOutputList.cpp
changeset 0 a03f92240627
child 20 ca8a1b6995f6
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <memspy/engine/memspyengineoutputlist.h>
       
    19 
       
    20 // System includes
       
    21 #include <e32debug.h>
       
    22 
       
    23 // User includes
       
    24 #include <memspy/engine/memspyengineutils.h>
       
    25 #include <memspy/engine/memspyengineoutputsink.h>
       
    26 #include "MemSpyEngineOutputListItem.h"
       
    27 
       
    28 // Constants
       
    29 _LIT( KMemSpyOutputListPseudoBlankItem, " " );
       
    30 
       
    31 
       
    32 CMemSpyEngineOutputList::CMemSpyEngineOutputList( CMemSpyEngineOutputSink* aSink )
       
    33 :   iSink( aSink ), iFormatBufferPtr( NULL, 0 )
       
    34     {
       
    35     }
       
    36 
       
    37 
       
    38 CMemSpyEngineOutputList::~CMemSpyEngineOutputList()
       
    39     {
       
    40     delete iFormatBuffer;
       
    41     iItems.ResetAndDestroy();
       
    42     iItems.Close();
       
    43     }
       
    44 
       
    45 
       
    46 void CMemSpyEngineOutputList::ConstructL()
       
    47     {
       
    48     iFormatBuffer = HBufC::NewL( 1024 );
       
    49     iFormatBufferPtr.Set( iFormatBuffer->Des() );
       
    50     }
       
    51 
       
    52 
       
    53 CMemSpyEngineOutputList* CMemSpyEngineOutputList::NewL()
       
    54     {
       
    55     CMemSpyEngineOutputList* self = new(ELeave) CMemSpyEngineOutputList();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 CMemSpyEngineOutputList* CMemSpyEngineOutputList::NewLC( CMemSpyEngineOutputSink& aSink )
       
    64     {
       
    65     CMemSpyEngineOutputList* self = new(ELeave) CMemSpyEngineOutputList( &aSink );
       
    66     CleanupStack::PushL( self );
       
    67 
       
    68     // No need to call ConstructL - it uses the sink's format buffer
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 TInt CMemSpyEngineOutputList::MdcaCount() const
       
    74     {
       
    75     return iItems.Count();
       
    76     }
       
    77 
       
    78 
       
    79 TPtrC CMemSpyEngineOutputList::MdcaPoint( TInt aPos ) const
       
    80     {
       
    81     CMemSpyEngineOutputListItem* item = iItems[ aPos ];
       
    82     return TPtrC( item->Combined() );
       
    83     }
       
    84 
       
    85 
       
    86 void CMemSpyEngineOutputList::PrintL()
       
    87     {
       
    88     ASSERT( iSink != NULL );
       
    89     PrintL( *iSink );
       
    90     }
       
    91 
       
    92 
       
    93 void CMemSpyEngineOutputList::PrintL( CMemSpyEngineOutputSink& aSink )
       
    94     {
       
    95     const TInt count = iItems.Count();
       
    96     if  ( count > 0 )
       
    97         {
       
    98         // First pass to get max lengths
       
    99         TInt maxLengthCaption = 0;
       
   100         TInt maxLengthValue = 0;
       
   101 
       
   102         for( TInt j=0; j<count; j++ )
       
   103             {
       
   104             const CMemSpyEngineOutputListItem* item = iItems[ j ];
       
   105             maxLengthCaption = Max( maxLengthCaption, item->Caption().Length() );
       
   106             maxLengthValue = Max( maxLengthValue, item->Value().Length() );
       
   107             }
       
   108 
       
   109         // Second pass - real this time - to print the values
       
   110         HBufC* line = HBufC::NewLC( ( maxLengthCaption + maxLengthValue ) + 20 );
       
   111         TPtr pLine( line->Des() );
       
   112         //
       
   113         for( TInt i=0; i<count; i++ )
       
   114             {
       
   115             const CMemSpyEngineOutputListItem* item = iItems[ i ];
       
   116 
       
   117             // Remove initial tabs in caption
       
   118             HBufC* caption = MemSpyEngineUtils::CleanupTextLC( item->Caption() );
       
   119         
       
   120             // Create value item & replace any further tabs
       
   121             HBufC* value = MemSpyEngineUtils::CleanupTextLC( item->Value() );
       
   122 
       
   123             // Now format the final line, with padding.
       
   124             pLine.Justify( *caption, maxLengthCaption + 3, ELeft, TChar(' ') );
       
   125             pLine.Append( *value );
       
   126             CleanupStack::PopAndDestroy( 2, caption );
       
   127 
       
   128             // Sink output
       
   129             aSink.OutputLineL( pLine );
       
   130             }
       
   131         //
       
   132         CleanupStack::PopAndDestroy( line );
       
   133         }
       
   134     }
       
   135 
       
   136 
       
   137 CMemSpyEngineOutputListItem& CMemSpyEngineOutputList::Item( TInt aPos )
       
   138     {
       
   139     CMemSpyEngineOutputListItem* ret = iItems[ aPos ];
       
   140     return *ret;
       
   141     }
       
   142 
       
   143 
       
   144 const CMemSpyEngineOutputListItem& CMemSpyEngineOutputList::Item( TInt aPos ) const
       
   145     {
       
   146     const CMemSpyEngineOutputListItem* ret = iItems[ aPos ];
       
   147     return *ret;
       
   148     }
       
   149 
       
   150 
       
   151 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption )
       
   152     {
       
   153     AddItemL( aCaption, KNullDesC );
       
   154     }
       
   155 
       
   156 
       
   157 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, const TDesC& aValue )
       
   158     {
       
   159     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   160     iItems.AppendL( item );
       
   161     CleanupStack::Pop( item );
       
   162     }
       
   163 
       
   164 
       
   165 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TInt aValue )
       
   166     {
       
   167     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewDecimalLC( aCaption, aValue );
       
   168     iItems.AppendL( item );
       
   169     CleanupStack::Pop( item );
       
   170     }
       
   171 
       
   172 
       
   173 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint aValue )
       
   174     {
       
   175     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewDecimalLC( aCaption, aValue );
       
   176     iItems.AppendL( item );
       
   177     CleanupStack::Pop( item );
       
   178     }
       
   179 
       
   180 
       
   181 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, const TInt64& aValue )
       
   182     {
       
   183     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLongLC( aCaption, aValue );
       
   184     iItems.AppendL( item );
       
   185     CleanupStack::Pop( item );
       
   186     }
       
   187 
       
   188 
       
   189 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TAny* aValue )
       
   190     {
       
   191     AddItemHexL( aCaption, (TUint) aValue );
       
   192     }
       
   193 
       
   194 
       
   195 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint* aValue )
       
   196     {
       
   197     AddItemHexL( aCaption, (TUint) aValue );
       
   198     }
       
   199 
       
   200 
       
   201 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint8* aValue )
       
   202     {
       
   203     AddItemHexL( aCaption, (TUint) aValue );
       
   204     }
       
   205 
       
   206 
       
   207 void CMemSpyEngineOutputList::AddItemFormatL( TRefByValue<const TDesC> aFormat, ... )
       
   208     {
       
   209 	VA_LIST list;
       
   210 	VA_START(list,aFormat);
       
   211 
       
   212     TPtr formatBuffer( FormatBuffer() );
       
   213 	formatBuffer.Zero();
       
   214     formatBuffer.FormatList( aFormat, list );
       
   215     //
       
   216     AddItemL( formatBuffer, KNullDesC );
       
   217     }
       
   218 
       
   219 
       
   220 void CMemSpyEngineOutputList::AddItemFormatL( const TDesC& aCaption, TRefByValue<const TDesC> aValueFormat, ... )
       
   221     {
       
   222 	VA_LIST list;
       
   223 	VA_START(list,aValueFormat);
       
   224 
       
   225     TPtr formatBuffer( FormatBuffer() );
       
   226 	formatBuffer.Zero();
       
   227     formatBuffer.FormatList( aValueFormat, list );
       
   228     //
       
   229     AddItemL( aCaption, formatBuffer );
       
   230     }
       
   231 
       
   232 
       
   233 void CMemSpyEngineOutputList::AddItemFormatUCL( TRefByValue<const TDesC> aFormat, ... )
       
   234     {
       
   235 	VA_LIST list;
       
   236 	VA_START(list,aFormat);
       
   237 
       
   238     TPtr formatBuffer( FormatBuffer() );
       
   239 	formatBuffer.Zero();
       
   240     formatBuffer.FormatList( aFormat, list );
       
   241     //
       
   242     AddItemUCL( formatBuffer, KNullDesC );
       
   243     }
       
   244 
       
   245 
       
   246 void CMemSpyEngineOutputList::AddItemUCL( const TDesC& aCaption, const TDesC& aValue )
       
   247     {
       
   248     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   249     iItems.AppendL( item );
       
   250     CleanupStack::Pop( item );
       
   251     //
       
   252     item->iCaption->Des().UpperCase();
       
   253     item->UpdateCombinedL();
       
   254     }
       
   255 
       
   256 
       
   257 void CMemSpyEngineOutputList::AddItemFormatUCL( const TDesC& aCaption, TRefByValue<const TDesC> aValueFormat, ... )
       
   258     {
       
   259 	VA_LIST list;
       
   260 	VA_START(list,aValueFormat);
       
   261 
       
   262     TPtr formatBuffer( FormatBuffer() );
       
   263 	formatBuffer.Zero();
       
   264     formatBuffer.FormatList( aValueFormat, list );
       
   265     //
       
   266     AddItemUCL( aCaption, formatBuffer );
       
   267     }
       
   268 
       
   269 
       
   270 void CMemSpyEngineOutputList::AddItemHexL( const TDesC& aCaption, TUint aValue )
       
   271     {
       
   272     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewHexLC( aCaption, aValue );
       
   273     iItems.AppendL( item );
       
   274     CleanupStack::Pop( item );
       
   275     }
       
   276 
       
   277 
       
   278 void CMemSpyEngineOutputList::AddItemYesNoL( const TDesC& aCaption, TBool aYes )
       
   279     {
       
   280     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewYesNoLC( aCaption, aYes );
       
   281     iItems.AppendL( item );
       
   282     CleanupStack::Pop( item );
       
   283     }
       
   284 
       
   285 
       
   286 void CMemSpyEngineOutputList::AddItemTrueFalseL( const TDesC& aCaption, TBool aTrue )
       
   287     {
       
   288     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewTrueFalseLC( aCaption, aTrue );
       
   289     iItems.AppendL( item );
       
   290     CleanupStack::Pop( item );
       
   291     }
       
   292 
       
   293 
       
   294 void CMemSpyEngineOutputList::AddItemOnOffL( const TDesC& aCaption, TBool aOn )
       
   295     {
       
   296     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewOnOffLC( aCaption, aOn );
       
   297     iItems.AppendL( item );
       
   298     CleanupStack::Pop( item );
       
   299     }
       
   300 
       
   301 
       
   302 void CMemSpyEngineOutputList::AddItemPercentageL( const TDesC& aCaption, TInt aOneHundredPercentValue, TInt aValue )
       
   303     {
       
   304     const TMemSpyPercentText val( MemSpyEngineUtils::FormatPercentage( TReal( aOneHundredPercentValue ), TReal( aValue ) ) );
       
   305     AddItemL( aCaption, val );
       
   306     }
       
   307 
       
   308 
       
   309 void CMemSpyEngineOutputList::AddBlankItemL( TInt aRepetitions )
       
   310     {
       
   311     const TInt count = Count();
       
   312     InsertBlankItemL( count, aRepetitions );
       
   313     }
       
   314 
       
   315 
       
   316 void CMemSpyEngineOutputList::AddUnderlineForPreviousItemL( TChar aUnderlineCharacter, TInt aBlankItemCount )
       
   317     {
       
   318     const TInt count = iItems.Count();
       
   319     if  ( count > 0 )
       
   320         {
       
   321         InsertUnderlineForItemAtL( count - 1, aUnderlineCharacter, aBlankItemCount );
       
   322         }
       
   323     }
       
   324 
       
   325 
       
   326 void CMemSpyEngineOutputList::InsertItemL( TInt aPos, const TDesC& aCaption )
       
   327     {
       
   328     InsertItemL( aPos, aCaption, KNullDesC );
       
   329     }
       
   330 
       
   331 
       
   332 void CMemSpyEngineOutputList::InsertItemL( TInt aPos, const TDesC& aCaption, const TDesC& aValue )
       
   333     {
       
   334     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   335     iItems.InsertL( item, aPos );
       
   336     CleanupStack::Pop( item );
       
   337     }
       
   338 
       
   339 
       
   340 void CMemSpyEngineOutputList::InsertItemFormatUCL( TInt aPos, TRefByValue<const TDesC> aValueFormat, ... )
       
   341     {
       
   342 	VA_LIST list;
       
   343 	VA_START(list,aValueFormat);
       
   344 
       
   345     TPtr formatBuffer( FormatBuffer() );
       
   346 	formatBuffer.Zero();
       
   347     formatBuffer.FormatList( aValueFormat, list );
       
   348     //
       
   349     InsertItemL( aPos, formatBuffer, KNullDesC );
       
   350     }
       
   351 
       
   352 
       
   353 void CMemSpyEngineOutputList::InsertBlankItemL( TInt aPos, TInt aRepetitions )
       
   354     {
       
   355     while( aRepetitions-- > 0 )
       
   356         {
       
   357         InsertItemL( aPos, KMemSpyOutputListPseudoBlankItem, KMemSpyOutputListPseudoBlankItem );
       
   358         }
       
   359     }
       
   360 
       
   361 
       
   362 void CMemSpyEngineOutputList::InsertUnderlineForItemAtL( TInt aPos, TChar aUnderlineCharacter, TInt aBlankItemCount )
       
   363     {
       
   364     const CMemSpyEngineOutputListItem& item = Item( aPos );
       
   365     
       
   366     // Clean text
       
   367     HBufC* caption = MemSpyEngineUtils::CleanupTextLC( item.Caption() );
       
   368     //RDebug::Print( _L("CMemSpyEngineOutputList::AddUnderlineForPreviousItemL() - [%3d] caption: %S"), caption->Length(), caption );
       
   369     HBufC* value = MemSpyEngineUtils::CleanupTextLC( item.Value() );
       
   370     //RDebug::Print( _L("CMemSpyEngineOutputList::AddUnderlineForPreviousItemL() - [%3d] value: %S"), value->Length(), value );
       
   371     
       
   372     // Make underline descriptor
       
   373     TBuf<1> underline;
       
   374     underline.Append( aUnderlineCharacter );
       
   375 
       
   376     // Make underline items
       
   377     const TInt lenCaption = caption->Length();
       
   378     if ( lenCaption > 0 )
       
   379         {
       
   380         TPtr pText( caption->Des() );
       
   381         pText.Repeat( underline );
       
   382         }
       
   383 
       
   384     const TInt lenValue = value->Length();
       
   385     if ( lenValue > 0 )
       
   386         {
       
   387         TPtr pText( value->Des() );
       
   388         pText.Repeat( underline );
       
   389         }
       
   390 
       
   391     // Create new item
       
   392     InsertItemL( aPos + 1, *caption, *value );
       
   393 
       
   394     // Clean up
       
   395     CleanupStack::PopAndDestroy( 2, caption );
       
   396 
       
   397     // Make blank row if needed
       
   398     InsertBlankItemL( aPos + 2, aBlankItemCount );
       
   399     }
       
   400 
       
   401 
       
   402 TPtr& CMemSpyEngineOutputList::FormatBuffer()
       
   403     {
       
   404     if  ( iSink )
       
   405         {
       
   406         return iSink->FormatBuffer();
       
   407         }
       
   408     //
       
   409     return iFormatBufferPtr;
       
   410     }
       
   411 
       
   412 
       
   413 
       
   414 
       
   415