0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / TDF / TDF_IDFilter.cxx
1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 //              ---------------------
21
22 // Version:     0.0
23 //Version       Date            Purpose
24 //              0.0     May 26 1997     Creation
25
26
27
28 #include <TDF_IDFilter.ixx>
29
30 #include <TDF_IDList.hxx>
31 #include <TDF_ListIteratorOfIDList.hxx>
32 #include <TDF_MapIteratorOfIDMap.hxx>
33
34 // To avoid too much resizing actions, et 23 est un nombre premier.
35 #define TDF_IDFilterMapSize 23
36
37 //=======================================================================
38 //function : TDF_IDFilter
39 //purpose  : 
40 //=======================================================================
41
42 TDF_IDFilter::TDF_IDFilter(const Standard_Boolean ignoreMode) :
43 myIgnore(ignoreMode)
44 {}
45
46
47 //=======================================================================
48 //function : TDF_IDFilter
49 //purpose  : Private, to forbid implicit or hidden accesses to
50 //          the copy constructor.
51 //=======================================================================
52
53 TDF_IDFilter::TDF_IDFilter(const TDF_IDFilter& /*aFilter*/)
54 {}
55
56
57 //=======================================================================
58 //function : IgnoreAll
59 //purpose  : 
60 //=======================================================================
61
62 void TDF_IDFilter::IgnoreAll(const Standard_Boolean ignore)
63 {
64   myIgnore = ignore;
65   myIDMap.Clear(); myIDMap.ReSize(TDF_IDFilterMapSize);
66 }
67
68
69 //=======================================================================
70 //function : Keep
71 //purpose  : Keeps an ID.
72 //=======================================================================
73
74 void TDF_IDFilter::Keep(const Standard_GUID& anID) 
75 {
76   if (myIgnore) myIDMap.Add(anID);
77   else          myIDMap.Remove(anID);
78 }
79
80
81 //=======================================================================
82 //function : Keep
83 //purpose  : Keeps a list of ID.
84 //=======================================================================
85
86 void TDF_IDFilter::Keep(const TDF_IDList& anIDList) 
87 {
88   if (!anIDList.IsEmpty()) {
89     TDF_ListIteratorOfIDList itr(anIDList);
90     if (myIgnore) {
91       Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
92       myIDMap.ReSize(n);
93       for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
94     }
95     else {
96       for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
97     }
98   }
99 }
100
101
102 //=======================================================================
103 //function : Ignore
104 //purpose  : Ignores an ID.
105 //=======================================================================
106
107 void TDF_IDFilter::Ignore(const Standard_GUID& anID) 
108 {
109   if (myIgnore) myIDMap.Remove(anID);
110   else          myIDMap.Add(anID);
111 }
112
113
114 //=======================================================================
115 //function : Ignore
116 //purpose  : Ignores a list of ID.
117 //=======================================================================
118
119 void TDF_IDFilter::Ignore(const TDF_IDList& anIDList)
120 {
121   if (!anIDList.IsEmpty()) {
122     TDF_ListIteratorOfIDList itr(anIDList);
123     if (myIgnore) {
124       for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
125     }
126     else {
127       Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
128       myIDMap.ReSize(n);
129       for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
130     }
131   }
132 }
133
134
135 //=======================================================================
136 //function : IDList
137 //purpose  : 
138 //=======================================================================
139
140 void TDF_IDFilter::IDList(TDF_IDList& anIDList) const
141 {
142   anIDList.Clear();
143   for (TDF_MapIteratorOfIDMap itr(myIDMap); itr.More(); itr.Next())
144     anIDList.Append(itr.Key());
145 }
146
147
148 //=======================================================================
149 //function : Copy
150 //purpose  : 
151 //=======================================================================
152
153 void TDF_IDFilter::Copy(const TDF_IDFilter& fromFilter)
154 {
155   myIgnore = fromFilter.IgnoreAll();
156   TDF_IDList idl;
157   fromFilter.IDList(idl);
158   if (myIgnore) Keep(idl);
159   else          Ignore(idl);
160 }
161
162
163 //=======================================================================
164 //function : Dump
165 //purpose  : 
166 //=======================================================================
167
168 void TDF_IDFilter::Dump(Standard_OStream& anOS) const
169 {
170   if (myIgnore) anOS<<"EX"; else anOS<<"IN"; anOS<<"CLUSIVE filter: ";
171   if (myIgnore) anOS<<"ignores"; else anOS<<"keeps  "; anOS<<" all IDs";
172   TDF_MapIteratorOfIDMap itr(myIDMap);
173   if (itr.More()) {
174     anOS<<" BUT:"<<endl;
175     for (; itr.More(); itr.Next()) {
176       const Standard_GUID& guid = itr.Key();
177       guid.ShallowDump(anOS);
178       anOS<<endl;
179     }
180   }
181 }