Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / debug / InputBufferEventSupport.cs
blobb58d4d6284906d320470c049af485cfe21a02f30
1 namespace antlr.debug
3 using System;
4 using ArrayList = System.Collections.ArrayList;
6 public class InputBufferEventSupport
8 public virtual ArrayList InputBufferListeners
10 get
12 return inputBufferListeners;
16 private object source;
17 private ArrayList inputBufferListeners;
18 private InputBufferEventArgs inputBufferEvent;
19 protected internal const int CONSUME = 0;
20 protected internal const int LA = 1;
21 protected internal const int MARK = 2;
22 protected internal const int REWIND = 3;
25 public InputBufferEventSupport(object source)
27 inputBufferEvent = new InputBufferEventArgs();
28 this.source = source;
30 public virtual void addInputBufferListener(InputBufferListener l)
32 if (inputBufferListeners == null)
33 inputBufferListeners = new ArrayList();
34 inputBufferListeners.Add(l);
36 public virtual void fireConsume(char c)
38 inputBufferEvent.setValues(InputBufferEventArgs.CONSUME, c, 0);
39 fireEvents(CONSUME, inputBufferListeners);
41 public virtual void fireEvent(int type, Listener l)
43 switch (type)
45 case CONSUME:
46 ((InputBufferListener) l).inputBufferConsume(source, inputBufferEvent); break;
48 case LA:
49 ((InputBufferListener) l).inputBufferLA(source, inputBufferEvent); break;
51 case MARK:
52 ((InputBufferListener) l).inputBufferMark(source, inputBufferEvent); break;
54 case REWIND:
55 ((InputBufferListener) l).inputBufferRewind(source, inputBufferEvent); break;
57 default:
58 throw new System.ArgumentException("bad type " + type + " for fireEvent()");
62 public virtual void fireEvents(int type, ArrayList listeners)
64 ArrayList targets = null;
65 Listener l = null;
67 lock(this)
69 if (listeners == null)
70 return ;
71 targets = (ArrayList) listeners.Clone();
74 if (targets != null)
75 for (int i = 0; i < targets.Count; i++)
77 l = (Listener) targets[i];
78 fireEvent(type, l);
81 public virtual void fireLA(char c, int la)
83 inputBufferEvent.setValues(InputBufferEventArgs.LA, c, la);
84 fireEvents(LA, inputBufferListeners);
86 public virtual void fireMark(int pos)
88 inputBufferEvent.setValues(InputBufferEventArgs.MARK, ' ', pos);
89 fireEvents(MARK, inputBufferListeners);
91 public virtual void fireRewind(int pos)
93 inputBufferEvent.setValues(InputBufferEventArgs.REWIND, ' ', pos);
94 fireEvents(REWIND, inputBufferListeners);
96 protected internal virtual void refresh(ArrayList listeners)
98 ArrayList v;
99 lock(listeners)
101 v = (ArrayList) listeners.Clone();
103 if (v != null)
104 for (int i = 0; i < v.Count; i++)
105 ((Listener) v[i]).refresh();
107 public virtual void refreshListeners()
109 refresh(inputBufferListeners);
111 public virtual void removeInputBufferListener(InputBufferListener l)
113 if (inputBufferListeners != null)
115 ArrayList temp_arraylist;
116 object temp_object;
117 temp_arraylist = inputBufferListeners;
118 temp_object = l;
119 temp_arraylist.Contains(temp_object);
120 temp_arraylist.Remove(temp_object);