1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
//#include <Dico_Iterator.ixx>
#include <Standard_NoSuchObject.hxx>
Dico_Iterator::Dico_Iterator (const Handle(Dico_Dictionary)& acell)
{
thenb = 0; // Clear initial
thebase = acell; thename.Clear();
Start();
}
Dico_Iterator::Dico_Iterator
(const Handle(Dico_Dictionary)& acell,
const TCollection_AsciiString& basename)
{
thenb = 0; // Clear initial
if (basename.Length() == 0) {
thename.Clear();
thebase = acell;
} else {
thename = basename;
Standard_Integer reslev,stat;
acell->SearchCell(basename.ToCString(),basename.Length(),basename.Value(1),
1, thebase,reslev,stat);
if (stat != 0 || reslev != 0) thebase.Nullify(); // loupe
}
Start();
}
// Idem, mais avec une CString
Dico_Iterator::Dico_Iterator
(const Handle(Dico_Dictionary)& acell,
const Standard_CString basename)
{
thenb = 0; // Clear initial
if (basename[0] == '\0') {
thename.Clear();
thebase = acell;
} else {
thename.AssignCat(basename);
Standard_Integer reslev,stat;
acell->SearchCell (basename,thename.Length(),basename[0],1,
thebase,reslev,stat);
if (stat != 0 || reslev != 0) thebase.Nullify(); // loupe
}
Start();
}
void Dico_Iterator::Start ()
{
thenb = 0; thelast.Nullify(); // Clear apres coup
themore = thenext = Standard_False; theinit = Standard_True;
if (thebase.IsNull()) return;
if (thebase->CellChar() == '\0') thebase = thebase->Next(); // 1re fois
if (!thebase.IsNull()) AppendStack(thebase);
}
Standard_Boolean Dico_Iterator::More ()
{
themore = Standard_True;
if (thenb == 0) return Standard_False; // fini
Handle(Dico_Dictionary) acell = thelast->Value();
if (theinit) {
theinit = Standard_False;
if (acell->HasIt()) return Standard_True; // c est bon
}
if (!thenext && acell->HasSub()) {
thenext = Standard_False; theinit = Standard_True;
AppendStack(acell->Sub());
}
else if (acell->HasNext()) { // fin de liste : remonter ...
thenext = Standard_False; theinit = Standard_True;
thelast->SetValue(acell->Next());
} else {
thenext = Standard_True; theinit = Standard_False;
thelast = thelast->Previous(); // Null si pas de Previous ... sinon boum
thenb --;
}
if (thenb == 1 && thename.Length() != 0) { thenb = 0; thelast.Nullify(); }
// ceci pour une sous-racine : ne pas regarder ses suivantes !
return More(); // reevaluation sur cette nouvelle tete de liste
}
void Dico_Iterator::Next ()
{
if (!themore)
More();
themore = Standard_False;
}
const TheItem& Dico_Iterator::Value () const
{
if (thenb == 0) Standard_NoSuchObject::Raise ("DicIter : no current value");
return thelast->Value()->It();
}
TCollection_AsciiString Dico_Iterator::Name () const
{
Standard_Integer nlen = thename.Length();
// On calcule le nom donne par la pile en cours
// if (thenb == 0) return TCollection_AsciiString(); // String vide
TCollection_AsciiString name(thenb,' ');
if (thenb > 0) {
Standard_Integer i = thenb;
Handle(Dico_StackItem) anitem = thelast;
while (!anitem.IsNull()) {
name.SetValue (i,anitem->Value()->CellChar()); // i-1 TString
i --;
anitem = anitem->Previous();
}
}
if (nlen < 2) return name;
TCollection_AsciiString basename(thename);
basename.Remove(nlen);
return basename.Cat(name);
}
// Appele deux fois, mis en commun
void Dico_Iterator::AppendStack (const Handle(Dico_Dictionary)& val)
{
Handle(Dico_StackItem) newlast;
if (thelast.IsNull()) newlast = new Dico_StackItem;
else newlast = new Dico_StackItem(thelast);
thelast = newlast;
thelast->SetValue(val);
thenb ++;
}
|