crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianETMLib/Common/Buffer/ETBufferBase.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 
       
    18 using System;
       
    19 using System.Collections.Generic;
       
    20 using System.IO;
       
    21 using System.Text;
       
    22 using SymbianUtils.BasicTypes;
       
    23 using SymbianETMLib.Common.Types;
       
    24 using SymbianETMLib.Common.Exception;
       
    25 
       
    26 namespace SymbianETMLib.Common.Buffer
       
    27 {
       
    28     public abstract class ETBufferBase
       
    29     {
       
    30         #region Constructors
       
    31         protected ETBufferBase()
       
    32         {
       
    33         }
       
    34 
       
    35         protected ETBufferBase( string aFileName )
       
    36         {
       
    37             byte[] buffer = File.ReadAllBytes( aFileName );
       
    38             AddRange( buffer );
       
    39         }
       
    40         #endregion
       
    41 
       
    42         #region API
       
    43         public void Clear()
       
    44         {
       
    45             iData.Clear();
       
    46         }
       
    47 
       
    48         public void AddRange( IEnumerable<byte> aBytes )
       
    49         {
       
    50             iData.AddRange( aBytes );
       
    51         }
       
    52 
       
    53         public void PushBack( SymByte aByte )
       
    54         {
       
    55             iData.Insert( 0, aByte.Value );
       
    56         }
       
    57 
       
    58         public SymByte Dequeue()
       
    59         {
       
    60             if ( IsEmpty )
       
    61             {
       
    62                 throw new ETMException( "ERROR - buffer is empty" );
       
    63             }
       
    64             //
       
    65             byte head = iData[ 0 ];
       
    66             iData.RemoveAt( 0 );
       
    67             return new SymByte( head );
       
    68         }
       
    69         #endregion
       
    70 
       
    71         #region Properties
       
    72         public bool IsEmpty
       
    73         {
       
    74             get { return iData.Count == 0; }
       
    75         }
       
    76 
       
    77         public int Count
       
    78         {
       
    79             get { return iData.Count; }
       
    80         }
       
    81         #endregion
       
    82 
       
    83         #region Internal methods
       
    84         protected List<byte> Data
       
    85         {
       
    86             get { return iData; }
       
    87             set { iData = value; }
       
    88         }
       
    89         #endregion
       
    90 
       
    91         #region Data members
       
    92         List<byte> iData = new List<byte>();
       
    93         #endregion
       
    94     }
       
    95 }