17 #include <boost/scoped_ptr.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/weak_ptr.hpp>
20 #include <boost/foreach.hpp>
21 #include <boost/signals2.hpp>
23 #include <tbb/spin_mutex.h>
24 #include <tbb/spin_rw_mutex.h>
25 #include <tbb/null_rw_mutex.h>
36 namespace MAKVRinTerra
46 Derived*
This() {
return static_cast<Derived*
>(
this); }
47 const Derived*
This()
const {
return static_cast<const Derived*
>(
this); }
56 typedef typename FeatureSet::Feature
Feature;
61 typedef boost::shared_ptr<Inner>
Ptr;
62 typedef boost::shared_ptr<const Inner>
CPtr;
64 template <
typename Function=ForEachFunction>
71 return handle->label();
73 return "empty feature set wrapper";
81 return handle->numberOfFeatures();
90 return handle->elided();
99 return handle->empty();
108 return handle->isIndexed();
110 return FS::isIndexed();
113 bool isCacheable(
const boost::optional<DtFeatureGeometry>& area)
const
117 return handle->isCacheable(area);
119 return FS::isCacheable(area);
122 void cacheEstimate(
double& time,
double&
size,
const boost::optional<DtFeatureGeometry>& area)
const
126 handle->cacheEstimate(time, size, area);
128 return FS::cacheEstimate(time, size, area);
132 const boost::optional<DtFeatureGeometry>& area,
137 handle->cacheData(area, progress);
139 FS::cacheData(area, progress);
146 return handle->loaded(timeout);
155 return handle->loaded(timeout);
174 boost::signals2::connection conn =
myLoadedSignal->connect(LoadedCounter(cb));
178 return boost::bind(&boost::signals2::connection::disconnect, conn);
191 handle->forEachFeatureParallel(func);
196 typedef CallbackRecord<ForEachFunction> Record;
197 typedef typename Record::Ptr RecordPtr;
204 detacher = handle->forEachFeatureAsync(func);
210 RecordPtr newHead(Record::Make(func,
myHead, detacher));
211 const_cast<RecordPtr&
>(
myHead) = newHead;
212 return typename Record::Detacher(newHead);
225 const boost::optional<DtFeatureGeometry>& geometry,
230 return this->Wrap(handle->filter(query, geometry, load));
234 DtTHROW_NEW(
DtException,
"filtered empty feature set wrapper");
239 return FS::filter(query, load);
244 return FS::filter(geometry, load);
248 template <
typename Function>
253 typedef boost::shared_ptr<CallbackRecord>
Ptr;
254 typedef boost::weak_ptr<CallbackRecord>
WPtr;
261 boost::shared_ptr<CallbackRecord> callback(
callbackWptr.lock());
266 explicit Detacher(
const boost::shared_ptr<CallbackRecord>& rec)
277 Mutex::scoped_lock lock(newRec->next->mutex);
278 if (newRec->next->func)
281 newRec->next = newRec->next->next;
291 Mutex::scoped_lock lock(
mutex);
323 ne->addCallbacksTo(fs);
341 Mutex::scoped_lock lock(
mutex);
360 lock.acquire(pr->mutex);
365 pr = pr->prev.lock();
370 Mutex::scoped_lock endLock(ne->mutex);
396 const Function&
func,
420 myHead->addCallbacksTo(fs);
437 typedef boost::signals2::signal_type<
439 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
LoadedSignal;
443 boost::weak_ptr<LoadedSignal>
sig;
449 boost::shared_ptr<LoadedSignal> signal(
sig.lock());
463 template <
typename>
class PtrTemplate,
467 template <
typename FS,
typename Inner>
481 template <
typename OtherFS>
483 : mySet(fs.release())
489 const Inner*
getPtr()
const {
return mySet.get(); }
493 return mySet->label();
498 return mySet->numberOfFeatures();
503 return mySet->elided();
508 return mySet->empty();
513 return mySet->isIndexed();
516 bool isCacheable(
const boost::optional<DtFeatureGeometry>& area)
const
518 return mySet->isCacheable(area);
521 void cacheEstimate(
double& time,
double&
size,
const boost::optional<DtFeatureGeometry>& area)
const
523 mySet->cacheEstimate(time, size, area);
527 const boost::optional<DtFeatureGeometry>& area,
530 mySet->cacheData(area, progress);
535 return mySet->loaded(timeout);
540 return mySet->addLoadedCallback(cb);
545 mySet->forEachFeatureParallel(func);
550 return mySet->forEachFeatureAsync(func);
555 const boost::optional<DtFeatureGeometry>& geometry,
558 return this->Wrap(mySet->filter(query, geometry, load));
563 return this->Wrap(mySet->clone());
567 const boost::scoped_ptr<Inner>
mySet;
570 template <
typename FS,
typename Inner>
573 DtFeatureSetWrapper<FS,boost::shared_ptr,Inner>,
585 setPtr(boost::shared_ptr<Inner>(fs));
588 template <
typename OtherFS>
592 setPtr(boost::shared_ptr<Inner>(fs.release()));
595 template <
typename OtherFS>
604 Mutex::scoped_lock lock(myMutex,
false);
608 boost::shared_ptr<const Inner>
getPtr()
const
610 Mutex::scoped_lock lock(myMutex,
false);
614 boost::shared_ptr<Inner>
setPtr(
const boost::shared_ptr<Inner>& p)
616 Mutex::scoped_lock lock(myMutex,
false);
620 if (!lock.upgrade_to_writer() && mySet && p)
625 lock.downgrade_to_reader();
626 this->setupCallbacks(p);
631 boost::shared_ptr<Inner>
setPtr(Inner* set)
633 boost::shared_ptr<Inner> fs(set);
639 return this->Wrap(getPtr());
649 template <
typename FS,
typename Inner>
652 DtFeatureSetWrapper<FS,boost::weak_ptr,Inner>,
664 template <
typename T>
670 template <
typename T>
679 Mutex::scoped_lock lock(myMutex,
false);
683 boost::shared_ptr<const Inner>
getPtr()
const
685 Mutex::scoped_lock lock(myMutex,
false);
694 boost::shared_ptr<Inner>
setPtr(
const boost::shared_ptr<Inner>& p)
696 Mutex::scoped_lock lock(myMutex,
false);
699 boost::shared_ptr<Inner> s(mySet.lock());
704 if (!lock.upgrade_to_writer() && p)
706 boost::shared_ptr<Inner> s(mySet.lock());
713 lock.downgrade_to_reader();
714 this->setupCallbacks(p);
721 Mutex::scoped_lock lock(myMutex,
false);
722 return this->Wrap(mySet);
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:659
const Inner * getPtr() const
Definition: featureSetWrappers.h:489
boost::shared_ptr< Inner > Ptr
Definition: featureSetWrappers.h:61
FeatureSet::Feature Feature
Definition: featureSetWrappers.h:56
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:578
CallbackRecord::Ptr myHead
Definition: featureSetWrappers.h:456
tbb::spin_mutex CallbackMutex
Definition: featureSetWrappers.h:436
boost::weak_ptr< Inner > mySet
Definition: featureSetWrappers.h:729
const LoadedCallback callback
Definition: featureSetWrappers.h:163
FeatureSet::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:57
Inner * getPtr()
Definition: featureSetWrappers.h:488
bool isCacheable(const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:516
DtFeatureSetWrapper(std::auto_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:482
Definition: featureSet.h:48
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:521
boost::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:602
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:643
FS::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:473
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:474
FeatureSet::DetachCallback DetachCallback
Definition: featureSetWrappers.h:58
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:661
voidpf void uLong size
Definition: ioapi.h:39
WPtr prev
Definition: featureSetWrappers.h:407
Wrapper which transforms feature set types.
Definition: featureSetWrappers.h:43
Ptr next
Definition: featureSetWrappers.h:408
FeatureSet * filter(const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:242
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:496
bool elided() const
Definition: featureSetWrappers.h:86
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Mutex mutex
Definition: featureSetWrappers.h:405
Detacher(const boost::shared_ptr< CallbackRecord > &rec)
Definition: featureSetWrappers.h:266
Default on in debug, off in release.
Definition: objectCounter.h:31
boost::shared_ptr< LoadedSignal > myLoadedSignal
Definition: featureSetWrappers.h:457
Definition: featureSet.h:60
DtFeatureSetWrapper(std::auto_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:589
Definition: featureSetWrappers.h:65
void cacheData(const boost::optional< DtFeatureGeometry > &area, DtFeatureCacheProgressCallback *progress) const
Definition: featureSetWrappers.h:131
LoadedCounter(const LoadedCallback &cb)
Definition: featureSetWrappers.h:164
boost::shared_ptr< const Inner > CPtr
Definition: featureSetWrappers.h:62
FS * clone() const
Definition: featureSetWrappers.h:719
boost::shared_ptr< Inner > setPtr(const boost::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:694
void operator()() const
Definition: featureSetWrappers.h:259
boost::shared_ptr< Inner > setPtr(Inner *set)
Definition: featureSetWrappers.h:631
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:77
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:538
std::string label() const
Definition: featureSetWrappers.h:491
DtFeatureSetWrapperTemplate()
Definition: featureSetWrappers.h:49
const boost::scoped_ptr< Inner > mySet
Definition: featureSetWrappers.h:567
virtual bool loadedThrowIfNotSet(double timeout=0.0) const
Definition: featureSetWrappers.h:151
boost::weak_ptr< CallbackRecord > callbackWptr
Definition: featureSetWrappers.h:269
Represents a set of characeters a DtFeature object can have.
Definition: query.h:38
static Ptr Make(const Function &func, const Ptr &curHead, const DetachCallback &detach)
Definition: featureSetWrappers.h:272
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
boost::weak_ptr< CallbackRecord > WPtr
Definition: featureSetWrappers.h:254
boost::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:677
bool elided() const
Definition: featureSetWrappers.h:501
FeatureSet::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:59
boost::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:608
Function func
Definition: featureSetWrappers.h:406
Definition: featureSetWrappers.h:30
tbb::spin_mutex Mutex
Definition: featureSetWrappers.h:392
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:582
FS * clone() const
Definition: featureSetWrappers.h:637
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:142
Mutex myMutex
Definition: featureSetWrappers.h:644
~CallbackRecord()
Definition: featureSetWrappers.h:386
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:658
Definition: featureSetWrappers.h:27
Definition: featureSetWrappers.h:160
boost::shared_ptr< Inner > setPtr(const boost::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:614
DtFeatureSetWrapper(const boost::weak_ptr< T > &fs)
Definition: featureSetWrappers.h:665
CallbackMutex myCallbackMutex
Definition: featureSetWrappers.h:455
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:168
Mutex myMutex
Definition: featureSetWrappers.h:727
DtFeatureSetWrapper(const boost::shared_ptr< T > &fs)
Definition: featureSetWrappers.h:671
bool empty() const
Definition: featureSetWrappers.h:95
std::string label() const
Definition: featureSetWrappers.h:67
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:289
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:194
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:548
boost::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:683
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:472
DtLoadType
Used to indicate whether to load features.
Definition: featureSet.h:36
const Derived * This() const
Definition: featureSetWrappers.h:47
DetachCallback detacher
Definition: featureSetWrappers.h:409
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type LoadedSignal
Definition: featureSetWrappers.h:439
bool isIndexed() const
Definition: featureSetWrappers.h:511
Definition: featureSetWrappers.h:256
Derived * This()
Definition: featureSetWrappers.h:46
DtFeatureSetWrapper(const boost::shared_ptr< OtherFS > &fs)
Definition: featureSetWrappers.h:596
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:476
void operator()() const
Definition: featureSetWrappers.h:447
void cacheData(const boost::optional< DtFeatureGeometry > &area, DtFeatureCacheProgressCallback *progress) const
Definition: featureSetWrappers.h:526
FS::Feature Feature
Definition: featureSetWrappers.h:657
Definition: featureSetWrappers.h:33
void setupCallbacks(const CPtr &fs)
Definition: featureSetWrappers.h:413
FS FeatureSet
Definition: featureSetWrappers.h:55
Definition: featureSet.h:62
FS::Feature Feature
Definition: featureSetWrappers.h:471
boost::weak_ptr< LoadedSignal > sig
Definition: featureSetWrappers.h:443
FeatureSet::DetachScopeGuard myLoadedSignalDetacher
Definition: featureSetWrappers.h:458
FS * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:553
LoadedCaller(const boost::shared_ptr< LoadedSignal > &sig)
Definition: featureSetWrappers.h:444
bool empty() const
Definition: featureSetWrappers.h:506
void operator()() const
Definition: featureSetWrappers.h:165
FS * clone() const
Definition: featureSetWrappers.h:561
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:187
FeatureSet * filter(const DtQuery &query, DtLoadType load) const
Definition: featureSetWrappers.h:237
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:122
void detach()
Definition: featureSetWrappers.h:339
FeatureSet * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:223
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:533
bool isCacheable(const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:113
CallbackRecord(const Function &func, const Ptr &next, const DetachCallback &detach)
Definition: featureSetWrappers.h:395
bool isIndexed() const
Definition: featureSetWrappers.h:104
Definition: featureSetWrappers.h:441
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:543
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:726
boost::shared_ptr< CallbackRecord > Ptr
Definition: featureSetWrappers.h:253
boost::shared_ptr< Inner > getMutablePtr() const
Definition: featureSetWrappers.h:689
boost::shared_ptr< Inner > mySet
Definition: featureSetWrappers.h:646