7fd59977 |
1 | #include <Interface_EntityCluster.ixx> |
2 | #include <Standard_OutOfRange.hxx> |
3 | #include <Standard_NullObject.hxx> |
4 | |
5 | // Un Cluster, ce sont 4 entites qui se suivent (dans le principe, nombre fixe, |
6 | // meme si pas 4). Elles sont remplies depuis 0. Il y a donc autant d Entites |
7 | // que de Handles non Nuls, plus le fait qu ils sont remplis dans l ordre |
8 | |
9 | // Ainsi (avec Next), on consomme 5 Handles pour 4 Entites, avec une pointe |
10 | // pour 1 et 2 Entites (on reste a 5 Handles) |
11 | |
12 | // Suppression : On retasse le Cluster pour que les Nulls soient tjrs a la fin |
13 | |
14 | // .... CONSTRUCTEURS .... |
15 | |
16 | Interface_EntityCluster::Interface_EntityCluster () { } |
17 | |
18 | Interface_EntityCluster::Interface_EntityCluster |
19 | (const Handle(Standard_Transient)& ent) |
20 | { theents[0] = ent; } |
21 | |
22 | Interface_EntityCluster::Interface_EntityCluster |
23 | (const Handle(Interface_EntityCluster)& ec) |
24 | { thenext = ec; } |
25 | |
26 | Interface_EntityCluster::Interface_EntityCluster |
27 | (const Handle(Standard_Transient)& ent, |
28 | const Handle(Interface_EntityCluster)& ec) |
29 | { theents[0] = ent; thenext = ec; } |
30 | |
31 | // .... AJOUT - SUPPRESSION .... |
32 | |
33 | void Interface_EntityCluster::Append |
34 | (const Handle(Standard_Transient)& ent) |
35 | { |
36 | if (ent.IsNull()) Standard_NullObject::Raise("Interface_EntityCluster Append"); |
37 | if (theents[0].IsNull()) theents[0] = ent; |
38 | else if (theents[1].IsNull()) theents[1] = ent; |
39 | else if (theents[2].IsNull()) theents[2] = ent; |
40 | else if (theents[3].IsNull()) theents[3] = ent; |
41 | else { // Si celui-ci est plein ... |
42 | if (thenext.IsNull()) thenext = new Interface_EntityCluster(ent); |
43 | else thenext->Append(ent); |
44 | } |
45 | } |
46 | |
47 | Standard_Boolean Interface_EntityCluster::Remove |
48 | (const Handle(Standard_Transient)& ent) |
49 | { |
50 | if (ent.IsNull()) Standard_NullObject::Raise("Interface_EntityCluster Remove"); |
51 | Standard_Integer i; |
52 | // <ent> est-il ici ? si oui, on a son rang |
53 | if (ent == theents[0]) i = 1; |
54 | else if (ent == theents[1]) i = 2; |
55 | else if (ent == theents[2]) i = 3; |
56 | else if (ent == theents[3]) i = 4; |
57 | |
58 | // Sinon, passer au suivant, qui peut du coup devenir vide -> |
59 | // On enleve le cluster vide de la liste (en principe cest le dernier) |
60 | else { // Pas trouve dans celui-ci ... |
61 | if (thenext.IsNull()) return Standard_False; |
62 | Standard_Integer res = thenext->Remove(ent); |
63 | if (res) thenext = thenext->Next(); |
64 | return Standard_False; |
65 | } |
66 | return Remove(i); |
67 | } |
68 | |
69 | Standard_Boolean Interface_EntityCluster::Remove |
70 | (const Standard_Integer num) |
71 | { |
72 | if (num < 1) Standard_OutOfRange::Raise("EntityCluster : Remove"); |
73 | Standard_Integer n = NbLocal(); |
74 | if (num > n) { |
75 | if (thenext.IsNull()) Standard_OutOfRange::Raise("EntityCluster : Remove"); |
76 | Standard_Boolean res = thenext->Remove (num-n); |
77 | if (res) thenext = thenext->Next(); |
78 | return Standard_False; |
79 | } |
80 | for (Standard_Integer j = num; j < n; j --) theents[j-1] = theents[j]; |
81 | theents[3].Nullify(); // On Nullify par la fin |
82 | return (n == 1); // Ancien NbLocal == 1 -> devient nul |
83 | } |
84 | |
85 | // .... ACCES AUX DONNEES .... |
86 | |
87 | Standard_Integer Interface_EntityCluster::NbEntities() const |
88 | { |
89 | Standard_Integer nb = NbLocal(); |
90 | if (!thenext.IsNull()) nb += thenext->NbEntities(); |
91 | return nb; |
92 | } |
93 | |
94 | const Handle(Standard_Transient)& Interface_EntityCluster::Value |
95 | (const Standard_Integer num) const |
96 | { |
97 | Standard_Integer nb = NbLocal(); |
98 | if (num <= 0) Standard_OutOfRange::Raise("Interface EntityCluster : Value"); |
99 | if (num > nb) { |
100 | if (thenext.IsNull()) Standard_OutOfRange::Raise |
101 | ("Interface EntityCluster : Value"); |
102 | return thenext->Value(num-nb); |
103 | } |
104 | return theents[num-1]; // numerotation a partir de 0 |
105 | } |
106 | |
107 | void Interface_EntityCluster::SetValue |
108 | (const Standard_Integer num, const Handle(Standard_Transient)& ent) |
109 | { |
110 | if (ent.IsNull()) Standard_NullObject::Raise("Interface_EntityCluster SetValue"); |
111 | Standard_Integer nb = NbLocal(); |
112 | if (num <= 0) Standard_OutOfRange::Raise("Interface EntityCluster : SetValue"); |
113 | if (num > nb) { |
114 | if (thenext.IsNull()) Standard_OutOfRange::Raise |
115 | ("Interface EntityCluster : SetValue"); |
116 | thenext->SetValue(num-nb,ent); |
117 | } |
118 | else theents[num-1] = ent; // numerotation a partir de 0 |
119 | } |
120 | |
121 | void Interface_EntityCluster::FillIterator |
122 | (Interface_EntityIterator& iter) const |
123 | { |
124 | if (!theents[0].IsNull()) iter.GetOneItem(theents[0]); |
125 | if (!theents[1].IsNull()) iter.GetOneItem(theents[1]); |
126 | if (!theents[2].IsNull()) iter.GetOneItem(theents[2]); |
127 | if (!theents[3].IsNull()) iter.GetOneItem(theents[3]); |
128 | if (!thenext.IsNull()) thenext->FillIterator(iter); |
129 | } |
130 | |
131 | // .... Actions atomiques internes .... |
132 | |
133 | Standard_Boolean Interface_EntityCluster::IsLocalFull () const |
134 | { |
135 | // Solaris Forte C++ compiler insisted it couldn't cast this, |
136 | // even though it seems to do so elsewhere |
137 | Handle_Standard_Transient tmp = Handle_Standard_Transient(theents[3]); |
138 | return ( !tmp.IsNull() ); |
139 | } |
140 | |
141 | Standard_Integer Interface_EntityCluster::NbLocal () const |
142 | { |
143 | Standard_Integer nb; |
144 | if (!theents[3].IsNull()) nb = 4; |
145 | else if (!theents[2].IsNull()) nb = 3; |
146 | else if (!theents[1].IsNull()) nb = 2; |
147 | else if (!theents[0].IsNull()) nb = 1; |
148 | else nb = 0; |
149 | return nb; |
150 | } |
151 | |
152 | Standard_Boolean Interface_EntityCluster::HasNext () const |
153 | { return (!thenext.IsNull()); } |
154 | |
155 | Handle(Interface_EntityCluster) Interface_EntityCluster::Next () const |
156 | { return thenext; } |