crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/CodeSegDefinitionCollectionComparers.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 
       
    20 namespace SymbolLib.CodeSegDef
       
    21 {
       
    22 	internal class CodeSegDefinitionCollectionCompareByFileName : IComparer<CodeSegDefinition>
       
    23 	{
       
    24 		#region IComparer Members
       
    25 		public int Compare( object aLeft, object aRight )
       
    26 		{
       
    27             int ret = -1;
       
    28             //
       
    29             if ( aLeft == null || aRight == null )
       
    30             {
       
    31                 if ( aRight == null )
       
    32                 {
       
    33                     ret = 1;
       
    34                 }
       
    35             }
       
    36             else
       
    37             {
       
    38                 CodeSegDefinition left = (CodeSegDefinition) aLeft;
       
    39                 CodeSegDefinition right = (CodeSegDefinition) aRight;
       
    40                 //
       
    41                 ret = Compare( left, right );
       
    42             }
       
    43             //
       
    44             return ret;
       
    45 		}
       
    46 		#endregion
       
    47 
       
    48         #region IComparer<CodeSegDefinition> Members
       
    49         int IComparer<CodeSegDefinition>.Compare( CodeSegDefinition aLeft, CodeSegDefinition aRight )
       
    50         {
       
    51             int ret = -1;
       
    52             //
       
    53             if ( aLeft == null || aRight == null )
       
    54             {
       
    55                 if ( aRight == null )
       
    56                 {
       
    57                     ret = 1;
       
    58                 }
       
    59             }
       
    60             else
       
    61             {
       
    62                 ret = string.Compare( aLeft.ImageFileNameAndPath, aRight.ImageFileNameAndPath, true );
       
    63             }
       
    64             //
       
    65             return ret;
       
    66         }
       
    67         #endregion
       
    68     }
       
    69 
       
    70     internal class CodeSegDefinitionCollectionCompareByAddress : IComparer<CodeSegDefinition>
       
    71 	{
       
    72         #region IComparer Members
       
    73         public int Compare( object aLeft, object aRight )
       
    74         {
       
    75             int ret = -1;
       
    76             //
       
    77             if ( aLeft == null || aRight == null )
       
    78             {
       
    79                 if ( aRight == null )
       
    80                 {
       
    81                     ret = 1;
       
    82                 }
       
    83             }
       
    84             else
       
    85             {
       
    86                 CodeSegDefinition left = (CodeSegDefinition) aLeft;
       
    87                 CodeSegDefinition right = (CodeSegDefinition) aRight;
       
    88                 //
       
    89                 ret = Compare( left, right );
       
    90             }
       
    91             //
       
    92             return ret;
       
    93         }
       
    94         #endregion
       
    95 
       
    96         #region IComparer Members
       
    97         int IComparer<CodeSegDefinition>.Compare( CodeSegDefinition aLeft, CodeSegDefinition aRight )
       
    98         {
       
    99 			int ret = -1;
       
   100             if ( aLeft.AddressStart == aRight.AddressStart && aLeft.AddressEnd == aRight.AddressEnd )
       
   101 			{
       
   102 				ret = 0;
       
   103 			}
       
   104             else if ( aLeft.AddressEnd == aRight.AddressStart )
       
   105 			{
       
   106                 System.Diagnostics.Debug.Assert( aLeft.AddressStart < aRight.AddressStart );
       
   107                 System.Diagnostics.Debug.Assert( aRight.AddressEnd >= aLeft.AddressEnd );
       
   108 				//
       
   109 				ret = -1;
       
   110 			}
       
   111             else if ( aLeft.AddressStart == aRight.AddressEnd )
       
   112 			{
       
   113                 System.Diagnostics.Debug.Assert( aRight.AddressStart < aLeft.AddressStart );
       
   114                 System.Diagnostics.Debug.Assert( aLeft.AddressEnd >= aRight.AddressEnd );
       
   115 				//
       
   116 				ret = 1;
       
   117 			}
       
   118             else if ( aLeft.AddressStart > aRight.AddressEnd )
       
   119 			{
       
   120                 System.Diagnostics.Debug.Assert( aLeft.AddressEnd > aRight.AddressEnd );
       
   121                 System.Diagnostics.Debug.Assert( aLeft.AddressEnd > aRight.AddressStart );
       
   122 				ret = 1;
       
   123 			}
       
   124             else if ( aLeft.AddressEnd < aRight.AddressStart )
       
   125 			{
       
   126                 System.Diagnostics.Debug.Assert( aLeft.AddressStart < aRight.AddressEnd );
       
   127                 System.Diagnostics.Debug.Assert( aRight.AddressEnd > aLeft.AddressEnd );
       
   128 				ret = -1;
       
   129 			}
       
   130 			//
       
   131 			return ret;
       
   132 		}
       
   133 		#endregion
       
   134     }
       
   135 }