memspy/Engine/Source/Sink/MemSpyEngineOutputList.cpp
changeset 51 98307c651589
parent 42 0ff24a8f6ca2
child 52 c2f44e33b468
equal deleted inserted replaced
42:0ff24a8f6ca2 51:98307c651589
     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 			if (item->Value().Length())
       
   106 				{
       
   107 	            maxLengthCaption = Max( maxLengthCaption, item->Caption().Length() );
       
   108 	            maxLengthValue = Max( maxLengthValue, item->Value().Length() );
       
   109 				}
       
   110 			else
       
   111 				{
       
   112 				// If something doesn't have a value (ie it's a section header, represented as just a caption) then the caption
       
   113 				// shouldn't be factored into the maxcaptionlength. But consider it in maxlengthValue to make sure we actually
       
   114 				// make the overall buffers big enough
       
   115 				maxLengthValue = Max( maxLengthValue, item->Caption().Length() );
       
   116 				}
       
   117             }
       
   118 
       
   119         // Second pass - real this time - to print the values
       
   120         HBufC* line = HBufC::NewLC( ( maxLengthCaption + maxLengthValue ) + 20 );
       
   121         TPtr pLine( line->Des() );
       
   122         //
       
   123         for( TInt i=0; i<count; i++ )
       
   124             {
       
   125             const CMemSpyEngineOutputListItem* item = iItems[ i ];
       
   126 
       
   127             // Remove initial tabs in caption
       
   128             HBufC* caption = MemSpyEngineUtils::CleanupTextLC( item->Caption() );
       
   129         
       
   130             // Create value item & replace any further tabs
       
   131             HBufC* value = MemSpyEngineUtils::CleanupTextLC( item->Value() );
       
   132 
       
   133             // Now format the final line, with padding.
       
   134 			if (value->Length()) 
       
   135 				{
       
   136 	            pLine.Justify( *caption, maxLengthCaption + 3, ELeft, TChar(' ') );
       
   137 				}
       
   138 			else
       
   139 				{
       
   140 				// items without value (ie just captions, ie section headers) aren't constrained by the maxLengthCaption restriction
       
   141 				pLine.Copy(*caption);
       
   142 				}
       
   143             pLine.Append( *value );
       
   144             CleanupStack::PopAndDestroy( 2, caption );
       
   145 
       
   146             // Sink output
       
   147             aSink.OutputLineL( pLine );
       
   148             }
       
   149         //
       
   150         CleanupStack::PopAndDestroy( line );
       
   151         }
       
   152     }
       
   153 
       
   154 
       
   155 CMemSpyEngineOutputListItem& CMemSpyEngineOutputList::Item( TInt aPos )
       
   156     {
       
   157     CMemSpyEngineOutputListItem* ret = iItems[ aPos ];
       
   158     return *ret;
       
   159     }
       
   160 
       
   161 
       
   162 const CMemSpyEngineOutputListItem& CMemSpyEngineOutputList::Item( TInt aPos ) const
       
   163     {
       
   164     const CMemSpyEngineOutputListItem* ret = iItems[ aPos ];
       
   165     return *ret;
       
   166     }
       
   167 
       
   168 
       
   169 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption )
       
   170     {
       
   171     AddItemL( aCaption, KNullDesC );
       
   172     }
       
   173 
       
   174 
       
   175 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, const TDesC& aValue )
       
   176     {
       
   177     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   178     iItems.AppendL( item );
       
   179     CleanupStack::Pop( item );
       
   180     }
       
   181 
       
   182 
       
   183 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TInt aValue )
       
   184     {
       
   185     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewDecimalLC( aCaption, aValue );
       
   186     iItems.AppendL( item );
       
   187     CleanupStack::Pop( item );
       
   188     }
       
   189 
       
   190 
       
   191 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint aValue )
       
   192     {
       
   193     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewDecimalLC( aCaption, aValue );
       
   194     iItems.AppendL( item );
       
   195     CleanupStack::Pop( item );
       
   196     }
       
   197 
       
   198 
       
   199 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, const TInt64& aValue )
       
   200     {
       
   201     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLongLC( aCaption, aValue );
       
   202     iItems.AppendL( item );
       
   203     CleanupStack::Pop( item );
       
   204     }
       
   205 
       
   206 
       
   207 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TAny* aValue )
       
   208     {
       
   209     AddItemHexL( aCaption, (TUint) aValue );
       
   210     }
       
   211 
       
   212 
       
   213 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint* aValue )
       
   214     {
       
   215     AddItemHexL( aCaption, (TUint) aValue );
       
   216     }
       
   217 
       
   218 
       
   219 void CMemSpyEngineOutputList::AddItemL( const TDesC& aCaption, TUint8* aValue )
       
   220     {
       
   221     AddItemHexL( aCaption, (TUint) aValue );
       
   222     }
       
   223 
       
   224 
       
   225 void CMemSpyEngineOutputList::AddItemFormatL( TRefByValue<const TDesC> aFormat, ... )
       
   226     {
       
   227 	VA_LIST list;
       
   228 	VA_START(list,aFormat);
       
   229 
       
   230     TPtr formatBuffer( FormatBuffer() );
       
   231 	formatBuffer.Zero();
       
   232     formatBuffer.FormatList( aFormat, list );
       
   233     //
       
   234     AddItemL( formatBuffer, KNullDesC );
       
   235     }
       
   236 
       
   237 
       
   238 void CMemSpyEngineOutputList::AddItemFormatL( const TDesC& aCaption, TRefByValue<const TDesC> aValueFormat, ... )
       
   239     {
       
   240 	VA_LIST list;
       
   241 	VA_START(list,aValueFormat);
       
   242 
       
   243     TPtr formatBuffer( FormatBuffer() );
       
   244 	formatBuffer.Zero();
       
   245     formatBuffer.FormatList( aValueFormat, list );
       
   246     //
       
   247     AddItemL( aCaption, formatBuffer );
       
   248     }
       
   249 
       
   250 
       
   251 void CMemSpyEngineOutputList::AddItemFormatUCL( TRefByValue<const TDesC> aFormat, ... )
       
   252     {
       
   253 	VA_LIST list;
       
   254 	VA_START(list,aFormat);
       
   255 
       
   256     TPtr formatBuffer( FormatBuffer() );
       
   257 	formatBuffer.Zero();
       
   258     formatBuffer.FormatList( aFormat, list );
       
   259     //
       
   260     AddItemUCL( formatBuffer, KNullDesC );
       
   261     }
       
   262 
       
   263 
       
   264 void CMemSpyEngineOutputList::AddItemUCL( const TDesC& aCaption, const TDesC& aValue )
       
   265     {
       
   266     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   267     iItems.AppendL( item );
       
   268     CleanupStack::Pop( item );
       
   269     //
       
   270     item->iCaption->Des().UpperCase();
       
   271     item->UpdateCombinedL();
       
   272     }
       
   273 
       
   274 
       
   275 void CMemSpyEngineOutputList::AddItemFormatUCL( const TDesC& aCaption, TRefByValue<const TDesC> aValueFormat, ... )
       
   276     {
       
   277 	VA_LIST list;
       
   278 	VA_START(list,aValueFormat);
       
   279 
       
   280     TPtr formatBuffer( FormatBuffer() );
       
   281 	formatBuffer.Zero();
       
   282     formatBuffer.FormatList( aValueFormat, list );
       
   283     //
       
   284     AddItemUCL( aCaption, formatBuffer );
       
   285     }
       
   286 
       
   287 
       
   288 void CMemSpyEngineOutputList::AddItemHexL( const TDesC& aCaption, TUint aValue )
       
   289     {
       
   290     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewHexLC( aCaption, aValue );
       
   291     iItems.AppendL( item );
       
   292     CleanupStack::Pop( item );
       
   293     }
       
   294 
       
   295 
       
   296 void CMemSpyEngineOutputList::AddItemYesNoL( const TDesC& aCaption, TBool aYes )
       
   297     {
       
   298     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewYesNoLC( aCaption, aYes );
       
   299     iItems.AppendL( item );
       
   300     CleanupStack::Pop( item );
       
   301     }
       
   302 
       
   303 
       
   304 void CMemSpyEngineOutputList::AddItemTrueFalseL( const TDesC& aCaption, TBool aTrue )
       
   305     {
       
   306     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewTrueFalseLC( aCaption, aTrue );
       
   307     iItems.AppendL( item );
       
   308     CleanupStack::Pop( item );
       
   309     }
       
   310 
       
   311 
       
   312 void CMemSpyEngineOutputList::AddItemOnOffL( const TDesC& aCaption, TBool aOn )
       
   313     {
       
   314     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewOnOffLC( aCaption, aOn );
       
   315     iItems.AppendL( item );
       
   316     CleanupStack::Pop( item );
       
   317     }
       
   318 
       
   319 
       
   320 void CMemSpyEngineOutputList::AddItemPercentageL( const TDesC& aCaption, TInt aOneHundredPercentValue, TInt aValue )
       
   321     {
       
   322     const TMemSpyPercentText val( MemSpyEngineUtils::FormatPercentage( TReal( aOneHundredPercentValue ), TReal( aValue ) ) );
       
   323     AddItemL( aCaption, val );
       
   324     }
       
   325 
       
   326 
       
   327 void CMemSpyEngineOutputList::AddBlankItemL( TInt aRepetitions )
       
   328     {
       
   329     const TInt count = Count();
       
   330     InsertBlankItemL( count, aRepetitions );
       
   331     }
       
   332 
       
   333 
       
   334 void CMemSpyEngineOutputList::AddUnderlineForPreviousItemL( TChar aUnderlineCharacter, TInt aBlankItemCount )
       
   335     {
       
   336     const TInt count = iItems.Count();
       
   337     if  ( count > 0 )
       
   338         {
       
   339         InsertUnderlineForItemAtL( count - 1, aUnderlineCharacter, aBlankItemCount );
       
   340         }
       
   341     }
       
   342 
       
   343 
       
   344 void CMemSpyEngineOutputList::InsertItemL( TInt aPos, const TDesC& aCaption )
       
   345     {
       
   346     InsertItemL( aPos, aCaption, KNullDesC );
       
   347     }
       
   348 
       
   349 
       
   350 void CMemSpyEngineOutputList::InsertItemL( TInt aPos, const TDesC& aCaption, const TDesC& aValue )
       
   351     {
       
   352     CMemSpyEngineOutputListItem* item = CMemSpyEngineOutputListItem::NewLC( aCaption, aValue );
       
   353     iItems.InsertL( item, aPos );
       
   354     CleanupStack::Pop( item );
       
   355     }
       
   356 
       
   357 
       
   358 void CMemSpyEngineOutputList::InsertItemFormatUCL( TInt aPos, TRefByValue<const TDesC> aValueFormat, ... )
       
   359     {
       
   360 	VA_LIST list;
       
   361 	VA_START(list,aValueFormat);
       
   362 
       
   363     TPtr formatBuffer( FormatBuffer() );
       
   364 	formatBuffer.Zero();
       
   365     formatBuffer.FormatList( aValueFormat, list );
       
   366     //
       
   367     InsertItemL( aPos, formatBuffer, KNullDesC );
       
   368     }
       
   369 
       
   370 
       
   371 void CMemSpyEngineOutputList::InsertBlankItemL( TInt aPos, TInt aRepetitions )
       
   372     {
       
   373     while( aRepetitions-- > 0 )
       
   374         {
       
   375         InsertItemL( aPos, KMemSpyOutputListPseudoBlankItem, KMemSpyOutputListPseudoBlankItem );
       
   376         }
       
   377     }
       
   378 
       
   379 
       
   380 void CMemSpyEngineOutputList::InsertUnderlineForItemAtL( TInt aPos, TChar aUnderlineCharacter, TInt aBlankItemCount )
       
   381     {
       
   382     const CMemSpyEngineOutputListItem& item = Item( aPos );
       
   383     
       
   384     // Clean text
       
   385     HBufC* caption = MemSpyEngineUtils::CleanupTextLC( item.Caption() );
       
   386     //RDebug::Print( _L("CMemSpyEngineOutputList::AddUnderlineForPreviousItemL() - [%3d] caption: %S"), caption->Length(), caption );
       
   387     HBufC* value = MemSpyEngineUtils::CleanupTextLC( item.Value() );
       
   388     //RDebug::Print( _L("CMemSpyEngineOutputList::AddUnderlineForPreviousItemL() - [%3d] value: %S"), value->Length(), value );
       
   389     
       
   390     // Make underline descriptor
       
   391     TBuf<1> underline;
       
   392     underline.Append( aUnderlineCharacter );
       
   393 
       
   394     // Make underline items
       
   395     const TInt lenCaption = caption->Length();
       
   396     if ( lenCaption > 0 )
       
   397         {
       
   398         TPtr pText( caption->Des() );
       
   399         pText.Repeat( underline );
       
   400         }
       
   401 
       
   402     const TInt lenValue = value->Length();
       
   403     if ( lenValue > 0 )
       
   404         {
       
   405         TPtr pText( value->Des() );
       
   406         pText.Repeat( underline );
       
   407         }
       
   408 
       
   409     // Create new item
       
   410     InsertItemL( aPos + 1, *caption, *value );
       
   411 
       
   412     // Clean up
       
   413     CleanupStack::PopAndDestroy( 2, caption );
       
   414 
       
   415     // Make blank row if needed
       
   416     InsertBlankItemL( aPos + 2, aBlankItemCount );
       
   417     }
       
   418 
       
   419 
       
   420 TPtr& CMemSpyEngineOutputList::FormatBuffer()
       
   421     {
       
   422     if  ( iSink )
       
   423         {
       
   424         return iSink->FormatBuffer();
       
   425         }
       
   426     //
       
   427     return iFormatBufferPtr;
       
   428     }
       
   429 
       
   430 
       
   431 
       
   432 
       
   433