memspy/Engine/Source/Sink/MemSpyEngineOutputListItem.cpp
changeset 0 a03f92240627
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 "MemSpyEngineOutputListItem.h"
       
    19 
       
    20 // System includes
       
    21 #include <e32debug.h>
       
    22 
       
    23 // User includes
       
    24 #include <memspy/engine/memspyengineutils.h>
       
    25 
       
    26 // Constants
       
    27 const TInt KMemSpyNumericFormatBufferSize = 20;
       
    28 
       
    29 // Literal constants
       
    30 _LIT(KMemSpyNumericHexFormat, "0x%08x");
       
    31 _LIT(KMemSpyNumericUnsignedFormat, "%u");
       
    32 _LIT(KMemSpyNumericDecFormat, "%d");
       
    33 _LIT(KMemSpyNumericLongFormat, "%Ld");
       
    34 _LIT(KMemSpyCaptionYes, "Yes");
       
    35 _LIT(KMemSpyCaptionNo, "No");
       
    36 _LIT(KMemSpyCaptionOn, "On");
       
    37 _LIT(KMemSpyCaptionOff, "Off");
       
    38 _LIT(KMemSpyCaptionTrue, "True");
       
    39 _LIT(KMemSpyCaptionFalse, "False");
       
    40 
       
    41 
       
    42 
       
    43 CMemSpyEngineOutputListItem::CMemSpyEngineOutputListItem()
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 CMemSpyEngineOutputListItem::~CMemSpyEngineOutputListItem()
       
    49     {
       
    50     delete iCaption;
       
    51     delete iValue;
       
    52     delete iCombined;
       
    53     }
       
    54 
       
    55 
       
    56 void CMemSpyEngineOutputListItem::ConstructL( const TDesC& aCaption, const TDesC& aValue )
       
    57     {
       
    58     iCaption = aCaption.AllocL();
       
    59     iValue = aValue.AllocL();
       
    60     //
       
    61     UpdateCombinedL();
       
    62     }
       
    63 
       
    64 
       
    65 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewLC( const CMemSpyEngineOutputListItem& aCopyMe )
       
    66     {
       
    67     CMemSpyEngineOutputListItem* self = new(ELeave) CMemSpyEngineOutputListItem();
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL( aCopyMe.Caption(), aCopyMe.Value() );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewLC( const TDesC& aCaption )
       
    75     {
       
    76     CMemSpyEngineOutputListItem* self = new(ELeave) CMemSpyEngineOutputListItem();
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aCaption, KNullDesC );
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewLC( const TDesC& aCaption, const TDesC& aValue )
       
    84     {
       
    85     CMemSpyEngineOutputListItem* self = new(ELeave) CMemSpyEngineOutputListItem();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL( aCaption, aValue );
       
    88     return self;
       
    89     }
       
    90 
       
    91 
       
    92 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewLC( const TDesC& aCaption, TUint aValue )
       
    93     {
       
    94     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
    95     ret->SetUnsignedL( aValue );
       
    96     return ret;
       
    97     }
       
    98 
       
    99 
       
   100 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewHexLC( const TDesC& aCaption, TUint aValue )
       
   101     {
       
   102     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   103     ret->SetHexL( aValue );
       
   104     return ret;
       
   105     }
       
   106 
       
   107 
       
   108 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewDecimalLC( const TDesC& aCaption, TInt aValue )
       
   109     {
       
   110     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   111     ret->SetDecimalL( aValue );
       
   112     return ret;
       
   113     }
       
   114 
       
   115 
       
   116 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewLongLC( const TDesC& aCaption, const TInt64& aValue )
       
   117     {
       
   118     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   119     ret->SetLongL( aValue );
       
   120     return ret;
       
   121     }
       
   122 
       
   123 
       
   124 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewYesNoLC( const TDesC& aCaption, TBool aYes )
       
   125     {
       
   126     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   127     ret->SetYesNoL( aYes );
       
   128     return ret;
       
   129     }
       
   130 
       
   131 
       
   132 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewTrueFalseLC( const TDesC& aCaption, TBool aTrue )
       
   133     {
       
   134     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   135     ret->SetTrueFalseL( aTrue );
       
   136     return ret;
       
   137     }
       
   138 
       
   139 
       
   140 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewOnOffLC( const TDesC& aCaption, TBool aOn )
       
   141     {
       
   142     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   143     ret->SetOnOffL( aOn );
       
   144     return ret;
       
   145     }
       
   146 
       
   147 
       
   148 CMemSpyEngineOutputListItem* CMemSpyEngineOutputListItem::NewPercentageLC( const TDesC& aCaption, TInt aOneHundredPercentValue, TInt aValue )
       
   149     {
       
   150     CMemSpyEngineOutputListItem* ret = CMemSpyEngineOutputListItem::NewLC( aCaption );
       
   151     ret->SetPercentageL( aOneHundredPercentValue, aValue );
       
   152     return ret;
       
   153     }
       
   154 
       
   155 
       
   156 void CMemSpyEngineOutputListItem::SetValueL( const TDesC& aValue )
       
   157     {
       
   158     if  ( iValue == NULL )
       
   159         {
       
   160         iValue = aValue.AllocL();
       
   161         }
       
   162     else
       
   163         {
       
   164         if  ( iValue->Des().MaxLength() < aValue.Length() )
       
   165             {
       
   166             iValue = iValue->ReAllocL( aValue.Length() );
       
   167             }
       
   168             
       
   169         // Now its safe to assign new content
       
   170         *iValue = aValue;
       
   171         }
       
   172         
       
   173     UpdateCombinedL();
       
   174     }
       
   175 
       
   176 
       
   177 void CMemSpyEngineOutputListItem::SetUnsignedL( TUint aValue )
       
   178     {
       
   179     TBuf<KMemSpyNumericFormatBufferSize> val;
       
   180     val.Format( KMemSpyNumericUnsignedFormat, aValue );
       
   181     SetValueL( val );
       
   182     }
       
   183 
       
   184 
       
   185 void CMemSpyEngineOutputListItem::SetHexL( TUint aValue )
       
   186     {
       
   187     TBuf<KMemSpyNumericFormatBufferSize> val;
       
   188     val.Format( KMemSpyNumericHexFormat, aValue );
       
   189     SetValueL( val );
       
   190     }
       
   191 
       
   192 
       
   193 void CMemSpyEngineOutputListItem::SetDecimalL( TInt aValue )
       
   194     {
       
   195     TBuf<KMemSpyNumericFormatBufferSize> val;
       
   196     val.Format( KMemSpyNumericDecFormat, aValue );
       
   197     SetValueL( val );
       
   198     }
       
   199 
       
   200 
       
   201 void CMemSpyEngineOutputListItem::SetLongL( const TInt64& aValue )
       
   202     {
       
   203     TBuf<KMemSpyNumericFormatBufferSize> val;
       
   204     val.Format( KMemSpyNumericLongFormat, aValue );
       
   205     SetValueL( val );
       
   206     }
       
   207 
       
   208 
       
   209 void CMemSpyEngineOutputListItem::SetYesNoL( TBool aYes )
       
   210     {
       
   211     if  ( aYes )
       
   212         {
       
   213         SetValueL( KMemSpyCaptionYes );
       
   214         }
       
   215     else
       
   216         {
       
   217         SetValueL( KMemSpyCaptionNo );
       
   218         }
       
   219     }
       
   220 
       
   221 
       
   222 void CMemSpyEngineOutputListItem::SetTrueFalseL( TBool aTrue )
       
   223     {
       
   224     if  ( aTrue )
       
   225         {
       
   226         SetValueL( KMemSpyCaptionTrue );
       
   227         }
       
   228     else
       
   229         {
       
   230         SetValueL( KMemSpyCaptionFalse );
       
   231         }
       
   232     }
       
   233 
       
   234 
       
   235 void CMemSpyEngineOutputListItem::SetOnOffL( TBool aOn )
       
   236     {
       
   237     if  ( aOn )
       
   238         {
       
   239         SetValueL( KMemSpyCaptionOn );
       
   240         }
       
   241     else
       
   242         {
       
   243         SetValueL( KMemSpyCaptionOff );
       
   244         }
       
   245     }
       
   246 
       
   247 
       
   248 void CMemSpyEngineOutputListItem::SetPercentageL( TInt aOneHundredPercentValue, TInt aValue )
       
   249     {
       
   250     const TMemSpyPercentText val( MemSpyEngineUtils::FormatPercentage( TReal( aOneHundredPercentValue ), TReal( aValue ) ) );
       
   251     SetValueL( val );
       
   252     }
       
   253 
       
   254 
       
   255 void CMemSpyEngineOutputListItem::UpdateCombinedL()
       
   256     {
       
   257     const TInt requiredLength = Caption().Length() + Value().Length() + 10;
       
   258     //
       
   259     if  ( iCombined == NULL )
       
   260         {
       
   261         iCombined = HBufC::NewL( requiredLength );
       
   262         }
       
   263     else if ( iCombined->Des().MaxLength() < requiredLength )
       
   264         {
       
   265         iCombined = iCombined->ReAllocL( requiredLength );
       
   266         }
       
   267         
       
   268     TPtr pCombined( iCombined->Des() );
       
   269     pCombined.Zero();
       
   270     pCombined.Append( _L("\t") );
       
   271     pCombined.Append( Caption() );
       
   272     pCombined.Append( _L("\t\t") );
       
   273     pCombined.Append( Value() );
       
   274     }
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280