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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
#include <Interface_BitMap.ixx>
#include <TCollection_AsciiString.hxx>
#include <Standard_NotImplemented.hxx>
Interface_BitMap::Interface_BitMap
(const Standard_Integer nbitems, const Standard_Integer resflags)
{
thenbitems = nbitems;
thenbwords = nbitems/32 + 1;
thenbflags = 0;
theflags = new TColStd_HArray1OfInteger (0,thenbwords*(resflags+1)); theflags->Init(0);
}
Interface_BitMap::Interface_BitMap
(const Interface_BitMap& other, const Standard_Boolean copied)
{
other.Internals (thenbitems,thenbwords,thenbflags,theflags,thenames);
if (!copied) return;
Standard_Integer nb = theflags->Upper ();
Handle(TColStd_HArray1OfInteger) flags = new TColStd_HArray1OfInteger(0,nb);
Standard_Integer i; // svv Jan11 2000 : porting on DEC
for (i = 0; i <= nb; i ++)
flags->SetValue (i,theflags->Value(i));
theflags = flags;
if (thenames.IsNull()) return;
nb = thenames->Length();
Handle(TColStd_HSequenceOfAsciiString) names = new TColStd_HSequenceOfAsciiString();
for (i = 1; i <= nb; i ++)
names->Append ( TCollection_AsciiString(thenames->Value(i)) );
thenames = names;
}
void Interface_BitMap::Internals
(Standard_Integer& nbitems, Standard_Integer& nbwords,
Standard_Integer& nbflags,
Handle(TColStd_HArray1OfInteger)& flags,
Handle(TColStd_HSequenceOfAsciiString)& names) const
{
nbitems = thenbitems; nbwords = thenbwords; nbflags = thenbflags;
flags = theflags; names = thenames;
}
void Interface_BitMap::Reservate (const Standard_Integer moreflags)
{
Standard_Integer nb = theflags->Upper ();
Standard_Integer nbflags = nb / thenbwords - 1; // flag 0 non compte ...
if (nbflags >= thenbflags + moreflags) return;
Standard_Integer nbw = thenbwords * (thenbflags+moreflags+2);
Handle(TColStd_HArray1OfInteger) flags = new TColStd_HArray1OfInteger(0,nbw);
Standard_Integer i; // svv Jan11 2000 : porting on DEC
for (i = 0; i <= nb; i ++)
flags->SetValue (i,theflags->Value(i));
for (i = nb+1; i <= nbw; i ++) flags->SetValue (i,0);
theflags = flags;
}
void Interface_BitMap::SetLength (const Standard_Integer nbitems)
{
Standard_Integer nbw = nbitems/32 + 1;
if (nbw == thenbwords) return;
Handle(TColStd_HArray1OfInteger) flags =
new TColStd_HArray1OfInteger(0,nbw*(thenbflags+1));
if (nbw > thenbwords) flags->Init(0);
Standard_Integer nbmots = (nbw > thenbwords ? thenbwords : nbw);
Standard_Integer i0 = 0, i1 = 0;
for (Standard_Integer nf = 0; nf <= thenbflags; nf ++) {
for (Standard_Integer i = 0; i < nbmots; i ++)
flags->SetValue (i1+i,theflags->Value(i0+i));
i0 += thenbwords; i1 += nbw;
}
theflags = flags;
thenbitems = nbitems;
thenbwords = nbw;
}
Standard_Integer Interface_BitMap::AddFlag (const Standard_CString name)
{
Reservate(1);
Standard_Integer deja = 0;
if (thenames.IsNull()) thenames = new TColStd_HSequenceOfAsciiString();
else {
Standard_Integer i, nb = thenames->Length();
for (i = 1; i <= nb; i ++) {
if (thenames->Value(i).IsEqual("."))
{ thenames->ChangeValue(i).AssignCat(name); deja = i; }
}
}
if (!deja) thenames->Append (TCollection_AsciiString(name));
thenbflags ++;
return (deja ? deja : thenbflags);
}
Standard_Integer Interface_BitMap::AddSomeFlags
(const Standard_Integer more)
{
Reservate(more);
if (thenames.IsNull()) thenames = new TColStd_HSequenceOfAsciiString();
for (Standard_Integer i = 1; i <= more; i ++)
thenames->Append (TCollection_AsciiString(""));
thenbflags += more;
return thenbflags;
}
Standard_Boolean Interface_BitMap::RemoveFlag
(const Standard_Integer num)
{
if (num < 1 || num > thenames->Length()) return Standard_False;
if (num == thenames->Length()) thenames->Remove (thenames->Length());
else thenames->ChangeValue(num).AssignCat(".");
thenbflags --;
return Standard_True;
}
Standard_Boolean Interface_BitMap::SetFlagName
(const Standard_Integer num, const Standard_CString name)
{
if (num < 1 || num > thenames->Length()) return Standard_False;
Standard_Integer deja = (name[0] == '\0' ? 0 : FlagNumber (name) );
if (deja != 0 && deja != num) return Standard_False;
thenames->ChangeValue(num).AssignCat(name);
return Standard_True;
}
Standard_Integer Interface_BitMap::NbFlags () const
{ return thenbflags; }
Standard_Integer Interface_BitMap::Length () const
{ return thenbitems; }
Standard_CString Interface_BitMap::FlagName
(const Standard_Integer num) const
{
if (theflags.IsNull()) return "";
if (num < 1 || num > thenames->Length()) return "";
return thenames->Value(num).ToCString();
}
Standard_Integer Interface_BitMap::FlagNumber
(const Standard_CString name) const
{
if (name[0] == '\0') return 0;
if (thenames.IsNull()) return 0;
Standard_Integer i, nb = thenames->Length();
for (i = 1; i <= nb; i ++)
if (thenames->Value(i).IsEqual(name)) return i;
return 0;
}
// Les valeurs ...
Standard_Boolean Interface_BitMap::Value
(const Standard_Integer item, const Standard_Integer flag) const
{
Standard_Integer numw = (thenbwords * flag) + (item >> 5);
const Standard_Integer& val = theflags->Value (numw);
if (val == 0 ) return Standard_False;
if (val == ~(0)) return Standard_True;
Standard_Integer numb = item & 31;
return ( ((1 << numb) & val) != 0);
}
void Interface_BitMap::SetValue
(const Standard_Integer item, const Standard_Boolean val,
const Standard_Integer flag) const
{
if (val) SetTrue (item,flag);
else SetFalse (item,flag);
}
void Interface_BitMap::SetTrue
(const Standard_Integer item, const Standard_Integer flag) const
{
Standard_Integer numw = (thenbwords * flag) + (item >> 5);
Standard_Integer numb = item & 31;
theflags->ChangeValue (numw) |= (1 << numb);
}
void Interface_BitMap::SetFalse
(const Standard_Integer item, const Standard_Integer flag) const
{
Standard_Integer numw = (thenbwords * flag) + (item >> 5);
Standard_Integer& val = theflags->ChangeValue (numw);
if (val == 0) return;
Standard_Integer numb = item & 31;
theflags->ChangeValue (numw) &= ~(1 << numb);
}
Standard_Boolean Interface_BitMap::CTrue
(const Standard_Integer item, const Standard_Integer flag) const
{
Standard_Integer numw = (thenbwords * flag) + (item >> 5);
Standard_Integer numb = item & 31;
Standard_Integer& val = theflags->ChangeValue (numw);
Standard_Integer res, mot = (1 << numb);
if (val == 0) { val = mot; return Standard_False; }
else { res = val & mot; val |= mot; }
return (res != 0);
}
Standard_Boolean Interface_BitMap::CFalse
(const Standard_Integer item, const Standard_Integer flag) const
{
Standard_Integer numw = (thenbwords * flag) + (item >> 5);
Standard_Integer numb = item & 31;
Standard_Integer& val = theflags->ChangeValue (numw);
Standard_Integer res, mot = ~(1 << numb);
if (val == ~(0)) { val = mot; return Standard_False; }
else { res = val | mot; val &= mot; }
return (res != 0);
}
void Interface_BitMap::Init
(const Standard_Boolean val, const Standard_Integer flag) const
{
Standard_Integer i, ii = thenbwords, i1 = thenbwords *flag;
if (flag < 0) { i1 = 0; ii = thenbwords*(thenbflags+1); }
if (val) for (i = 0; i < ii; i ++) theflags->SetValue (i1+i,~(0));
else for (i = 0; i < ii; i ++) theflags->SetValue (i1+i, 0 );
}
|