comparison dwtx/text/edits/TreeIterationInfo.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.text.edits.TreeIterationInfo;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.core.runtime.Assert;
18
19
20 class TreeIterationInfo {
21
22 interface Visitor {
23 void visit(TextEdit edit);
24 }
25
26 private int fMark= -1;
27 private TextEdit[][] fEditStack= new TextEdit[10][];
28 private int[] fIndexStack= new int[10];
29
30 public int getSize() {
31 return fMark + 1;
32 }
33 public void push(TextEdit[] edits) {
34 if (++fMark is fEditStack.length) {
35 TextEdit[][] t1= new TextEdit[fEditStack.length * 2][];
36 System.arraycopy(fEditStack, 0, t1, 0, fEditStack.length);
37 fEditStack= t1;
38 int[] t2= new int[fEditStack.length];
39 System.arraycopy(fIndexStack, 0, t2, 0, fIndexStack.length);
40 fIndexStack= t2;
41 }
42 fEditStack[fMark]= edits;
43 fIndexStack[fMark]= -1;
44 }
45 public void setIndex(int index) {
46 fIndexStack[fMark]= index;
47 }
48 public void pop() {
49 fEditStack[fMark]= null;
50 fIndexStack[fMark]= -1;
51 fMark--;
52 }
53 public void accept(Visitor visitor) {
54 for (int i= fMark; i >= 0; i--) {
55 Assert.isTrue(fIndexStack[i] >= 0);
56 int start= fIndexStack[i] + 1;
57 TextEdit[] edits= fEditStack[i];
58 for (int s= start; s < edits.length; s++) {
59 visitor.visit(edits[s]);
60 }
61 }
62 }
63 }