crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Parser/Framework/Workers/SymParserWorker.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.Tree;
       
    21 using SymBuildParsingLib.Token;
       
    22 
       
    23 namespace SymBuildParsingLib.Parser.Framework.Workers
       
    24 {
       
    25 	public abstract class SymParserWorker
       
    26 	{
       
    27 		#region Enumerations
       
    28 		public enum TTokenConsumptionType
       
    29 		{
       
    30 			ETokenNotConsumed = 0,
       
    31 			ETokenConsumed
       
    32 		};
       
    33 		#endregion
       
    34 
       
    35 		#region Constructors & destructor
       
    36 		public SymParserWorker( SymParserWorkerContext aContext )
       
    37 			: this( aContext, 0 )
       
    38 		{
       
    39 		}
       
    40 
       
    41 		public SymParserWorker( SymParserWorkerContext aContext, int aPriority )
       
    42 		{
       
    43 			iWorkerContext = aContext;
       
    44 			iPriority = aPriority;
       
    45 		}
       
    46 		#endregion
       
    47 
       
    48 		#region API
       
    49 		public virtual SymParserWorker.TTokenConsumptionType OfferToken( SymToken aToken )
       
    50 		{
       
    51 			SymParserWorker.TTokenConsumptionType consumptionType = TTokenConsumptionType.ETokenNotConsumed;
       
    52 			//
       
    53 			int count = iChildren.Count;
       
    54 			for( int i=0; i<count; i++ )
       
    55 			{
       
    56 				SymParserWorker worker = this[ i ];
       
    57 				consumptionType = worker.OfferToken( aToken );
       
    58 				//
       
    59 				if	( consumptionType == SymParserWorker.TTokenConsumptionType.ETokenConsumed )
       
    60 				{
       
    61 					break;
       
    62 				}
       
    63 			}
       
    64 			//
       
    65 			return consumptionType;
       
    66 		}
       
    67 		#endregion
       
    68 
       
    69 		#region Worker related
       
    70 		public virtual void RemoveSelf()
       
    71 		{
       
    72 			if	( WorkerContext.Parent != null )
       
    73 			{
       
    74 				WorkerContext.Parent.RemoveChild( this );
       
    75 			}
       
    76 		}
       
    77 
       
    78 		public virtual void AddChild( SymParserWorker aWorker )
       
    79 		{
       
    80 			iChildren.Add( aWorker );
       
    81 		}
       
    82 
       
    83 		public virtual void RemoveChild( SymParserWorker aWorker )
       
    84 		{
       
    85 			iChildren.Remove( aWorker );
       
    86 		}
       
    87 		
       
    88 		public int ChildCount
       
    89 		{
       
    90 			get { return iChildren.Count; }
       
    91 		}
       
    92 
       
    93 		public SymParserWorker this[ int aIndex ]
       
    94 		{
       
    95 			get { return (SymParserWorker) iChildren[ aIndex ]; }
       
    96 		}
       
    97 		#endregion
       
    98 
       
    99 		#region Properties
       
   100 		public int Priority
       
   101 		{
       
   102 			get { return iPriority; }
       
   103 		}
       
   104 
       
   105 		public SymParserWorkerContext WorkerContext
       
   106 		{
       
   107 			get { return iWorkerContext; }
       
   108 		}
       
   109 		#endregion
       
   110 
       
   111 		#region Data members
       
   112 		private readonly SymParserWorkerContext iWorkerContext;
       
   113 		private int iPriority = 0;
       
   114 		private ArrayList iChildren = new ArrayList(2);
       
   115 		#endregion
       
   116 	}
       
   117 }