17 #include <boost/signals2.hpp>
19 #include <tbb/spin_mutex.h>
20 #include <tbb/spin_rw_mutex.h>
21 #include <tbb/null_rw_mutex.h>
32 namespace MAKVRinTerra
42 Derived*
This() {
return static_cast<Derived*
>(
this); }
43 const Derived*
This()
const {
return static_cast<const Derived*
>(
this); }
52 typedef typename FeatureSet::Feature
Feature;
57 typedef std::shared_ptr<Inner>
Ptr;
58 typedef std::shared_ptr<const Inner>
CPtr;
60 template <
typename Function=ForEachFunction>
67 return handle->label();
69 return "empty feature set wrapper";
77 return handle->numberOfFeatures();
86 return handle->elided();
95 return handle->empty();
104 return handle->isIndexed();
106 return FS::isIndexed();
109 bool isCacheable(
const boost::optional<DtFeatureGeometry>& area)
const
113 return handle->isCacheable(area);
115 return FS::isCacheable(area);
118 void cacheEstimate(
double& time,
double&
size,
const boost::optional<DtFeatureGeometry>& area)
const
122 handle->cacheEstimate(time, size, area);
124 return FS::cacheEstimate(time, size, area);
128 const boost::optional<DtFeatureGeometry>& area,
133 handle->cacheData(area, progress);
135 FS::cacheData(area, progress);
142 return handle->loaded(timeout);
151 return handle->loaded(timeout);
157 #ifdef DtObjectDebugger_Enable
172 boost::signals2::connection conn =
myLoadedSignal->connect(LoadedCounter(cb));
176 return boost::bind(&boost::signals2::connection::disconnect, conn);
189 handle->forEachFeatureParallel(func);
194 typedef CallbackRecord<ForEachFunction> Record;
195 typedef typename Record::Ptr RecordPtr;
202 detacher = handle->forEachFeatureAsync(func);
208 RecordPtr newHead(Record::Make(func,
myHead, detacher));
209 const_cast<RecordPtr&
>(
myHead) = newHead;
210 return typename Record::Detacher(newHead);
223 const boost::optional<DtFeatureGeometry>& geometry,
228 return this->Wrap(handle->filter(query, geometry, load));
232 DtTHROW_NEW(
DtException,
"filtered empty feature set wrapper");
237 return FS::filter(query, load);
242 return FS::filter(geometry, load);
246 template <
typename Function>
248 #ifdef DtObjectDebugger_Enable
253 typedef std::shared_ptr<CallbackRecord>
Ptr;
254 typedef std::weak_ptr<CallbackRecord>
WPtr;
257 #ifdef DtObjectDebugger_Enable
263 std::shared_ptr<CallbackRecord> callback(
callbackWptr.lock());
268 explicit Detacher(
const std::shared_ptr<CallbackRecord>& rec)
279 Mutex::scoped_lock lock(newRec->next->mutex);
280 if (newRec->next->func)
283 newRec->next = newRec->next->next;
293 Mutex::scoped_lock lock(
mutex);
325 ne->addCallbacksTo(fs);
343 Mutex::scoped_lock lock(
mutex);
362 lock.acquire(pr->mutex);
367 pr = pr->prev.lock();
372 Mutex::scoped_lock endLock(ne->mutex);
398 const Function&
func,
422 myHead->addCallbacksTo(fs);
439 typedef boost::signals2::signal_type<
441 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
LoadedSignal;
444 #ifdef DtObjectDebugger_Enable
448 std::weak_ptr<LoadedSignal>
sig;
454 std::shared_ptr<LoadedSignal> signal(
sig.lock());
468 template <
typename>
class PtrTemplate,
472 template <
typename FS,
typename Inner>
486 template <
typename OtherFS>
488 : mySet(fs.release())
494 const Inner*
getPtr()
const {
return mySet.get(); }
498 return mySet->label();
503 return mySet->numberOfFeatures();
508 return mySet->elided();
513 return mySet->empty();
518 return mySet->isIndexed();
521 bool isCacheable(
const boost::optional<DtFeatureGeometry>& area)
const
523 return mySet->isCacheable(area);
526 void cacheEstimate(
double& time,
double&
size,
const boost::optional<DtFeatureGeometry>& area)
const
528 mySet->cacheEstimate(time, size, area);
532 const boost::optional<DtFeatureGeometry>& area,
535 mySet->cacheData(area, progress);
540 return mySet->loaded(timeout);
545 return mySet->addLoadedCallback(cb);
550 mySet->forEachFeatureParallel(func);
555 return mySet->forEachFeatureAsync(func);
560 const boost::optional<DtFeatureGeometry>& geometry,
563 return this->Wrap(mySet->filter(query, geometry, load));
568 return this->Wrap(mySet->clone());
575 template <
typename FS,
typename Inner>
578 DtFeatureSetWrapper<FS,std::shared_ptr,Inner>,
590 setPtr(std::shared_ptr<Inner>(fs));
593 template <
typename OtherFS>
597 setPtr(std::shared_ptr<Inner>(fs.release()));
600 template <
typename OtherFS>
609 Mutex::scoped_lock lock(myMutex,
false);
613 std::shared_ptr<const Inner>
getPtr()
const
615 Mutex::scoped_lock lock(myMutex,
false);
619 std::shared_ptr<Inner>
setPtr(
const std::shared_ptr<Inner>& p)
621 Mutex::scoped_lock lock(myMutex,
false);
625 if (!lock.upgrade_to_writer() && mySet && p)
630 lock.downgrade_to_reader();
631 this->setupCallbacks(p);
636 std::shared_ptr<Inner>
setPtr(Inner* set)
638 std::shared_ptr<Inner> fs(set);
644 return this->Wrap(getPtr());
654 template <
typename FS,
typename Inner>
657 DtFeatureSetWrapper<FS,std::weak_ptr,Inner>,
669 template <
typename T>
675 template <
typename T>
684 Mutex::scoped_lock lock(myMutex,
false);
688 std::shared_ptr<const Inner>
getPtr()
const
690 Mutex::scoped_lock lock(myMutex,
false);
699 std::shared_ptr<Inner>
setPtr(
const std::shared_ptr<Inner>& p)
701 Mutex::scoped_lock lock(myMutex,
false);
704 std::shared_ptr<Inner> s(mySet.lock());
709 if (!lock.upgrade_to_writer() && p)
711 std::shared_ptr<Inner> s(mySet.lock());
718 lock.downgrade_to_reader();
719 this->setupCallbacks(p);
726 Mutex::scoped_lock lock(myMutex,
false);
727 return this->Wrap(mySet);
std::weak_ptr< CallbackRecord > WPtr
Definition: featureSetWrappers.h:254
FeatureSet::Feature Feature
Definition: featureSetWrappers.h:52
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:731
const Inner * getPtr() const
Definition: featureSetWrappers.h:494
std::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:613
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:501
FS * clone() const
Definition: featureSetWrappers.h:642
CallbackRecord::Ptr myHead
Definition: featureSetWrappers.h:461
tbb::spin_mutex CallbackMutex
Definition: featureSetWrappers.h:438
Mutex myMutex
Definition: featureSetWrappers.h:649
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:664
std::shared_ptr< Inner > getMutablePtr() const
Definition: featureSetWrappers.h:694
DtFeatureSetWrapper(const std::shared_ptr< OtherFS > &fs)
Definition: featureSetWrappers.h:601
std::string label() const
Definition: featureSetWrappers.h:496
const LoadedCallback callback
Definition: featureSetWrappers.h:161
FeatureSet::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:53
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:587
Definition: featureSet.h:45
FS * clone() const
Definition: featureSetWrappers.h:566
Mutex myMutex
Definition: featureSetWrappers.h:732
FeatureSet::DetachCallback DetachCallback
Definition: featureSetWrappers.h:54
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:648
voidpf void uLong size
Definition: ioapi.h:39
std::shared_ptr< Inner > Ptr
Definition: featureSetWrappers.h:57
std::weak_ptr< Inner > mySet
Definition: featureSetWrappers.h:734
WPtr prev
Definition: featureSetWrappers.h:409
std::shared_ptr< Inner > mySet
Definition: featureSetWrappers.h:651
DtFeatureSetWrapper(const std::shared_ptr< T > &fs)
Definition: featureSetWrappers.h:676
Wrapper which transforms feature set types.
Definition: featureSetWrappers.h:39
Ptr next
Definition: featureSetWrappers.h:410
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:543
FeatureSet * filter(const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:240
bool elided() const
Definition: featureSetWrappers.h:82
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Mutex mutex
Definition: featureSetWrappers.h:407
bool elided() const
Definition: featureSetWrappers.h:506
Default on in debug, off in release.
Definition: objectCounter.h:27
FS::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:478
Definition: featureSet.h:64
Definition: featureSetWrappers.h:61
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:479
void cacheData(const boost::optional< DtFeatureGeometry > &area, DtFeatureCacheProgressCallback *progress) const
Definition: featureSetWrappers.h:127
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:477
const std::unique_ptr< Inner > mySet
Definition: featureSetWrappers.h:572
Detacher(const std::shared_ptr< CallbackRecord > &rec)
Definition: featureSetWrappers.h:268
LoadedCounter(const LoadedCallback &cb)
Definition: featureSetWrappers.h:162
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:666
void operator()() const
Definition: featureSetWrappers.h:261
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:73
std::shared_ptr< Inner > setPtr(Inner *set)
Definition: featureSetWrappers.h:636
DtFeatureSetWrapperTemplate()
Definition: featureSetWrappers.h:45
std::shared_ptr< CallbackRecord > Ptr
Definition: featureSetWrappers.h:253
virtual bool loadedThrowIfNotSet(double timeout=0.0) const
Definition: featureSetWrappers.h:147
std::weak_ptr< CallbackRecord > callbackWptr
Definition: featureSetWrappers.h:271
Represents a set of characeters a DtFeature object can have. DtQuery objects are the way to communica...
Definition: query.h:37
static Ptr Make(const Function &func, const Ptr &curHead, const DetachCallback &detach)
Definition: featureSetWrappers.h:274
std::shared_ptr< Inner > setPtr(const std::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:699
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:553
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:663
bool empty() const
Definition: featureSetWrappers.h:511
FeatureSet::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:55
Function func
Definition: featureSetWrappers.h:408
DtFeatureSetWrapper(std::unique_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:594
DtFeatureSetWrapper(std::unique_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:487
bool isCacheable(const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:521
Definition: featureSetWrappers.h:26
tbb::spin_mutex Mutex
Definition: featureSetWrappers.h:394
std::shared_ptr< LoadedSignal > myLoadedSignal
Definition: featureSetWrappers.h:462
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:526
DtFeatureSetWrapper(const std::weak_ptr< T > &fs)
Definition: featureSetWrappers.h:670
Inner * getPtr()
Definition: featureSetWrappers.h:493
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:138
~CallbackRecord()
Definition: featureSetWrappers.h:388
Definition: featureSetWrappers.h:23
Definition: featureSetWrappers.h:156
CallbackMutex myCallbackMutex
Definition: featureSetWrappers.h:460
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:166
bool empty() const
Definition: featureSetWrappers.h:91
std::shared_ptr< const Inner > CPtr
Definition: featureSetWrappers.h:58
std::string label() const
Definition: featureSetWrappers.h:63
void addCallbacksTo(const CPtr &fs)
called by setPtr when a wrapper has it's wrapped feature set we must call all the saved callbacks on ...
Definition: featureSetWrappers.h:291
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:192
DtLoadType
Used to indicate whether to load features. See DtFeatureSetTemplate::filter.
Definition: featureSet.h:33
const Derived * This() const
Definition: featureSetWrappers.h:43
DetachCallback detacher
Definition: featureSetWrappers.h:411
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type LoadedSignal
Definition: featureSetWrappers.h:441
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:538
Definition: featureSetWrappers.h:256
Derived * This()
Definition: featureSetWrappers.h:42
FS::Feature Feature
Definition: featureSetWrappers.h:662
std::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:607
void operator()() const
Definition: featureSetWrappers.h:452
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:481
LoadedCaller(const std::shared_ptr< LoadedSignal > &sig)
Definition: featureSetWrappers.h:449
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:583
Definition: featureSetWrappers.h:29
std::weak_ptr< LoadedSignal > sig
Definition: featureSetWrappers.h:448
bool isIndexed() const
Definition: featureSetWrappers.h:516
void setupCallbacks(const CPtr &fs)
Definition: featureSetWrappers.h:415
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:548
FS FeatureSet
Definition: featureSetWrappers.h:51
Definition: featureSet.h:66
std::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:682
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
FeatureSet::DetachScopeGuard myLoadedSignalDetacher
Definition: featureSetWrappers.h:463
FS * clone() const
Definition: featureSetWrappers.h:724
void operator()() const
Definition: featureSetWrappers.h:163
std::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:688
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:185
FeatureSet * filter(const DtQuery &query, DtLoadType load) const
Definition: featureSetWrappers.h:235
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:118
FS * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:558
std::shared_ptr< Inner > setPtr(const std::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:619
void detach()
Definition: featureSetWrappers.h:341
FS::Feature Feature
Definition: featureSetWrappers.h:476
FeatureSet * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:221
bool isCacheable(const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:109
CallbackRecord(const Function &func, const Ptr &next, const DetachCallback &detach)
Definition: featureSetWrappers.h:397
bool isIndexed() const
Definition: featureSetWrappers.h:100
Definition: featureSetWrappers.h:443
void cacheData(const boost::optional< DtFeatureGeometry > &area, DtFeatureCacheProgressCallback *progress) const
Definition: featureSetWrappers.h:531