0023274: MSVC++ warnings issued during compilation for 64bits
[occt.git] / src / Dico / Dico_Iterator.gxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19//#include <Dico_Iterator.ixx>
20#include <Standard_NoSuchObject.hxx>
21
22
23
b311480e 24Dico_Iterator::Dico_Iterator (const Handle(Dico_Dictionary)& acell)
7fd59977 25{
26 thenb = 0; // Clear initial
27 thebase = acell; thename.Clear();
28 Start();
29}
30
31 Dico_Iterator::Dico_Iterator
32 (const Handle(Dico_Dictionary)& acell,
33 const TCollection_AsciiString& basename)
34{
35 thenb = 0; // Clear initial
36 if (basename.Length() == 0) {
37 thename.Clear();
38 thebase = acell;
39 } else {
40 thename = basename;
fb8a7358
P
41 Standard_Integer stat;
42 Standard_Size reslev;
7fd59977 43 acell->SearchCell(basename.ToCString(),basename.Length(),basename.Value(1),
44 1, thebase,reslev,stat);
45 if (stat != 0 || reslev != 0) thebase.Nullify(); // loupe
46 }
47 Start();
48}
49
50// Idem, mais avec une CString
51 Dico_Iterator::Dico_Iterator
52 (const Handle(Dico_Dictionary)& acell,
53 const Standard_CString basename)
54{
55 thenb = 0; // Clear initial
56 if (basename[0] == '\0') {
57 thename.Clear();
58 thebase = acell;
59 } else {
60 thename.AssignCat(basename);
fb8a7358
P
61 Standard_Integer stat;
62 Standard_Size reslev;
7fd59977 63 acell->SearchCell (basename,thename.Length(),basename[0],1,
64 thebase,reslev,stat);
65 if (stat != 0 || reslev != 0) thebase.Nullify(); // loupe
66 }
67 Start();
68}
69
70
71 void Dico_Iterator::Start ()
72{
73 thenb = 0; thelast.Nullify(); // Clear apres coup
74 themore = thenext = Standard_False; theinit = Standard_True;
75 if (thebase.IsNull()) return;
76 if (thebase->CellChar() == '\0') thebase = thebase->Next(); // 1re fois
77 if (!thebase.IsNull()) AppendStack(thebase);
78}
79
80 Standard_Boolean Dico_Iterator::More ()
81{
82 themore = Standard_True;
83 if (thenb == 0) return Standard_False; // fini
84 Handle(Dico_Dictionary) acell = thelast->Value();
85 if (theinit) {
86 theinit = Standard_False;
87 if (acell->HasIt()) return Standard_True; // c est bon
88 }
89
90 if (!thenext && acell->HasSub()) {
91 thenext = Standard_False; theinit = Standard_True;
92 AppendStack(acell->Sub());
93 }
94 else if (acell->HasNext()) { // fin de liste : remonter ...
95 thenext = Standard_False; theinit = Standard_True;
96 thelast->SetValue(acell->Next());
97 } else {
98 thenext = Standard_True; theinit = Standard_False;
99 thelast = thelast->Previous(); // Null si pas de Previous ... sinon boum
100 thenb --;
101 }
102 if (thenb == 1 && thename.Length() != 0) { thenb = 0; thelast.Nullify(); }
103// ceci pour une sous-racine : ne pas regarder ses suivantes !
104 return More(); // reevaluation sur cette nouvelle tete de liste
105}
106
107
108 void Dico_Iterator::Next ()
109{
110 if (!themore)
111 More();
112 themore = Standard_False;
113}
114
115 const TheItem& Dico_Iterator::Value () const
116{
117 if (thenb == 0) Standard_NoSuchObject::Raise ("DicIter : no current value");
118 return thelast->Value()->It();
119}
120
121 TCollection_AsciiString Dico_Iterator::Name () const
122{
123 Standard_Integer nlen = thename.Length();
124
125// On calcule le nom donne par la pile en cours
126// if (thenb == 0) return TCollection_AsciiString(); // String vide
127 TCollection_AsciiString name(thenb,' ');
128 if (thenb > 0) {
129 Standard_Integer i = thenb;
130 Handle(Dico_StackItem) anitem = thelast;
131 while (!anitem.IsNull()) {
132 name.SetValue (i,anitem->Value()->CellChar()); // i-1 TString
133 i --;
134 anitem = anitem->Previous();
135 }
136 }
137
138 if (nlen < 2) return name;
139 TCollection_AsciiString basename(thename);
140 basename.Remove(nlen);
141 return basename.Cat(name);
142}
143
144
145// Appele deux fois, mis en commun
146 void Dico_Iterator::AppendStack (const Handle(Dico_Dictionary)& val)
147{
148 Handle(Dico_StackItem) newlast;
149 if (thelast.IsNull()) newlast = new Dico_StackItem;
150 else newlast = new Dico_StackItem(thelast);
151 thelast = newlast;
152 thelast->SetValue(val);
153 thenb ++;
154}