VR-Forces 4.2 Class Documentation
featureSet.h
Go to the documentation of this file.
1 
2 
3 
4 
5 #pragma once
6 
8 #include <features/query.h>
9 
10 #include <boost/function.hpp>
11 #include <vector>
12 #include <memory>
13 
14 namespace MAKVRinTerra
15 {
16  class DtFeature;
17 
21  {
26  };
27 
31  {
36  };
37 
38  template <
39  typename FS,
40  template <typename> class PtrTemplate = boost::scoped_ptr,
41  typename InnerFS = FS>
42  class DtFeatureSetWrapper;
43 
44  template <typename FS, typename InnerFS = FS>
45  class DtSharedFeatureSetWrapper;
46 
47  template <typename FS>
49 
50  template <typename FS>
52 
53  template <typename FS>
55 
56  template <typename FS>
58 
66  template <typename F>
67  class DT_DLL_features DtFeatureSetTemplate : boost::noncopyable
68  {
69  public:
71  typedef F Feature;
72 
75 
77  typedef boost::function<void (const Feature&)> ForEachFunction;
78 
81 
84 
87 
92 
94  template <typename FS>
95  static DtFeatureSetTemplate* Wrap(FS* fs)
96  {
98  return new Wrapper(fs);
99  }
100 
102  {
103  return fs;
104  }
105 
107  virtual ~DtFeatureSetTemplate();
108 
110  virtual std::string label() const = 0;
111 
115  virtual void forEachFeature(ForEachFunction func, DtWaitType wait) const = 0;
116 
119  virtual void forEachFeatureParallel(ForEachFunction func, DtWaitType wait) const;
120 
125  virtual DtFeatureSetTemplate* filter(const DtQuery& query, DtLoadType load) const;
126 
132  virtual DtFeatureSetTemplate* clone() const = 0;
133 
145  virtual bool loaded(double timeout=0.0) const = 0;
146 
154  virtual bool empty() const;
155 
157  virtual bool isIndexed() const;
158 
165  virtual unsigned numberOfFeatures() const;
166 
169 
170  class Visitor
171  {
172  public:
173  virtual ~Visitor();
174  virtual void visit(FeatureSet&) = 0;
175  };
176 
178  {
179  public:
180  virtual ~ConstVisitor();
181  virtual void visit(const FeatureSet&) = 0;
182  };
184 
189 
190  virtual void accept(Visitor&);
191  virtual void accept(ConstVisitor&) const;
193  };
194 
196  template <typename F>
198  {
199  return from.clone();
200  }
201 
203  template <typename FS>
205  {
206  public:
207  typedef FS FeatureSet;
208  typedef typename FeatureSet::ForEachFunction ForEachFunction;
209  typedef typename FS::Visitor Visitor;
210  typedef typename FS::ConstVisitor ConstVisitor;
211 
212  DtFeatureSetList(std::string label = std::string());
213  ~DtFeatureSetList();
214 
215  void setLabel(std::string);
216 
219  void add(FS* fs);
220  void add(const FS&);
221  void add(std::auto_ptr<FS>);
222 
223  std::string label() const;
224  void forEachFeature(ForEachFunction func, DtWaitType) const;
225  void forEachFeatureParallel(ForEachFunction func, DtWaitType) const;
226  DtFeatureSetList* filter(const DtQuery&, DtLoadType) const;
227  DtFeatureSetList* clone() const;
228  bool loaded(double = 0.0) const;
229  unsigned numberOfFeatures() const;
230  bool empty() const;
231  bool isIndexed() const;
232 
233  void accept(Visitor&);
234  void accept(ConstVisitor&) const;
235 
236  protected:
238  explicit DtFeatureSetList(const DtFeatureSetList&);
239 
240  typedef std::list<FS*> PtrList;
241 
243  std::string myLabel;
244  };
245 
247  template <typename FS>
249  {
250  public:
251  typedef FS FeatureSet;
252  typedef typename FeatureSet::Feature Feature;
253  typedef typename FeatureSet::ForEachFunction ForEachFunction;
254  typedef typename FS::Visitor Visitor;
255  typedef typename FS::ConstVisitor ConstVisitor;
256 
257  struct Caller;
258 
259  DtFilteredFeatureSet(FS* fs, const DtQuery &);
260  DtFilteredFeatureSet(const FS&, const DtQuery&);
261 
262  const FS& filteredFeatureSet() const;
263  const DtQuery& query() const;
264 
265  std::string label() const;
266  void forEachFeature(ForEachFunction func, DtWaitType) const;
267  void forEachFeatureParallel(ForEachFunction func, DtWaitType) const;
268  FS* filter(const DtQuery&, DtLoadType) const;
269  DtFilteredFeatureSet* clone() const;
270  bool loaded(double = 0.0) const;
271  unsigned numberOfFeatures() const;
272  bool empty() const;
273  bool isIndexed() const;
274 
275  void accept(Visitor&);
276  void accept(ConstVisitor&) const;
277 
278  protected:
280 
281  boost::scoped_ptr<FS> myFeatureSet;
283  };
284 
285  template <typename FS>
287  {
288  public:
289  typedef FS FeatureSet;
290  typedef typename FeatureSet::ForEachFunction ForEachFunction;
291 
292  std::string label() const;
293  void forEachFeature(ForEachFunction, DtWaitType) const;
294  DtEmptyFeatureSet* filter(const DtQuery&, DtLoadType) const;
295  DtEmptyFeatureSet* clone() const;
296  bool loaded(double = 0.0) const;
297  unsigned numberOfFeatures() const;
298  bool empty() const { return true; }
299  };
300 
301  template <typename FS>
303  {
304  public:
305  typedef FS FeatureSet;
306  typedef typename FeatureSet::Feature Feature;
307  typedef typename FeatureSet::ForEachFunction ForEachFunction;
308 
309  typedef std::vector<typename Feature::CPtr> FeatureVector;
310 
311  static FS* Make(FeatureSet*);
312 
313  explicit DtStorageFeatureSet(const FS&);
314  explicit DtStorageFeatureSet();
315 
316  std::string label() const;
317  void forEachFeature(ForEachFunction, DtWaitType) const;
318  void forEachFeatureParallel(ForEachFunction func, DtWaitType) const;
319  DtStorageFeatureSet* clone() const;
320  bool loaded(double = 0.0) const;
321  unsigned numberOfFeatures() const;
322  bool empty() const { return myFeatures->empty(); }
323 
324  void addFeature(const Feature& feature);
325 
326  protected:
327  struct AddFeature;
328  struct ParallelCaller;
329 
330  explicit DtStorageFeatureSet(const DtStorageFeatureSet&);
331 
332  boost::shared_ptr<FeatureVector> myFeatures;
333  std::string myLabel;
334  };
335 
337  template <typename FS, template <typename> class PtrTemplate, typename InnerFS>
338  class DtFeatureSetWrapper : public FS
339  {
340  public:
341  typedef FS FeatureSet;
342  typedef typename FeatureSet::Feature Feature;
343  typedef typename FeatureSet::ForEachFunction ForEachFunction;
344 
345  typedef PtrTemplate<InnerFS> WrappedPtr;
346 
347  explicit DtFeatureSetWrapper(InnerFS* fs)
348  : mySet(fs)
349  {
350  }
351 
353  : mySet(fs)
354  {
355  }
356 
357  bool isSet() const
358  {
359  return mySet.get();
360  }
361 
362  void set(InnerFS* fs)
363  {
364  mySet.reset(fs);
365  }
366 
367  template <typename PtrType>
368  void set(PtrType fs)
369  {
370  mySet = fs;
371  }
372 
373  std::string label() const
374  {
375  return mySet->label();
376  }
377 
379  {
380  mySet->forEachFeature(func,wait);
381  }
382 
384  {
385  mySet->forEachFeatureParallel(func,wait);
386  }
387 
388  FeatureSet* filter(const DtQuery& query, DtLoadType load) const
389  {
390  return FeatureSet::Wrap(mySet->filter(query,load));
391  }
392 
393  FeatureSet* clone() const
394  {
395  return new DtFeatureSetWrapper(mySet->clone());
396  }
397 
398  bool loaded(double timeout = 0.0) const
399  {
400  return mySet->loaded(timeout);
401  }
402 
403  unsigned numberOfFeatures() const
404  {
405  return mySet->numberOfFeatures();
406  }
407 
408  bool empty() const
409  {
410  return mySet->empty();
411  }
412 
413  bool isIndexed() const
414  {
415  return mySet->isIndexed();
416  }
417 
418  protected:
420  };
421 
422  template <typename FS, template <typename> class PtrTemplate>
423  class DtFeatureSetWrapper<FS,PtrTemplate,FS> : public FS
424  {
425  public:
426  typedef FS FeatureSet;
427  typedef typename FeatureSet::Feature Feature;
428  typedef typename FeatureSet::ForEachFunction ForEachFunction;
429 
430  typedef PtrTemplate<FS> WrappedPtr;
431 
432  explicit DtFeatureSetWrapper(FS* fs)
433  : mySet(fs)
434  {
435  }
436 
438  : mySet(fs)
439  {
440  }
441 
442  bool isSet() const
443  {
444  return mySet.get();
445  }
446 
447  void set(FS* fs)
448  {
449  mySet.reset(fs);
450  }
451 
452  template <typename PtrType>
453  void set(PtrType fs)
454  {
455  mySet = fs;
456  }
457 
458  std::string label() const
459  {
460  return mySet->label();
461  }
462 
464  {
465  mySet->forEachFeature(func,wait);
466  }
467 
469  {
470  mySet->forEachFeatureParallel(func,wait);
471  }
472 
473  FeatureSet* filter(const DtQuery& query, DtLoadType load) const
474  {
475  return mySet->filter(query,load);
476  }
477 
478  FeatureSet* clone() const
479  {
480  assert(mySet.get());
481  return mySet->clone();
482  }
483 
484  bool loaded(double timeout = 0.0) const
485  {
486  return mySet->loaded(timeout);
487  }
488 
489  unsigned numberOfFeatures() const
490  {
491  return mySet->numberOfFeatures();
492  }
493 
494  bool empty() const
495  {
496  return mySet->empty();
497  }
498 
499  bool isIndexed() const
500  {
501  return mySet->isIndexed();
502  }
503 
504  protected:
506  };
507 
508  template <typename FS, typename InnerFS>
510  : public DtFeatureSetWrapper<FS, boost::shared_ptr, InnerFS>
511  {
513  typedef typename Parent::WrappedPtr WrappedPtr;
514 
515  public:
516  explicit DtSharedFeatureSetWrapper(InnerFS* fs)
517  : Parent(fs)
518  {
519  }
520 
522  : Parent(fs)
523  {
524  }
525 
526  FS* clone() const
527  {
528  assert(this->mySet.get());
529  return new DtSharedFeatureSetWrapper(this->mySet);
530  }
531  };
532 
534 }

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)