1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
20 // ---------------------
23 //Version Date Purpose
24 // 0.0 May 26 1997 Creation
28 #include <TDF_IDFilter.ixx>
30 #include <TDF_IDList.hxx>
31 #include <TDF_ListIteratorOfIDList.hxx>
32 #include <TDF_MapIteratorOfIDMap.hxx>
34 // To avoid too much resizing actions, et 23 est un nombre premier.
35 #define TDF_IDFilterMapSize 23
37 //=======================================================================
38 //function : TDF_IDFilter
40 //=======================================================================
42 TDF_IDFilter::TDF_IDFilter(const Standard_Boolean ignoreMode) :
47 //=======================================================================
48 //function : TDF_IDFilter
49 //purpose : Private, to forbid implicit or hidden accesses to
50 // the copy constructor.
51 //=======================================================================
53 TDF_IDFilter::TDF_IDFilter(const TDF_IDFilter& /*aFilter*/)
57 //=======================================================================
58 //function : IgnoreAll
60 //=======================================================================
62 void TDF_IDFilter::IgnoreAll(const Standard_Boolean ignore)
65 myIDMap.Clear(); myIDMap.ReSize(TDF_IDFilterMapSize);
69 //=======================================================================
71 //purpose : Keeps an ID.
72 //=======================================================================
74 void TDF_IDFilter::Keep(const Standard_GUID& anID)
76 if (myIgnore) myIDMap.Add(anID);
77 else myIDMap.Remove(anID);
81 //=======================================================================
83 //purpose : Keeps a list of ID.
84 //=======================================================================
86 void TDF_IDFilter::Keep(const TDF_IDList& anIDList)
88 if (!anIDList.IsEmpty()) {
89 TDF_ListIteratorOfIDList itr(anIDList);
91 Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
93 for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
96 for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
102 //=======================================================================
104 //purpose : Ignores an ID.
105 //=======================================================================
107 void TDF_IDFilter::Ignore(const Standard_GUID& anID)
109 if (myIgnore) myIDMap.Remove(anID);
110 else myIDMap.Add(anID);
114 //=======================================================================
116 //purpose : Ignores a list of ID.
117 //=======================================================================
119 void TDF_IDFilter::Ignore(const TDF_IDList& anIDList)
121 if (!anIDList.IsEmpty()) {
122 TDF_ListIteratorOfIDList itr(anIDList);
124 for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value());
127 Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1;
129 for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value());
135 //=======================================================================
138 //=======================================================================
140 void TDF_IDFilter::IDList(TDF_IDList& anIDList) const
143 for (TDF_MapIteratorOfIDMap itr(myIDMap); itr.More(); itr.Next())
144 anIDList.Append(itr.Key());
148 //=======================================================================
151 //=======================================================================
153 void TDF_IDFilter::Copy(const TDF_IDFilter& fromFilter)
155 myIgnore = fromFilter.IgnoreAll();
157 fromFilter.IDList(idl);
158 if (myIgnore) Keep(idl);
163 //=======================================================================
166 //=======================================================================
168 void TDF_IDFilter::Dump(Standard_OStream& anOS) const
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);
175 for (; itr.More(); itr.Next()) {
176 const Standard_GUID& guid = itr.Key();
177 guid.ShallowDump(anOS);