crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/Sources/Symbol/Collection/SymbolsForBinaryCollection.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;
       
    19 using System.Collections.Generic;
       
    20 using SymbolLib.Sources.Symbol.File;
       
    21 using SymbolLib.Sources.Symbol.Comparison;
       
    22 
       
    23 namespace SymbolLib.Sources.Symbol.Collection
       
    24 {
       
    25     public class SymbolsForBinaryCollection : IEnumerable<SymbolsForBinary>
       
    26     {
       
    27         #region Constructors & destructor
       
    28         public SymbolsForBinaryCollection()
       
    29             : this( 50 )
       
    30         {
       
    31         }
       
    32 
       
    33         public SymbolsForBinaryCollection( int aGranularity )
       
    34         {
       
    35             iSymbolsForBinaries = new List<SymbolsForBinary>( aGranularity );
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region API
       
    40         public void Clear()
       
    41         {
       
    42             lock ( iSymbolsForBinaries )
       
    43             {
       
    44                 iSymbolsForBinaries.Clear();
       
    45             }
       
    46         }
       
    47 
       
    48         public void Add( SymbolsForBinary aEntry )
       
    49         {
       
    50             lock ( iSymbolsForBinaries )
       
    51             {
       
    52                 if ( !iSymbolsForBinaries.Contains( aEntry ) )
       
    53                 {
       
    54                     iSymbolsForBinaries.Add( aEntry );
       
    55                 }
       
    56             }
       
    57         }
       
    58 
       
    59         public void Add( SymbolsForBinaryCollection aCollection )
       
    60         {
       
    61             foreach ( SymbolsForBinary entry in aCollection )
       
    62             {
       
    63                 Add( entry );
       
    64             }
       
    65         }
       
    66 
       
    67         public void Remove( SymbolsForBinary aFile )
       
    68         {
       
    69             iSymbolsForBinaries.Remove( aFile );
       
    70         }
       
    71 
       
    72         public void RemoveLast()
       
    73         {
       
    74             // Dump the last collection - only ever called when
       
    75             // the parser detects a collection with zero entries
       
    76             lock ( iSymbolsForBinaries )
       
    77             {
       
    78                 if ( Count == 0 )
       
    79                 {
       
    80                     throw new ArgumentOutOfRangeException( "No last entry to remove" );
       
    81                 }
       
    82 
       
    83                 iSymbolsForBinaries.RemoveAt( Count - 1 );
       
    84             }
       
    85         }
       
    86 
       
    87         public void Sort()
       
    88         {
       
    89             // Sort the collections into some kind of address order
       
    90             if ( Count > 0 )
       
    91             {
       
    92                 SymbolsForBinaryCompareByAddress comparer = new SymbolsForBinaryCompareByAddress();
       
    93                 try
       
    94                 {
       
    95                     lock ( iSymbolsForBinaries )
       
    96                     {
       
    97                         iSymbolsForBinaries.Sort( comparer );
       
    98                     }
       
    99                 }
       
   100                 catch ( Exception )
       
   101                 {
       
   102                     SymbianUtils.SymDebug.SymDebugger.Break();
       
   103                 }
       
   104             }
       
   105         }
       
   106         #endregion
       
   107 
       
   108         #region Properties
       
   109         public int Count
       
   110         {
       
   111             get { return iSymbolsForBinaries.Count; }
       
   112         }
       
   113 
       
   114         public SymbolsForBinary this[ int aIndex ]
       
   115         {
       
   116             get 
       
   117             {
       
   118                 lock ( iSymbolsForBinaries )
       
   119                 {
       
   120                     return iSymbolsForBinaries[ aIndex ];
       
   121                 }
       
   122             }
       
   123         }
       
   124 
       
   125         public SymbolsForBinary LastCollection
       
   126         {
       
   127             get
       
   128             {
       
   129                 lock ( iSymbolsForBinaries )
       
   130                 {
       
   131                     SymbolsForBinary ret = this[ Count - 1 ];
       
   132                     return ret;
       
   133                 }
       
   134             }
       
   135         }
       
   136         #endregion
       
   137 
       
   138         #region From IEnumerable
       
   139         IEnumerator IEnumerable.GetEnumerator()
       
   140         {
       
   141             return new SymbolsForBinaryCollectionEnumerator( this );
       
   142         }
       
   143 
       
   144         IEnumerator<SymbolsForBinary> IEnumerable<SymbolsForBinary>.GetEnumerator()
       
   145         {
       
   146             return new SymbolsForBinaryCollectionEnumerator( this );
       
   147         }
       
   148         #endregion
       
   149 
       
   150         #region Data members
       
   151         private readonly List<SymbolsForBinary> iSymbolsForBinaries;
       
   152         #endregion
       
   153     }
       
   154 }