crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/Resolver/CodeSegResolverEntryCollection.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 
       
    21 namespace SymbolLib.CodeSegDef
       
    22 {
       
    23 	public class CodeSegResolverEntryCollection : IEnumerable<CodeSegResolverEntry>
       
    24 	{
       
    25 		#region Constructors & destructor
       
    26 		public CodeSegResolverEntryCollection()
       
    27 			: this( 10 )
       
    28 		{
       
    29 		}
       
    30 
       
    31         public CodeSegResolverEntryCollection( int aGranularity )
       
    32 		{
       
    33             iEntries = new List<CodeSegResolverEntry>( aGranularity );
       
    34 		}
       
    35 		#endregion
       
    36 
       
    37 		#region API
       
    38 		public void Reset()
       
    39 		{
       
    40 			iEntries.Clear();
       
    41 		}
       
    42 
       
    43         public void Add( CodeSegResolverEntry aNewEntry )
       
    44 		{
       
    45             if ( aNewEntry.ImageFileName.Length == 0 )
       
    46             {
       
    47                 throw new ArgumentException( "Invalid code seg definition entry" );
       
    48             }
       
    49 
       
    50             // Our check-for-exists predicate
       
    51             Predicate<CodeSegResolverEntry> existsPredicate = delegate( CodeSegResolverEntry aEntry )
       
    52             {
       
    53                 return aEntry.ImageFileName.ToLower() == aNewEntry.ImageFileName.ToLower();
       
    54             };
       
    55 
       
    56             // Check whether there is already an entry that matches
       
    57             if ( !iEntries.Exists( existsPredicate ) )
       
    58             {
       
    59                 iEntries.Add( aNewEntry );
       
    60             }
       
    61             else
       
    62             {
       
    63 #if TRACE_RESOLVER
       
    64                 System.Diagnostics.Debug.WriteLine( "IGNORING DUPE CodeSegDefinition: " + aNewEntry.ToString() );
       
    65 #endif
       
    66             }
       
    67 		}
       
    68 
       
    69         public void Remove( CodeSegResolverEntry aRemoveEntry )
       
    70         {
       
    71             if  ( String.IsNullOrEmpty( aRemoveEntry.ImageFileName ) )
       
    72             {
       
    73                 // Remove by environment file name
       
    74                 Predicate<CodeSegResolverEntry> matchPredicate = delegate( CodeSegResolverEntry aEntry )
       
    75                 {
       
    76                     return aEntry.EnvironmentFileName.ToLower() == aRemoveEntry.EnvironmentFileName.ToLower();
       
    77                 };
       
    78                 iEntries.RemoveAll( matchPredicate );
       
    79             }
       
    80             else
       
    81             {
       
    82                 // Remove by phone file name
       
    83                 Predicate<CodeSegResolverEntry> matchPredicate = delegate( CodeSegResolverEntry aEntry )
       
    84                 {
       
    85                     return aEntry.ImageFileName.ToLower() == aRemoveEntry.ImageFileName.ToLower();
       
    86                 };
       
    87                 iEntries.RemoveAll( matchPredicate );
       
    88             }
       
    89         }
       
    90 
       
    91         public int IndexOf( CodeSegResolverEntry aEntry )
       
    92         {
       
    93             int index = -1;
       
    94             //
       
    95             int count = iEntries.Count;
       
    96             for( int i=0; i<count; i++ )
       
    97             {
       
    98                 CodeSegResolverEntry entry = iEntries[ i ];
       
    99                 //
       
   100                 if ( entry.EnvironmentFileNameAndPath.ToLower() == aEntry.EnvironmentFileNameAndPath.ToLower() )
       
   101                 {
       
   102                     index = i;
       
   103                     break;
       
   104                 }
       
   105                 ++i;
       
   106             }
       
   107             //
       
   108             return index;
       
   109         }
       
   110 
       
   111         public void Sort()
       
   112         {
       
   113             iEntries.Sort( new Comparison<CodeSegResolverEntry>( Compare ) );
       
   114         }
       
   115 
       
   116         public CodeSegResolverEntry FindByCodeSegmentFileNameAndPath( string aImageCodeSegmentFileNameAndPath )
       
   117 		{
       
   118             CodeSegResolverEntry temp = new CodeSegResolverEntry( string.Empty, aImageCodeSegmentFileNameAndPath );
       
   119 			int index = iEntries.IndexOf( temp );
       
   120 
       
   121 			int x = 0;
       
   122 			if	( x != 0 )
       
   123 			{
       
   124 				int count = iEntries.Count;
       
   125 				for( int i=0; i<count; i++ )
       
   126 				{
       
   127                     CodeSegResolverEntry e = this[ i ];
       
   128 #if TRACE_RESOLVER
       
   129 					System.Diagnostics.Debug.WriteLine( "Entry = ENV[ " + e.EnvironmentFileName + " => " + e.EnvironmentFileNameAndPath + " ] IMG[ " + e.ImageFileName + " => " + e.ImageFileNameAndPath + " ]" );
       
   130 #endif
       
   131 
       
   132 				}
       
   133 			}
       
   134 
       
   135 			if	( index >= 0 && index < Count )
       
   136 			{
       
   137 				temp = this[ index ];
       
   138 			}
       
   139 			else
       
   140 			{
       
   141 				// Not found
       
   142 				temp = null;
       
   143 			}
       
   144 			//
       
   145 			return temp;
       
   146 		}
       
   147 		#endregion
       
   148 
       
   149 		#region Properties
       
   150 		public int Count
       
   151 		{
       
   152 			get { return iEntries.Count; }
       
   153 		}
       
   154 
       
   155         public CodeSegResolverEntry this[ int aIndex ]
       
   156 		{
       
   157 			get { return iEntries[ aIndex ]; }
       
   158 		}
       
   159 		#endregion
       
   160 
       
   161         #region IEnumerable<CodeSegResolverEntry> Members
       
   162         IEnumerator IEnumerable.GetEnumerator()
       
   163         {
       
   164             foreach ( CodeSegResolverEntry entry in iEntries )
       
   165             {
       
   166                 yield return entry;
       
   167             }
       
   168         }
       
   169 
       
   170         IEnumerator<CodeSegResolverEntry> IEnumerable<CodeSegResolverEntry>.GetEnumerator()
       
   171         {
       
   172             foreach ( CodeSegResolverEntry entry in iEntries )
       
   173             {
       
   174                 yield return entry;
       
   175             }
       
   176         }
       
   177         #endregion
       
   178 
       
   179         #region Internal methods
       
   180         private static int Compare( CodeSegResolverEntry aLeft, CodeSegResolverEntry aRight )
       
   181         {
       
   182             return aLeft.EnvironmentFileNameAndPath.CompareTo( aRight.EnvironmentFileNameAndPath );
       
   183         }
       
   184         #endregion
       
   185 
       
   186         #region Data members
       
   187         private readonly List<CodeSegResolverEntry> iEntries;
       
   188 		#endregion
       
   189     }
       
   190 }