VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
featureSet.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2014 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
9 
10 #pragma once
11 
13 
14 #include <memory>
15 #include <string>
16 
17 #include <boost/function.hpp>
18 #include <boost/scoped_ptr.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/weak_ptr.hpp>
21 
22 #include <boost/optional.hpp>
23 #include <boost/noncopyable.hpp>
24 
25 #include <vrfutil/objectCounter.h>
27 
28 namespace MAKVRinTerra
29 {
30  class DtFeature;
31  class DtQuery;
32  class DtFeatureGeometry;
33 
37  {
46  };
47 
48  template <
49  typename FS,
50  template <typename> class PtrTemplate = boost::scoped_ptr,
51  typename InnerFS = FS>
52  class DtFeatureSetWrapper;
53 
55  {
56  public:
58  };
59 
60  template <typename FS, typename InnerFS = FS>
62 
63  template <size_t N, typename FS, typename InnerFS = FS>
65 
66  template <typename FS>
68 
69  template <typename FS>
71 
72  template <typename FS, typename F = typename FS::Feature>
74 
75  template <typename FS>
77 
92  template <typename F>
94  : private boost::noncopyable
95  , public DtObjectDebugger< DtFeatureSetTemplate<F> >
96  {
97  public:
99  typedef F Feature;
100 
103 
115  typedef boost::function<void ()> DetachCallback;
116 
118  class DetachScopeGuard : boost::noncopyable
119  {
121 
122  public:
124  callback(cb) {};
126  {
127  if (callback)
128  {
129  callback();
130  }
131  };
132 
133  void reset(const DetachCallback& cb = DetachCallback())
134  {
135  if (callback)
136  callback();
137 
138  callback = cb;
139  };
140  };
141 
143  typedef boost::function<void (const Feature&)> ForEachFunction;
144 
146  typedef boost::function<void ()> LoadedCallback;
147 
150 
153 
155 
162 
175  template <typename FS>
176  static FeatureSet* Wrap(FS* fs)
177  {
178  std::auto_ptr<FS> set(fs);
179  return Wrap(set);
180  }
181 
183  {
184  return fs;
185  }
186 
187  static DtFeatureSetTemplate* Wrap(std::auto_ptr<FeatureSet> fs)
188  {
189  return fs.release();
190  }
191 
192  template <typename FS>
193  static FeatureSet* Wrap(std::auto_ptr<FS> fs)
194  {
195  if (!fs.get() || fs->empty())
196  return 0;
197 
199  }
200 
201  template <typename FS>
202  static FeatureSet* Wrap(const boost::shared_ptr<FS>& fs)
203  {
204  if (!fs || fs->empty())
205  return 0;
206 
208  }
209 
210  template <typename FS>
211  static FeatureSet* Wrap(const boost::weak_ptr<FS>& fs)
212  {
213  boost::shared_ptr<FS> ptr(fs.lock());
214  if (!ptr || ptr->empty())
215  return 0;
216 
218  }
220 
222  virtual ~DtFeatureSetTemplate();
223 
227  virtual std::string label() const = 0;
228 
236  virtual void forEachFeatureParallel(const ForEachFunction& func) const = 0;
237 
239  void forEachFeature(const ForEachFunction& func) const;
240 
243 
244  bool forEachFeatureParallelBlock(const ForEachFunction& func, double timeout = 60) const;
245  bool forEachFeatureBlock(const ForEachFunction& func, double timeout = 60) const;
247 
272  virtual DetachCallback forEachFeatureAsync(const ForEachFunction& func) const = 0;
274 
285 
286  virtual DtFeatureSetTemplate* filter(
287  const DtQuery& query,
288  const boost::optional<DtFeatureGeometry>& geometry,
289  DtLoadType load) const;
290 
291  DtFeatureSetTemplate* filter(
292  const DtQuery& query, DtLoadType load) const;
293 
294  DtFeatureSetTemplate* filter(
295  const boost::optional<DtFeatureGeometry>& geometry, DtLoadType load) const;
297 
304 
305  virtual bool load(
306  const DtQuery& query,
307  const boost::optional<DtFeatureGeometry>& geometry) const;
308 
309  bool load(const DtQuery& query) const;
310  bool load(const boost::optional<DtFeatureGeometry>& geometry) const;
312 
319  virtual DtFeatureSetTemplate* clone() const = 0;
320 
338  virtual bool loaded(double timeout=0.0) const = 0;
339 
349  virtual DetachCallback addLoadedCallback(const LoadedCallback&) const = 0;
350 
360  virtual bool empty() const;
361 
364  virtual bool isIndexed() const;
365 
380  virtual unsigned numberOfFeatures() const;
381 
386 
387  class Visitor
388  {
389  public:
390  virtual ~Visitor();
391  virtual void visit(FeatureSet&) = 0;
392  };
393 
395  {
396  public:
397  virtual ~ConstVisitor();
398  virtual void visit(const FeatureSet&) = 0;
399  };
401 
406 
407  virtual void accept(Visitor&);
408  virtual void accept(ConstVisitor&) const;
410 
411  protected:
412  class SynchronizedFunction;
413  struct FeatureCounter;
414  };
415 
417  template <typename F>
419  {
420  return from.clone();
421  }
422 
425 
426  template <typename FS>
427  inline bool DtIsEmpty(const FS& fs)
428  {
429  return fs.empty();
430  }
431 
432  template <typename FS>
433  inline bool DtIsEmpty(FS* fs)
434  {
435  if (!fs)
436  return true;
437 
438  return DtIsEmpty(*fs);
439  }
441 
443 }
444 
446 #define DT_INSTANTIATE_FEATURE_SETS(F) \
447  template class MAKVRinTerra::DtFeatureSetTemplate<F>; \
448  template class MAKVRinTerra::DtFeatureSetList< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
449  template class MAKVRinTerra::DtFeatureSetArray<4, MAKVRinTerra::DtFeatureSetTemplate<F> >; \
450  template class MAKVRinTerra::DtFilteredFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
451  template class MAKVRinTerra::DtEmptyFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
452  template class MAKVRinTerra::DtSinkFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
453  template class MAKVRinTerra::DtSourceFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
454  template class MAKVRinTerra::DtAsyncLoadingFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
455  template class MAKVRinTerra::DtPagingFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
456 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)