summaryrefslogtreecommitdiff
path: root/src/TDF/TDF_IDFilter.cxx
blob: e1465ca62982832525539231dfe024b3f41d649b (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// File:	TDF_IDFilter.cxx
//      	---------------------
// Author:	DAUTRY Philippe
//		<fid@fox.paris1.matra-dtv.fr>
// Copyright:	Matra Datavision 1997

// Version:	0.0
// History:	Version	Date		Purpose
//		0.0	May 26 1997	Creation



#include <TDF_IDFilter.ixx>

#include <TDF_IDList.hxx>
#include <TDF_ListIteratorOfIDList.hxx>
#include <TDF_MapIteratorOfIDMap.hxx>

// To avoid too much resizing actions, et 23 est un nombre premier.
#define TDF_IDFilterMapSize 23

//=======================================================================
//function : TDF_IDFilter
//purpose  : 
//=======================================================================

TDF_IDFilter::TDF_IDFilter(const Standard_Boolean ignoreMode) :
myIgnore(ignoreMode)
{}


//=======================================================================
//function : TDF_IDFilter
//purpose  : Private, to forbid implicit or hidden accesses to
//          the copy constructor.
//=======================================================================

TDF_IDFilter::TDF_IDFilter(const TDF_IDFilter& aFilter)
{}


//=======================================================================
//function : IgnoreAll
//purpose  : 
//=======================================================================

void TDF_IDFilter::IgnoreAll(const Standard_Boolean ignore)
{
  myIgnore = ignore;
  myIDMap.Clear(); myIDMap.ReSize(TDF_IDFilterMapSize);
}


//=======================================================================
//function : Keep
//purpose  : Keeps an ID.
//=======================================================================

void TDF_IDFilter::Keep(const Standard_GUID& anID) 
{
  if (myIgnore) myIDMap.Add(anID);
  else          myIDMap.Remove(anID);
}


//=======================================================================
//function : Keep
//purpose  : Keeps a list of ID.
//=======================================================================

void TDF_IDFilter::Keep(const TDF_IDList& anIDList) 
{
  if (!anIDList.IsEmpty()) {
    TDF_ListIteratorOfIDList itr(anIDList);
    if (myIgnore) {
      Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
      myIDMap.ReSize(n);
      for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
    }
    else {
      for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
    }
  }
}


//=======================================================================
//function : Ignore
//purpose  : Ignores an ID.
//=======================================================================

void TDF_IDFilter::Ignore(const Standard_GUID& anID) 
{
  if (myIgnore) myIDMap.Remove(anID);
  else          myIDMap.Add(anID);
}


//=======================================================================
//function : Ignore
//purpose  : Ignores a list of ID.
//=======================================================================

void TDF_IDFilter::Ignore(const TDF_IDList& anIDList)
{
  if (!anIDList.IsEmpty()) {
    TDF_ListIteratorOfIDList itr(anIDList);
    if (myIgnore) {
      for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
    }
    else {
      Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
      myIDMap.ReSize(n);
      for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
    }
  }
}


//=======================================================================
//function : IDList
//purpose  : 
//=======================================================================

void TDF_IDFilter::IDList(TDF_IDList& anIDList) const
{
  anIDList.Clear();
  for (TDF_MapIteratorOfIDMap itr(myIDMap); itr.More(); itr.Next())
    anIDList.Append(itr.Key());
}


//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================

void TDF_IDFilter::Copy(const TDF_IDFilter& fromFilter)
{
  myIgnore = fromFilter.IgnoreAll();
  TDF_IDList idl;
  fromFilter.IDList(idl);
  if (myIgnore) Keep(idl);
  else          Ignore(idl);
}


//=======================================================================
//function : Dump
//purpose  : 
//=======================================================================

void TDF_IDFilter::Dump(Standard_OStream& anOS) const
{
  if (myIgnore) anOS<<"EX"; else anOS<<"IN"; anOS<<"CLUSIVE filter: ";
  if (myIgnore) anOS<<"ignores"; else anOS<<"keeps  "; anOS<<" all IDs";
  TDF_MapIteratorOfIDMap itr(myIDMap);
  if (itr.More()) {
    anOS<<" BUT:"<<endl;
    for (; itr.More(); itr.Next()) {
      const Standard_GUID& guid = itr.Key();
      guid.ShallowDump(anOS);
      anOS<<endl;
    }
  }
}