crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/BasicTypes/SymMask.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     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 using System;
       
    18 using System.Collections.Generic;
       
    19 using System.Text;
       
    20 
       
    21 namespace SymbianUtils.BasicTypes
       
    22 {
       
    23     public class SymMask
       
    24     {
       
    25         #region Enumerations
       
    26         public enum TShiftDirection
       
    27         {
       
    28             ELeft = 0,
       
    29             ERight
       
    30         }
       
    31         #endregion
       
    32 
       
    33         #region Constructors
       
    34         public SymMask( string aBinary )
       
    35         {
       
    36             iMaskingBits = SymBitUtils.CreateMask( aBinary, out iExpectedValueAfterMasking );
       
    37         }
       
    38 
       
    39         public SymMask( string aBinary, TShiftDirection aDirection, uint aCount )
       
    40             : this( aBinary )
       
    41         {
       
    42             if ( aDirection == TShiftDirection.ELeft )
       
    43             {
       
    44                 iShift = -Convert.ToInt32( aCount );
       
    45             }
       
    46             else
       
    47             {
       
    48                 iShift = Convert.ToInt32( aCount );
       
    49             }
       
    50         }
       
    51 
       
    52         public SymMask( uint aMask )
       
    53             : this( aMask, aMask, TShiftDirection.ELeft, 0 )
       
    54         {
       
    55         }
       
    56 
       
    57         public SymMask( uint aMask, TShiftDirection aDirection, int aCount )
       
    58             : this( aMask, aMask, aDirection, aCount )
       
    59         {
       
    60         }
       
    61 
       
    62         public SymMask( uint aMask, uint aValue, TShiftDirection aDirection, int aCount )
       
    63         {
       
    64             iMaskingBits = aMask;
       
    65             iExpectedValueAfterMasking = aValue;
       
    66             if ( aDirection == TShiftDirection.ELeft )
       
    67             {
       
    68                 iShift = -Convert.ToInt32( aCount );
       
    69             }
       
    70             else
       
    71             {
       
    72                 iShift = Convert.ToInt32( aCount );
       
    73             }
       
    74         }
       
    75         #endregion
       
    76 
       
    77         #region API
       
    78         public bool IsMatch( uint aValue )
       
    79         {
       
    80             //      101 0 000000000000000000000000
       
    81             //      111 0 000000000000000000000000
       
    82             // 1110 010 1 100111110000000000111100
       
    83             bool ret = ( aValue & iMaskingBits ) == iExpectedValueAfterMasking;
       
    84             return ret;
       
    85         }
       
    86 
       
    87         public uint Apply( uint aValue )
       
    88         {
       
    89             uint ret = ( iMaskingBits & aValue );
       
    90             if ( iShift != 0 )
       
    91             {
       
    92                 if ( iShift < 0 )
       
    93                 {
       
    94                     ret <<= iShift;
       
    95                 }
       
    96                 else
       
    97                 {
       
    98                     ret >>= iShift;
       
    99                 }
       
   100             }
       
   101             return ret;
       
   102         }
       
   103         #endregion
       
   104 
       
   105         #region Properties
       
   106         #endregion
       
   107 
       
   108         #region Operators
       
   109         #endregion
       
   110 
       
   111         #region From System.Object
       
   112         #endregion
       
   113 
       
   114         #region Internal methods
       
   115         #endregion
       
   116 
       
   117         #region Data members
       
   118         private int iShift = 0;
       
   119         private uint iMaskingBits = 0;
       
   120         private uint iExpectedValueAfterMasking = 0;
       
   121         #endregion
       
   122     }
       
   123 }