crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/TextUtilities/Readers/Filters/AsyncTextReaderFilterCollection.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.IO;
       
    19 using System.Text;
       
    20 using System.Threading;
       
    21 using System.Collections;
       
    22 
       
    23 namespace SymbianUtils
       
    24 {
       
    25 	public class AsyncTextReaderFilterCollection : IEnumerable
       
    26 	{
       
    27 		#region Enumerations
       
    28 		public enum TCombinationType
       
    29 		{
       
    30 			ECombinationTypeUndefined = 0,
       
    31 			ECombinationTypeOR,
       
    32 			ECombinationTypeAND,
       
    33 			ECombinationTypeNOT
       
    34 		}
       
    35 		#endregion
       
    36 
       
    37 		#region Constructors
       
    38 		public AsyncTextReaderFilterCollection()
       
    39 		{
       
    40 		}
       
    41 		#endregion
       
    42 
       
    43 		#region API - Filter processing
       
    44 		public bool ProcessFilters( ref string aLine )
       
    45 		{
       
    46 			bool propagateLine = false;
       
    47 			//
       
    48 			if	( aLine.Length > 0 ) 
       
    49 			{
       
    50 				int matchCount = 0;
       
    51 				int filterCount = Count;
       
    52 
       
    53 				// First phase: check for filter matches
       
    54 				for ( int i = 0; i < filterCount; i++ )
       
    55 				{
       
    56 					AsyncTextReaderFilter filter = this[ i ];
       
    57 					//
       
    58 					bool matchedFilter = filter.Matches( aLine );
       
    59 					if ( matchedFilter )
       
    60 					{
       
    61 						++matchCount;
       
    62 					}
       
    63 				}
       
    64 
       
    65 				// Second phase: check for overall match against combined
       
    66 				// criteria.
       
    67 				propagateLine = ( filterCount == 0 ); // Default to true when no filters
       
    68 				switch ( CombinationType )
       
    69 				{
       
    70 					case TCombinationType.ECombinationTypeOR:
       
    71 						propagateLine = ( matchCount > 0 );
       
    72 						break;
       
    73 					case TCombinationType.ECombinationTypeAND:
       
    74 						propagateLine = ( matchCount == filterCount );
       
    75 						break;
       
    76 					case TCombinationType.ECombinationTypeNOT:
       
    77 						propagateLine = ( matchCount == 0 );
       
    78 						break;
       
    79 					default:
       
    80 					case TCombinationType.ECombinationTypeUndefined:
       
    81 						break;
       
    82 				}
       
    83 
       
    84 				// Third phase: process filter
       
    85 				if	( propagateLine )
       
    86 				{
       
    87 					for ( int i = 0; i < filterCount; i++ )
       
    88 					{
       
    89 						AsyncTextReaderFilter filter = this[ i ];
       
    90 						filter.Process( ref aLine );
       
    91 					}
       
    92 				}
       
    93 			}
       
    94 
       
    95 			return propagateLine;
       
    96 		}
       
    97 		#endregion
       
    98 
       
    99 		#region API - Filter management
       
   100 		public void Add( AsyncTextReaderFilter aFilter )
       
   101 		{
       
   102 			iFilters.Add( aFilter );
       
   103 		}
       
   104 
       
   105 		public void RemoveAt( int aIndex )
       
   106 		{
       
   107 			iFilters.RemoveAt( aIndex );
       
   108 		}
       
   109 
       
   110 		public void Remove( AsyncTextReaderFilter aFilter )
       
   111 		{
       
   112 			iFilters.Remove( aFilter );
       
   113 		}
       
   114 
       
   115 		public void Clear()
       
   116 		{
       
   117 			iFilters.Clear();
       
   118 		}
       
   119 
       
   120 		#endregion
       
   121 
       
   122 		#region Properties
       
   123 		public int Count
       
   124 		{
       
   125 			get { return iFilters.Count; }
       
   126 		}
       
   127 
       
   128 		public AsyncTextReaderFilter this[ int aIndex ]
       
   129 		{
       
   130 			get { return (AsyncTextReaderFilter) iFilters[ aIndex ]; }
       
   131 		}
       
   132 
       
   133 		public TCombinationType CombinationType
       
   134 		{
       
   135 			get { return iCombinationType; }
       
   136 			set { iCombinationType = value; }
       
   137 		}
       
   138 		#endregion
       
   139 
       
   140 		#region IEnumerable Members
       
   141 		public IEnumerator GetEnumerator()
       
   142 		{
       
   143 			return new AsyncTextReaderFilterCollectionEnumerator( this );
       
   144 		}
       
   145 		#endregion
       
   146 
       
   147 		#region Data members
       
   148 		private TCombinationType iCombinationType = TCombinationType.ECombinationTypeUndefined;
       
   149 		private ArrayList iFilters = new ArrayList();
       
   150 		#endregion
       
   151 	}
       
   152 }