HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_DataFilter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __SIM_DataFilter_h__
9 #define __SIM_DataFilter_h__
10 
11 #include "SIM_API.h"
12 #include <UT/UT_Guid.h>
13 #include <UT/UT_String.h>
14 #include <UT/UT_WorkArgs.h>
15 #include <UT/UT_DMatrix4.h>
16 
17 class SIM_Data;
18 
19 /// This class is used to filter SIM_Data. This class or its subclasses are
20 /// used in the SIM_Data::filterSubData(), SIM_Data::filterConstSubData(),
21 /// SIM_Data::getFirstSubData(), SIM_Data::getFirstConstSubData(),
22 /// SIM_Data::forEachSubData(), and SIM_Data::forEachConstSubData()
23 /// functions.
25 {
26 public:
27  explicit SIM_DataFilter()
28  { }
29  virtual ~SIM_DataFilter()
30  { }
32  { }
33 
34  /// Override this function to decide what data is accepted and what
35  /// is rejected. The name parameter is the path of the data relative
36  /// to the root of the search that is calling this filter.
37  virtual bool acceptData(const SIM_Data *data,
38  const char *dataname) const = 0;
39 
40 private:
41  /// Disable the assignment operator so subclasses don't need to worry
42  /// about implementing it.
43  const SIM_DataFilter &operator=(const SIM_DataFilter &)
44  { return *this; }
45 };
46 
47 /// This filter accepts any data.
49 {
50 public:
51  explicit SIM_DataFilterAll()
52  { }
54  { }
56  : SIM_DataFilter()
57  { }
58 
59  virtual bool acceptData(const SIM_Data *,
60  const char *) const
61  { return true; }
62 };
63 
64 /// This filter rejects all data.
66 {
67 public:
68  explicit SIM_DataFilterNone()
69  { }
71  { }
73  : SIM_DataFilter()
74  { }
75 
76  virtual bool acceptData(const SIM_Data *,
77  const char *) const
78  { return false; }
79 };
80 
81 /// This implementation filters data based on its type. Any data that can
82 /// be cast to the data type specified in the constructor is accepted.
84 {
85 public:
86  explicit SIM_DataFilterByType(const char *datatype)
87  : myDataType(datatype, 1)
88  { }
90  { }
92  : SIM_DataFilter(),
93  myDataType(src.myDataType, 1)
94  { }
95 
96  virtual bool acceptData(const SIM_Data *data,
97  const char *dataname) const;
98 
99 private:
100  const UT_String myDataType;
101 };
102 
103 /// This implementation filters data based on its name. Any data that
104 /// matches the pattern specified in the constructor is accepted.
105 /// Pattern matching is case sensitive.
107 {
108 public:
109  explicit SIM_DataFilterByName(const char *pattern)
110  : myPattern(pattern, 1)
111  { }
113  { }
115  : SIM_DataFilter(),
116  myPattern(src.myPattern, 1)
117  { }
118 
119  virtual bool acceptData(const SIM_Data *data,
120  const char *dataname) const;
121 
122 private:
123  const UT_String myPattern;
124 };
125 
126 /// This implementation filters data based on its unique id. Only data with
127 /// the specified unique id will be accepted.
129 {
130 public:
131  explicit SIM_DataFilterByUniqueId(const UT_Guid &uniqueid)
132  : myUniqueId(uniqueid)
133  { }
135  { }
138  : SIM_DataFilter(),
139  myUniqueId(src.myUniqueId)
140  { }
141 
142  virtual bool acceptData(const SIM_Data *data,
143  const char *dataname) const;
144 
145 private:
146  const UT_Guid myUniqueId;
147 };
148 
149 /// This implementation accepts the Nth data accepted by some other filter.
150 /// The nth time data is accepted by this secondary filter, this filter
151 /// accepts the data. All subsequent data is immediately rejected.
152 ///
153 /// Note: in typical C++ fashion, n starts at zero.
155 {
156 public:
157  explicit SIM_DataFilterNth(const SIM_DataFilter &filter, int n)
158  : myFilter(filter),
159  myN(n),
160  myCount(0)
161  { }
163  { }
165  : SIM_DataFilter(),
166  myFilter(src.myFilter),
167  myCount(src.myCount),
168  myN(src.myN)
169  { }
170 
171  virtual bool acceptData(const SIM_Data *data,
172  const char *dataname) const
173  {
174  if( myCount <= myN &&
175  myFilter.acceptData(data, dataname) )
176  {
177  ++myCount;
178  return myCount == myN + 1;
179  }
180  return false;
181  }
182 
183 private:
184  const SIM_DataFilter &myFilter;
185  mutable int myCount;
186  const int myN;
187 };
188 
189 /// This implementation returns the union of two other filters.
190 /// If either one accepts the data, then this filter accepts the data.
192 {
193 public:
194  explicit SIM_DataFilterOr(const SIM_DataFilter &filter1,
195  const SIM_DataFilter &filter2)
196  : myFilter1(filter1),
197  myFilter2(filter2)
198  { }
200  { }
202  : SIM_DataFilter(),
203  myFilter1(src.myFilter1),
204  myFilter2(src.myFilter2)
205  { }
206 
207  virtual bool acceptData(const SIM_Data *data,
208  const char *dataname) const
209  {
210  if( myFilter1.acceptData(data, dataname) ||
211  myFilter2.acceptData(data, dataname) )
212  return true;
213  return false;
214  }
215 
216 private:
217  const SIM_DataFilter &myFilter1;
218  const SIM_DataFilter &myFilter2;
219 };
220 
221 /// This implementation returns the intersection of two other filters.
222 /// If both accept the data, then this filter accepts the data.
224 {
225 public:
226  explicit SIM_DataFilterAnd(const SIM_DataFilter &filter1,
227  const SIM_DataFilter &filter2)
228  : myFilter1(filter1),
229  myFilter2(filter2)
230  { }
232  { }
234  : SIM_DataFilter(),
235  myFilter1(src.myFilter1),
236  myFilter2(src.myFilter2)
237  { }
238 
239  virtual bool acceptData(const SIM_Data *data,
240  const char *dataname) const
241  {
242  if( myFilter1.acceptData(data, dataname) &&
243  myFilter2.acceptData(data, dataname) )
244  return true;
245  return false;
246  }
247 
248 private:
249  const SIM_DataFilter &myFilter1;
250  const SIM_DataFilter &myFilter2;
251 };
252 
253 /// This implementation returns the opposite value of some other filter.
254 /// If the secondary filter rejects the data, this filter accepts it.
256 {
257 public:
259  : myFilter(filter)
260  { }
262  { }
264  : SIM_DataFilter(),
265  myFilter(src.myFilter)
266  { }
267 
268  virtual bool acceptData(const SIM_Data *data,
269  const char *dataname) const
270  {
271  if( !myFilter.acceptData(data, dataname) )
272  return true;
273  return false;
274  }
275 
276 private:
277  const SIM_DataFilter &myFilter;
278 };
279 
280 /// This class is specific to filtering SIM_RootData and its subclasses,
281 /// SIM_Relationship and SIM_Object.
283 {
284 public:
285  explicit SIM_DataFilterRootData(const char *filterstr)
286  : myFilterStr(filterstr, 1)
287  {
288  myFilterStr.tokenize(myFilterArgs);
289  }
291  { }
294  : SIM_DataFilter(),
295  myFilterStr(src.myFilterStr),
296  myFilterArgs(src.myFilterArgs)
297  { }
298 
299  /// Compares the rootdata to the string passed to the constructor. An
300  /// rootdata is accepted if its name or id appears in the string, or if
301  /// the string contains the name of a group to which the rootdata belongs.
302  virtual bool acceptData(const SIM_Data *data,
303  const char *dataname) const;
304 
305 private:
306  UT_String myFilterStr;
307  UT_WorkArgs myFilterArgs;
308 };
309 
310 #endif
311 
virtual ~SIM_DataFilterByType()
SIM_DataFilterByName(const SIM_DataFilterByName &src)
SIM_DataFilterNot(const SIM_DataFilter &filter)
virtual ~SIM_DataFilterAll()
SIM_DataFilterOr(const SIM_DataFilterOr &src)
virtual ~SIM_DataFilter()
SIM_DataFilter(const SIM_DataFilter &)
virtual bool acceptData(const SIM_Data *data, const char *dataname) const
SIM_DataFilterOr(const SIM_DataFilter &filter1, const SIM_DataFilter &filter2)
SIM_DataFilterAll(const SIM_DataFilterAll &)
virtual ~SIM_DataFilterRootData()
This filter accepts any data.
SIM_DataFilterNone(const SIM_DataFilterNone &)
SIM_DataFilterNth(const SIM_DataFilterNth &src)
virtual bool acceptData(const SIM_Data *data, const char *dataname) const
virtual ~SIM_DataFilterAnd()
GLdouble n
Definition: glcorearb.h:2007
SIM_DataFilterByType(const char *datatype)
virtual ~SIM_DataFilterNone()
SIM_DataFilterRootData(const char *filterstr)
virtual bool acceptData(const SIM_Data *data, const char *dataname) const
SIM_DataFilterByName(const char *pattern)
GLboolean * data
Definition: glcorearb.h:130
SIM_DataFilterByUniqueId(const SIM_DataFilterByUniqueId &src)
virtual ~SIM_DataFilterOr()
virtual bool acceptData(const SIM_Data *, const char *) const
virtual ~SIM_DataFilterNth()
This filter rejects all data.
SIM_DataFilterAnd(const SIM_DataFilterAnd &src)
SIM_DataFilterNth(const SIM_DataFilter &filter, int n)
#define SIM_API
Definition: SIM_API.h:10
virtual ~SIM_DataFilterNot()
SIM_DataFilterByType(const SIM_DataFilterByType &src)
virtual ~SIM_DataFilterByName()
virtual bool acceptData(const SIM_Data *data, const char *dataname) const
virtual bool acceptData(const SIM_Data *data, const char *dataname) const =0
SIM_DataFilterRootData(const SIM_DataFilterRootData &src)
SIM_DataFilterNot(const SIM_DataFilterNot &src)
virtual bool acceptData(const SIM_Data *, const char *) const
SIM_DataFilterByUniqueId(const UT_Guid &uniqueid)
SIM_DataFilterAnd(const SIM_DataFilter &filter1, const SIM_DataFilter &filter2)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296
GLenum src
Definition: glcorearb.h:1792