1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_EntityIterator.hxx>
16 #include <Interface_IntVal.hxx>
17 #include <Standard_NoMoreObject.hxx>
18 #include <Standard_NoSuchObject.hxx>
19 #include <Standard_Transient.hxx>
21 // Iterateur pour ecriture for, ou while avec Next en fin :
22 // for (creer iterateur; iter.More(); iter.Next()) { val = iter.Value(); ... }
23 // .... Definitions initiales : en particulier celles requises pour
24 // les outils de graphe (construction avec le graphe, avec un vertex)
25 Interface_EntityIterator::Interface_EntityIterator ()
27 // thecurr = new Interface_IntVal;
28 // thecurr->CValue() = 0;
29 // thelist = new TColStd_HSequenceOfTransient(); // constructeur vide
30 // thelist sera construit au premier Add (quelquefois, il nyena pas)
33 Interface_EntityIterator::Interface_EntityIterator
34 (const Handle(TColStd_HSequenceOfTransient)& list)
36 thecurr = new Interface_IntVal;
37 thecurr->CValue() = 0;
41 void Interface_EntityIterator::AddList
42 (const Handle(TColStd_HSequenceOfTransient)& list)
44 if (thelist.IsNull()) thelist = new TColStd_HSequenceOfTransient();
45 if (thecurr.IsNull()) thecurr = new Interface_IntVal;
46 thecurr->CValue() = 0;
47 thelist->Append(list);
50 void Interface_EntityIterator::AddItem
51 (const Handle(Standard_Transient)& anentity)
53 if (anentity.IsNull()) return;
54 if (thecurr.IsNull()) thecurr = new Interface_IntVal;
55 if (thelist.IsNull()) thelist = new TColStd_HSequenceOfTransient();
56 thecurr->CValue() = 0;
57 thelist->Append(anentity);
60 void Interface_EntityIterator::GetOneItem
61 (const Handle(Standard_Transient)& anentity)
62 { AddItem(anentity); }
64 void Interface_EntityIterator::Reset ()
66 if (thecurr.IsNull()) thecurr = new Interface_IntVal;
67 thecurr->CValue() = 0;
68 thelist = new TColStd_HSequenceOfTransient();
72 // .... Fonctionnalites de tri prealable a l'iteration ....
74 // Facon "bete" : supprimer les termes qui ne conviennent pas : lent !
75 // Mieux vaut refaire une autre sequence a cote
77 void Interface_EntityIterator::SelectType
78 (const Handle(Standard_Type)& atype, const Standard_Boolean keep)
80 if (thelist.IsNull()) return;
81 Standard_Integer i, n = thelist->Length();
82 Handle(TColStd_HSequenceOfTransient) nlist = new TColStd_HSequenceOfTransient();
83 for (i = 1 ; i <= n ; i ++) {
84 if (thelist->Value(i)->IsKind(atype) == keep) nlist->Append(thelist->Value(i));
89 // .... Iteration proprement dite ....
91 Standard_Integer Interface_EntityIterator::NbEntities () const
93 if (thelist.IsNull()) return 0;
94 if (!thecurr.IsNull() && thecurr->Value() == 0) Start();
95 return thelist->Length();
98 Standard_Integer Interface_EntityIterator::NbTyped
99 (const Handle(Standard_Type)& atype) const
101 Standard_Integer res = 0;
102 if (thelist.IsNull()) return res;
103 Standard_Integer i, n = thelist->Length();
104 for (i = 1 ; i <= n ; i ++) {
105 if (thelist->Value(i)->IsKind(atype)) res ++;
110 Interface_EntityIterator Interface_EntityIterator::Typed
111 (const Handle(Standard_Type)& atype) const
113 Interface_EntityIterator res;
114 if (thelist.IsNull()) return res;
115 Standard_Integer i, n = thelist->Length();
116 for (i = 1 ; i <= n ; i ++) {
117 if (thelist->Value(i)->IsKind(atype)) res.AddItem (thelist->Value(i));
123 void Interface_EntityIterator::Start () const
124 { if (!thecurr.IsNull()) thecurr->CValue() = 1 ; } // peut etre redefini ...
126 Standard_Boolean Interface_EntityIterator::More () const
128 if (thecurr.IsNull()) return Standard_False;
129 if (thecurr->Value() == 0) Start(); // preparation de l iteration
130 if (thelist.IsNull()) return Standard_False;
131 return (thecurr->Value() <= thelist->Length());
134 void Interface_EntityIterator::Next () const
135 { thecurr->CValue() ++; } // Next ne verifie rien : soin laisse a Value
137 const Handle(Standard_Transient)& Interface_EntityIterator::Value () const
139 // NbEntity pas const (on ne sait pas comment il est implemente apres tout)
140 if (thelist.IsNull()) Standard_NoSuchObject::Raise("Interface_EntityIterator");
141 if (thecurr->Value() < 1 || thecurr->Value() > thelist->Length())
142 Standard_NoSuchObject::Raise("Interface_EntityIterator");
143 return thelist->Value(thecurr->Value());
146 Handle(TColStd_HSequenceOfTransient) Interface_EntityIterator::Content () const
148 if (!thecurr.IsNull() && thecurr->Value() == 0) Start();
149 if (thelist.IsNull()) return new TColStd_HSequenceOfTransient(); // vide
153 void Interface_EntityIterator::Destroy ()
154 { thecurr.Nullify(); } // redevient vide !
156 Interface_EntityIterator::~Interface_EntityIterator()