VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
featureSet.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2020 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 
19 #include <boost/optional.hpp>
20 #include <boost/noncopyable.hpp>
21 
22 #include <vrfutil/objectCounter.h>
24 
25 namespace MAKVRinTerra
26 {
27  class DtFeature;
28  class DtQuery;
29  class DtFeatureGeometry;
30 
34  {
43  };
44 
46  {
47  public:
48  virtual void layerName(const std::string&) = 0;
49  virtual void percent(double) = 0;
50  virtual bool isCancelled() = 0;
51  };
52 
57  template <typename T>
58  using DtUniquePtr = std::unique_ptr<T, std::default_delete<T> >;
59 
60  template <
61  typename FS,
62  template <typename> class PtrTemplate = DtUniquePtr,
63  typename InnerFS = FS>
65 
67  {
68  public:
70  };
71 
72  template <typename FS, typename InnerFS = FS>
74 
75  template <size_t N, typename FS, typename InnerFS = FS>
77 
78  template <typename FS>
80 
81  template <typename FS>
83 
84  template <typename FS, typename F = typename FS::Feature>
86 
87  template <typename FS>
89 
104  template <typename F>
106  : private boost::noncopyable
107 #ifdef DtObjectDebugger_Enable
108  , public DtObjectDebugger< DtFeatureSetTemplate<F> >
109 #endif
110  {
111  public:
112 
113  DtFeatureSetTemplate() : myBlockOnAsynchronousOperations(false) {};
114 
116  typedef F Feature;
117 
120 
132  typedef boost::function<void ()> DetachCallback;
133 
135  class DetachScopeGuard : boost::noncopyable
136  {
138 
139  public:
141  callback(cb) {};
143  {
144  if (callback)
145  {
146  callback();
147  }
148  };
149 
150  void reset(const DetachCallback& cb = DetachCallback())
151  {
152  if (callback)
153  callback();
154 
155  callback = cb;
156  };
157  };
158 
160  typedef boost::function<void (const Feature&)> ForEachFunction;
161 
163  typedef boost::function<void ()> LoadedCallback;
164 
167 
170 
172 
179 
192  template <typename FS>
193  static FeatureSet* Wrap(FS* fs)
194  {
195  std::unique_ptr<FS> set(fs);
196  return Wrap(std::move(set));
197  }
198 
200  {
201  return fs;
202  }
203 
204  static DtFeatureSetTemplate* Wrap(std::unique_ptr<FeatureSet> fs)
205  {
206  return fs.release();
207  }
208 
209  template <typename FS>
210  static FeatureSet* Wrap(std::unique_ptr<FS> fs)
211  {
212  if (!fs.get() || fs->elided())
213  return 0;
214 
215  return new DtFeatureSetWrapper<FeatureSet, DtUniquePtr, FS>(std::move(fs));
216  }
217 
218  template <typename FS>
219  static FeatureSet* Wrap(const std::shared_ptr<FS>& fs)
220  {
221  if (!fs || fs->elided())
222  return 0;
223 
225  }
226 
227  template <typename FS>
228  static FeatureSet* Wrap(const std::weak_ptr<FS>& fs)
229  {
230  std::shared_ptr<FS> ptr(fs.lock());
231  if (!ptr || ptr->elided())
232  return 0;
233 
235  }
237 
239  virtual ~DtFeatureSetTemplate();
240 
242  virtual DtFeatureSetTemplate* setBlockOnAsynchronousOperations(bool block);
243 
244  virtual bool blockOnAsynchronousOperations() const;
245 
249  virtual std::string label() const = 0;
250 
258  virtual void forEachFeatureParallel(const ForEachFunction& func) const = 0;
259 
261  void forEachFeature(const ForEachFunction& func) const;
262 
265 
266  bool forEachFeatureParallelBlock(const ForEachFunction& func, double timeout = 60) const;
267  bool forEachFeatureBlock(const ForEachFunction& func, double timeout = 60) const;
269 
294  virtual DetachCallback forEachFeatureAsync(const ForEachFunction& func) const = 0;
296 
307 
308  virtual DtFeatureSetTemplate* filter(
309  const DtQuery& query,
310  const boost::optional<DtFeatureGeometry>& geometry,
311  DtLoadType load) const;
312 
313  DtFeatureSetTemplate* filter(
314  const DtQuery& query, DtLoadType load) const;
315 
316  DtFeatureSetTemplate* filter(
317  const boost::optional<DtFeatureGeometry>& geometry, DtLoadType load) const;
319 
326 
327  virtual bool load(
328  const DtQuery& query,
329  const boost::optional<DtFeatureGeometry>& geometry) const;
330 
331  bool load(const DtQuery& query) const;
332  bool load(const boost::optional<DtFeatureGeometry>& geometry) const;
334 
341  virtual DtFeatureSetTemplate* clone() const = 0;
342 
360  virtual bool loaded(double timeout=0.0) const = 0;
361 
371  virtual DetachCallback addLoadedCallback(const LoadedCallback&) const = 0;
372 
382  virtual bool elided() const = 0;
383 
391  virtual bool empty() const = 0;
392 
395  virtual bool isIndexed() const;
396 
400  virtual bool isCacheable(const boost::optional<DtFeatureGeometry>& area = boost::none_t()) const;
401 
405  virtual void cacheEstimate(
406  double& time, double& size,
407  const boost::optional<DtFeatureGeometry>& area = boost::none_t()) const;
408 
411  virtual void cacheData(
412  const boost::optional<DtFeatureGeometry>& area = boost::none_t(),
413  DtFeatureCacheProgressCallback* progress = 0) const;
415 
430  virtual unsigned numberOfFeatures() const;
431 
436 
438  {
439  public:
440  virtual ~Visitor();
441  virtual void visit(FeatureSet&) = 0;
442  };
443 
445  {
446  public:
447  virtual ~ConstVisitor();
448  virtual void visit(const FeatureSet&) = 0;
449  };
451 
456 
457  virtual void accept(Visitor&);
458  virtual void accept(ConstVisitor&) const;
460 
461  protected:
462  class SynchronizedFunction;
463  struct FeatureCounter;
464 
466  };
467 
469  template <typename F>
471  {
472  return from.clone();
473  }
474 
477 
478  template <typename FS>
479  inline bool DtIsElided(const FS& fs)
480  {
481  return fs.elided();
482  }
483 
484  template <typename FS>
485  inline bool DtIsElided(FS* fs)
486  {
487  if (!fs)
488  return true;
489 
490  return DtIsElided(*fs);
491  }
493 
495 }
496 
498 #define DT_INSTANTIATE_FEATURE_SETS(F) \
499  template class MAKVRinTerra::DtFeatureSetTemplate<F>; \
500  template class MAKVRinTerra::DtFeatureSetList< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
501  template class MAKVRinTerra::DtFeatureSetArray<4, MAKVRinTerra::DtFeatureSetTemplate<F> >; \
502  template class MAKVRinTerra::DtFilteredFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
503  template class MAKVRinTerra::DtEmptyFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
504  template class MAKVRinTerra::DtSinkFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
505  template class MAKVRinTerra::DtSourceFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
506  template class MAKVRinTerra::DtAsyncLoadingFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
507  template class MAKVRinTerra::DtPagingFeatureSet< MAKVRinTerra::DtFeatureSetTemplate<F> >; \
508 
Represents a set of DtFeature objects or others which conform to the DtFeature concept.
Definition: featureSet.h:105
DtFeatureSet which filters out features from a feature set. Wraps a feature set with a geometry and q...
Definition: featureSetUtils.h:45
boost::function< void(const Feature &)> ForEachFunction
Callback type type for iterating through features.
Definition: featureSet.h:160
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
virtual DtFeatureSetTemplate * clone() const =0
Clone the feature set. Called assumes ownership of returned feature set. Implementation should share ...
void reset(const DetachCallback &cb=DetachCallback())
Definition: featureSet.h:150
DtFilteredFeatureSet< FeatureSet > Filtered
Typedefs for various features system framework classes.
Definition: featureSet.h:174
Definition: featureSetList.h:98
static FeatureSet * Wrap(FS *fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:193
boost::function< void()> DetachCallback
Callback type for disconnecting other callbacks. Functions which register callbacks return a DetachCa...
Definition: featureSet.h:132
DtFeatureSetWrapper< FeatureSet, std::shared_ptr > SharedWrapper
Wraps a std::shared_ptr to a feature set.
Definition: featureSet.h:169
DtFeatureSetWrapper< FeatureSet, DtUniquePtr > ScopedWrapper
Wraps a std::unique_ptr to a feature set.
Definition: featureSet.h:166
DtFeatureSetTemplate()
Definition: featureSet.h:113
static FeatureSet * Wrap(const std::weak_ptr< FS > &fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:228
Load all features which may be in the feature set.
Definition: featureSet.h:36
voidpf void uLong size
Definition: ioapi.h:39
Do not initiate new loads, read whatever is currently loaded.
Definition: featureSet.h:42
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
DtSourceFeatureSet< FeatureSet > Source
Typedefs for various features system framework classes.
Definition: featureSet.h:177
Default on in debug, off in release.
Definition: objectCounter.h:27
Definition: featureSet.h:64
DtEmptyFeatureSet< FeatureSet > Empty
Typedefs for various features system framework classes.
Definition: featureSet.h:175
DtFeatureSetTemplate FeatureSet
Feature set type.
Definition: featureSet.h:119
DtFeatureSetList< FeatureSet > List
Typedefs for various features system framework classes.
Definition: featureSet.h:173
static FeatureSet * Wrap(std::unique_ptr< FS > fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:210
Load all features but try to do as little work in the calling thread as possible. Not all feature set...
Definition: featureSet.h:40
DtFeatureSetTemplate< F > * new_clone(const DtFeatureSetTemplate< F > &from)
Makes DtFeatureSetTemplate usable with boost pointer containers.
Definition: featureSet.h:470
Definition: feature.h:26
Feature set object which will take another feature set, iterate over its contents asynchronously and ...
Definition: featureSetUtils.h:141
DetachScopeGuard(const DetachCallback &cb=DetachCallback())
Definition: featureSet.h:140
Represents a set of characeters a DtFeature object can have. DtQuery objects are the way to communica...
Definition: query.h:37
#define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type)
Definition: objectCounter.h:32
static FeatureSet * Wrap(const std::shared_ptr< FS > &fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:219
Dummy feature set which contains no features.
Definition: featureSetUtils.h:100
static DtFeatureSetTemplate * Wrap(std::unique_ptr< FeatureSet > fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:204
bool myBlockOnAsynchronousOperations
Definition: featureSet.h:463
bool DtIsElided(const FS &fs)
Helper functions using null pointers to feature sets to denote empty feature sets. This helps avoid dynamically allocating lots of empty feature sets.
Definition: featureSet.h:479
DtLoadType
Used to indicate whether to load features. See DtFeatureSetTemplate::filter.
Definition: featureSet.h:33
DtFeatureSetTemplate< DtFeature > DtFeatureSet
Definition: featureSet.h:494
DetachCallback callback
Definition: featureSet.h:137
Source feature sets are used to create your own feature sets with your own features.
Definition: featureSetUtils.h:287
std::unique_ptr< T, std::default_delete< T > > DtUniquePtr
Defining a unique_ptr that takes a single template argument instead of two This works around a C3201 ...
Definition: featureSet.h:58
Scope guard which will automatically call detach callback in destructor.
Definition: featureSet.h:135
DtFeatureSet used to combine multiple feature sets into one. This class allows all feature set algori...
Definition: featureSetList.h:26
boost::function< void()> LoadedCallback
Callback type type for async notification of feature set loading.
Definition: featureSet.h:163
static DtFeatureSetTemplate * Wrap(DtFeatureSetTemplate *fs)
Wrap a compatible feature set type in the interface of this feature set type. The Wrap functions are ...
Definition: featureSet.h:199
DtSinkFeatureSet< FeatureSet > Sink
Typedefs for various features system framework classes.
Definition: featureSet.h:176
Visitors allow feature sets which are implemented as compound structures of other feature sets to exp...
Definition: featureSet.h:437

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)