summaryrefslogtreecommitdiff
path: root/src/Interface/Interface_EntityIterator.cxx
blob: 2b8a50dd81a3635cee8fb052ab05166a96f4e72c (plain)
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
135
136
137
138
139
140
141
142
#include <Interface_EntityIterator.ixx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_NoSuchObject.hxx>


//  Iterateur pour ecriture for, ou while avec Next en fin :
//  for (creer iterateur; iter.More(); iter.Next()) { val = iter.Value(); ... }


// .... Definitions initiales : en particulier celles requises pour
//      les outils de graphe (construction avec le graphe, avec un vertex)

    Interface_EntityIterator::Interface_EntityIterator ()
{
//  thecurr = new Interface_IntVal;
//  thecurr->CValue() = 0;
//  thelist = new TColStd_HSequenceOfTransient();  // constructeur vide
//  thelist sera construit au premier Add (quelquefois, il nyena pas)
}

    Interface_EntityIterator::Interface_EntityIterator
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  thecurr = new Interface_IntVal;
  thecurr->CValue() = 0;
  thelist = list;
}

    void Interface_EntityIterator::AddList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  if (thelist.IsNull()) thelist = new TColStd_HSequenceOfTransient();
  if (thecurr.IsNull()) thecurr = new Interface_IntVal;
  thecurr->CValue() = 0;
  thelist->Append(list);
}

    void Interface_EntityIterator::AddItem
  (const Handle(Standard_Transient)& anentity)
{
  if (anentity.IsNull()) return;
  if (thecurr.IsNull()) thecurr = new Interface_IntVal;
  if (thelist.IsNull()) thelist = new TColStd_HSequenceOfTransient();
  thecurr->CValue() = 0;
  thelist->Append(anentity);
}

    void Interface_EntityIterator::GetOneItem
  (const Handle(Standard_Transient)& anentity)
      {  AddItem(anentity);  }

    void Interface_EntityIterator::Reset ()
{
  if (thecurr.IsNull()) thecurr = new Interface_IntVal;
  thecurr->CValue() = 0;
  thelist = new TColStd_HSequenceOfTransient();
}


// .... Fonctionnalites de tri prealable a l'iteration ....

//  Facon "bete" : supprimer les termes qui ne conviennent pas : lent !
//  Mieux vaut refaire une autre sequence a cote

    void Interface_EntityIterator::SelectType
  (const Handle(Standard_Type)& atype, const Standard_Boolean keep)
{
  if (thelist.IsNull()) return;
  Standard_Integer i, n = thelist->Length();
  Handle(TColStd_HSequenceOfTransient) nlist = new TColStd_HSequenceOfTransient();
  for (i = 1 ; i <= n ; i ++) {
    if (thelist->Value(i)->IsKind(atype) == keep) nlist->Append(thelist->Value(i));
  }
  thelist = nlist;
}

//  ....  Iteration proprement dite  ....

    Standard_Integer Interface_EntityIterator::NbEntities () const
{
  if (thelist.IsNull()) return 0;
  if (!thecurr.IsNull() && thecurr->Value() == 0) Start();
  return thelist->Length();
}

    Standard_Integer Interface_EntityIterator::NbTyped
  (const Handle(Standard_Type)& atype) const
{
  Standard_Integer res = 0;
  if (thelist.IsNull()) return res;
  Standard_Integer i, n = thelist->Length();
  for (i = 1 ; i <= n ; i ++) {
    if (thelist->Value(i)->IsKind(atype)) res ++;
  }
  return res;
}

    Interface_EntityIterator  Interface_EntityIterator::Typed
  (const Handle(Standard_Type)& atype) const
{
  Interface_EntityIterator res;
  if (thelist.IsNull()) return res;
  Standard_Integer i, n = thelist->Length();
  for (i = 1 ; i <= n ; i ++) {
    if (thelist->Value(i)->IsKind(atype)) res.AddItem (thelist->Value(i));
  }
  return res;
}


    void Interface_EntityIterator::Start () const
      {    if (!thecurr.IsNull()) thecurr->CValue() = 1 ;  }     // peut etre redefini ...

    Standard_Boolean Interface_EntityIterator::More () const
{
  if (thecurr.IsNull()) return Standard_False;
  if (thecurr->Value() == 0) Start();  // preparation de l iteration
  if (thelist.IsNull()) return Standard_False;
  return (thecurr->Value() <= thelist->Length());
}

    void Interface_EntityIterator::Next () const
      {    thecurr->CValue() ++;  }    // Next ne verifie rien : soin laisse a Value

    const Handle(Standard_Transient)& Interface_EntityIterator::Value () const
{
//  NbEntity pas const (on ne sait pas comment il est implemente apres tout)
  if (thelist.IsNull()) Standard_NoSuchObject::Raise("Interface_EntityIterator");
  if (thecurr->Value() < 1 || thecurr->Value() > thelist->Length())
    Standard_NoSuchObject::Raise("Interface_EntityIterator");
  return thelist->Value(thecurr->Value());
}

    Handle(TColStd_HSequenceOfTransient)  Interface_EntityIterator::Content () const
{
  if (!thecurr.IsNull() && thecurr->Value() == 0) Start();
  if (thelist.IsNull()) return new TColStd_HSequenceOfTransient();  // vide
  return thelist;
}

    void  Interface_EntityIterator::Destroy ()
      {  thecurr.Nullify();  }  // redevient vide !