From bfe2e33e1abc05b6e6b5fb52efac5b30ab28e7de Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 8 Sep 2011 17:58:44 +0000 Subject: [PATCH] codetools: TStringTree: enumerator git-svn-id: trunk@32237 - --- components/codetools/codetoolsstructs.pas | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/components/codetools/codetoolsstructs.pas b/components/codetools/codetoolsstructs.pas index 99b23146d2..c93283ba85 100644 --- a/components/codetools/codetoolsstructs.pas +++ b/components/codetools/codetoolsstructs.pas @@ -147,6 +147,21 @@ type constructor Create(CaseInsensitive: boolean); // false = system default end; + TStringTree = class; + + { TStringTreeEnumerator } + + TStringTreeEnumerator = class + private + FTree: TStringTree; + FCurrent: TAVLTreeNode; + function GetCurrent: string; + public + constructor Create(Tree: TStringTree); + function MoveNext: boolean; + property Current: string read GetCurrent; + end; + { TStringTree } TStringTree = class @@ -158,6 +173,7 @@ type function FindNode(const s: string): TAVLTreeNode; inline; procedure ReplaceString(var s: string); function CalcMemSize: PtrUInt; + function GetEnumerator: TStringTreeEnumerator; end; type @@ -312,6 +328,27 @@ begin Result:=CompareStr(AnsiString(Data1),AnsiString(Data2)); end; +{ TStringTreeEnumerator } + +function TStringTreeEnumerator.GetCurrent: string; +begin + Result:=AnsiString(FCurrent.Data); +end; + +constructor TStringTreeEnumerator.Create(Tree: TStringTree); +begin + FTree:=Tree; +end; + +function TStringTreeEnumerator.MoveNext: boolean; +begin + if FCurrent=nil then + FCurrent:=FTree.Tree.FindLowest + else + FCurrent:=FTree.Tree.FindSuccessor(FCurrent); + Result:=FCurrent<>nil; +end; + { TCodeXYPositions } function TCodeXYPositions.GetItems(Index: integer): PCodeXYPosition; @@ -784,6 +821,11 @@ begin end; end; +function TStringTree.GetEnumerator: TStringTreeEnumerator; +begin + Result:=TStringTreeEnumerator.Create(Self); +end; + { TComponentChildCollector } procedure TComponentChildCollector.AddChildComponent(Child: TComponent);