crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Common/Objects/SymIncludeDirectory.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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;
       
    20 using SymBuildParsingLib.Utils;
       
    21 
       
    22 namespace SymBuildParsingLib.Common.Objects
       
    23 {
       
    24 	public class SymIncludeDirectory
       
    25 	{
       
    26 		#region Constructors & destructor
       
    27 		public SymIncludeDirectory()
       
    28 		{
       
    29 		}
       
    30 
       
    31 		public SymIncludeDirectory( SymIncludeDirectory aCopy )
       
    32 		{
       
    33 		}
       
    34 		#endregion
       
    35 
       
    36 		#region API
       
    37 		public void Add( SymIncludeDefinition aDefinition )
       
    38 		{
       
    39 			string location = aDefinition.Location;
       
    40 			if	( location == String.Empty )
       
    41 			{
       
    42 				throw new ArgumentException( "Include location cannot be null when adding to include directory", aDefinition.ToString() );
       
    43 			}
       
    44 			
       
    45 			if	( iIncludes[ location ] == null )
       
    46 			{
       
    47 				iIncludes.Add( location, aDefinition );
       
    48 			}
       
    49 		}
       
    50 
       
    51 		public string ResolveFileName( SymIncludeDefinition aDefinition )
       
    52 		{
       
    53 			// First check against the specified type for an exact match...
       
    54 			string location = aDefinition.Location;
       
    55 			string ret = FindInSpecifiedIncludeEntries( location, aDefinition.Type );
       
    56 
       
    57 			if  ( ret == string.Empty )
       
    58 			{
       
    59 				// Try the other remaining type
       
    60 				SymIncludeDefinition.TType type = SymIncludeDefinition.TType.ETypeUser;
       
    61 
       
    62 				if	( aDefinition.Type == SymIncludeDefinition.TType.ETypeUser )
       
    63 				{
       
    64 					type = SymIncludeDefinition.TType.ETypeSystem;
       
    65 				}
       
    66 				else
       
    67 				{
       
    68 					type = SymIncludeDefinition.TType.ETypeUser;
       
    69 				}
       
    70 
       
    71 				ret = FindInSpecifiedIncludeEntries( location, type );
       
    72 			}
       
    73 			//
       
    74 			return ret;
       
    75 		}
       
    76 		#endregion
       
    77 
       
    78 		#region Properties
       
    79 		#endregion
       
    80 
       
    81 		#region Internal methods
       
    82 		private string FindInSpecifiedIncludeEntries( string aFileName, SymIncludeDefinition.TType aType )
       
    83 		{
       
    84 			string ret = string.Empty;
       
    85 			//
       
    86 			IDictionaryEnumerator enumerator = iIncludes.GetEnumerator();
       
    87 			while ( enumerator.MoveNext() )
       
    88 			{
       
    89 				SymIncludeDefinition include = (SymIncludeDefinition) enumerator.Value;
       
    90 				//
       
    91 				if	( include.Type == aType )
       
    92 				{
       
    93 					string includePath = include.Location;
       
    94 					string resolvedFileName = SymFileSystemUtils.MergePaths( includePath, aFileName );
       
    95 					//
       
    96 					if	( SymFileSystemUtils.FileExists( resolvedFileName ) )
       
    97 					{
       
    98 						ret = resolvedFileName;
       
    99 						break;
       
   100 					}
       
   101 				}
       
   102 			}
       
   103 			//
       
   104 			return ret;
       
   105 		}
       
   106 		#endregion
       
   107 
       
   108 		#region Data members
       
   109 		private Hashtable iIncludes = new Hashtable( 10 );
       
   110 		#endregion
       
   111 	}
       
   112 }