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);
161 #ifdef DtObjectDebugger_Enable
176 boost::signals2::connection conn =
myLoadedSignal->connect(LoadedCounter(cb));
180 return boost::bind(&boost::signals2::connection::disconnect, conn);
193 handle->forEachFeatureParallel(func);
198 typedef CallbackRecord<ForEachFunction> Record;
199 typedef typename Record::Ptr RecordPtr;
206 detacher = handle->forEachFeatureAsync(func);
212 RecordPtr newHead(Record::Make(func,
myHead, detacher));
213 const_cast<RecordPtr&
>(
myHead) = newHead;
214 return typename Record::Detacher(newHead);
227 const boost::optional<DtFeatureGeometry>& geometry,
232 return this->Wrap(handle->filter(query, geometry, load));
236 DtTHROW_NEW(
DtException,
"filtered empty feature set wrapper");
241 return FS::filter(query, load);
246 return FS::filter(geometry, load);
250 template <
typename Function>
252 #ifdef DtObjectDebugger_Enable
257 typedef boost::shared_ptr<CallbackRecord>
Ptr;
258 typedef boost::weak_ptr<CallbackRecord>
WPtr;
261 #ifdef DtObjectDebugger_Enable
267 boost::shared_ptr<CallbackRecord> callback(
callbackWptr.lock());
272 explicit Detacher(
const boost::shared_ptr<CallbackRecord>& rec)
283 Mutex::scoped_lock lock(newRec->next->mutex);
284 if (newRec->next->func)
287 newRec->next = newRec->next->next;
297 Mutex::scoped_lock lock(
mutex);
329 ne->addCallbacksTo(fs);
347 Mutex::scoped_lock lock(
mutex);
366 lock.acquire(pr->mutex);
371 pr = pr->prev.lock();
376 Mutex::scoped_lock endLock(ne->mutex);
402 const Function&
func,
426 myHead->addCallbacksTo(fs);
443 typedef boost::signals2::signal_type<
445 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
LoadedSignal;
448 #ifdef DtObjectDebugger_Enable
452 boost::weak_ptr<LoadedSignal>
sig;
458 boost::shared_ptr<LoadedSignal> signal(
sig.lock());
472 template <
typename>
class PtrTemplate,
476 template <
typename FS,
typename Inner>
490 template <
typename OtherFS>
492 : mySet(fs.release())
498 const Inner*
getPtr()
const {
return mySet.get(); }
502 return mySet->label();
507 return mySet->numberOfFeatures();
512 return mySet->elided();
517 return mySet->empty();
522 return mySet->isIndexed();
525 bool isCacheable(
const boost::optional<DtFeatureGeometry>& area)
const
527 return mySet->isCacheable(area);
530 void cacheEstimate(
double& time,
double&
size,
const boost::optional<DtFeatureGeometry>& area)
const
532 mySet->cacheEstimate(time, size, area);
536 const boost::optional<DtFeatureGeometry>& area,
539 mySet->cacheData(area, progress);
544 return mySet->loaded(timeout);
549 return mySet->addLoadedCallback(cb);
554 mySet->forEachFeatureParallel(func);
559 return mySet->forEachFeatureAsync(func);
564 const boost::optional<DtFeatureGeometry>& geometry,
567 return this->Wrap(mySet->filter(query, geometry, load));
572 return this->Wrap(mySet->clone());
576 const boost::scoped_ptr<Inner>
mySet;
579 template <
typename FS,
typename Inner>
582 DtFeatureSetWrapper<FS,boost::shared_ptr,Inner>,
594 setPtr(boost::shared_ptr<Inner>(fs));
597 template <
typename OtherFS>
601 setPtr(boost::shared_ptr<Inner>(fs.release()));
604 template <
typename OtherFS>
613 Mutex::scoped_lock lock(myMutex,
false);
617 boost::shared_ptr<const Inner>
getPtr()
const
619 Mutex::scoped_lock lock(myMutex,
false);
623 boost::shared_ptr<Inner>
setPtr(
const boost::shared_ptr<Inner>& p)
625 Mutex::scoped_lock lock(myMutex,
false);
629 if (!lock.upgrade_to_writer() && mySet && p)
634 lock.downgrade_to_reader();
635 this->setupCallbacks(p);
640 boost::shared_ptr<Inner>
setPtr(Inner* set)
642 boost::shared_ptr<Inner> fs(set);
648 return this->Wrap(getPtr());
658 template <
typename FS,
typename Inner>
661 DtFeatureSetWrapper<FS,boost::weak_ptr,Inner>,
673 template <
typename T>
679 template <
typename T>
688 Mutex::scoped_lock lock(myMutex,
false);
692 boost::shared_ptr<const Inner>
getPtr()
const
694 Mutex::scoped_lock lock(myMutex,
false);
703 boost::shared_ptr<Inner>
setPtr(
const boost::shared_ptr<Inner>& p)
705 Mutex::scoped_lock lock(myMutex,
false);
708 boost::shared_ptr<Inner> s(mySet.lock());
713 if (!lock.upgrade_to_writer() && p)
715 boost::shared_ptr<Inner> s(mySet.lock());
722 lock.downgrade_to_reader();
723 this->setupCallbacks(p);
730 Mutex::scoped_lock lock(myMutex,
false);
731 return this->Wrap(mySet);
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:668
const Inner * getPtr() const
Definition: featureSetWrappers.h:498
boost::shared_ptr< Inner > Ptr
Definition: featureSetWrappers.h:61
FeatureSet::Feature Feature
Definition: featureSetWrappers.h:56
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:587
CallbackRecord::Ptr myHead
Definition: featureSetWrappers.h:465
tbb::spin_mutex CallbackMutex
Definition: featureSetWrappers.h:442
boost::weak_ptr< Inner > mySet
Definition: featureSetWrappers.h:738
const LoadedCallback callback
Definition: featureSetWrappers.h:165
FeatureSet::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:57
Inner * getPtr()
Definition: featureSetWrappers.h:497
bool isCacheable(const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:525
DtFeatureSetWrapper(std::auto_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:491
Definition: featureSet.h:48
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:530
boost::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:611
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:652
FS::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:482
FS::DetachCallback DetachCallback
Definition: featureSetWrappers.h:483
FeatureSet::DetachCallback DetachCallback
Definition: featureSetWrappers.h:58
DtFeatureSetWrapper()
Definition: featureSetWrappers.h:670
voidpf void uLong size
Definition: ioapi.h:39
WPtr prev
Definition: featureSetWrappers.h:413
Wrapper which transforms feature set types.
Definition: featureSetWrappers.h:43
Ptr next
Definition: featureSetWrappers.h:414
FeatureSet * filter(const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:244
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:505
bool elided() const
Definition: featureSetWrappers.h:86
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Mutex mutex
Definition: featureSetWrappers.h:411
Detacher(const boost::shared_ptr< CallbackRecord > &rec)
Definition: featureSetWrappers.h:272
Default on in debug, off in release.
Definition: objectCounter.h:31
boost::shared_ptr< LoadedSignal > myLoadedSignal
Definition: featureSetWrappers.h:466
Definition: featureSet.h:60
DtFeatureSetWrapper(std::auto_ptr< OtherFS > fs)
Definition: featureSetWrappers.h:598
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:166
boost::shared_ptr< const Inner > CPtr
Definition: featureSetWrappers.h:62
FS * clone() const
Definition: featureSetWrappers.h:728
boost::shared_ptr< Inner > setPtr(const boost::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:703
void operator()() const
Definition: featureSetWrappers.h:265
boost::shared_ptr< Inner > setPtr(Inner *set)
Definition: featureSetWrappers.h:640
unsigned numberOfFeatures() const
Definition: featureSetWrappers.h:77
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:547
std::string label() const
Definition: featureSetWrappers.h:500
DtFeatureSetWrapperTemplate()
Definition: featureSetWrappers.h:49
const boost::scoped_ptr< Inner > mySet
Definition: featureSetWrappers.h:576
virtual bool loadedThrowIfNotSet(double timeout=0.0) const
Definition: featureSetWrappers.h:151
boost::weak_ptr< CallbackRecord > callbackWptr
Definition: featureSetWrappers.h:275
Represents a set of characeters a DtFeature object can have. DtQuery objects are the way to communica...
Definition: query.h:38
static Ptr Make(const Function &func, const Ptr &curHead, const DetachCallback &detach)
Definition: featureSetWrappers.h:278
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
boost::weak_ptr< CallbackRecord > WPtr
Definition: featureSetWrappers.h:258
boost::shared_ptr< Inner > getPtr()
Definition: featureSetWrappers.h:686
bool elided() const
Definition: featureSetWrappers.h:510
FeatureSet::LoadedCallback LoadedCallback
Definition: featureSetWrappers.h:59
boost::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:617
Function func
Definition: featureSetWrappers.h:412
Definition: featureSetWrappers.h:30
tbb::spin_mutex Mutex
Definition: featureSetWrappers.h:398
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:591
FS * clone() const
Definition: featureSetWrappers.h:646
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:142
Mutex myMutex
Definition: featureSetWrappers.h:653
~CallbackRecord()
Definition: featureSetWrappers.h:392
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:667
Definition: featureSetWrappers.h:27
Definition: featureSetWrappers.h:160
boost::shared_ptr< Inner > setPtr(const boost::shared_ptr< Inner > &p)
Definition: featureSetWrappers.h:623
DtFeatureSetWrapper(const boost::weak_ptr< T > &fs)
Definition: featureSetWrappers.h:674
CallbackMutex myCallbackMutex
Definition: featureSetWrappers.h:464
DetachCallback addLoadedCallback(const LoadedCallback &cb) const
Definition: featureSetWrappers.h:170
Mutex myMutex
Definition: featureSetWrappers.h:736
DtFeatureSetWrapper(const boost::shared_ptr< T > &fs)
Definition: featureSetWrappers.h:680
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:295
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:196
DetachCallback forEachFeatureAsync(const ForEachFunction &func) const
Definition: featureSetWrappers.h:557
boost::shared_ptr< const Inner > getPtr() const
Definition: featureSetWrappers.h:692
FS::ForEachFunction ForEachFunction
Definition: featureSetWrappers.h:481
DtLoadType
Used to indicate whether to load features. See DtFeatureSetTemplate::filter.
Definition: featureSet.h:36
const Derived * This() const
Definition: featureSetWrappers.h:47
DetachCallback detacher
Definition: featureSetWrappers.h:415
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type LoadedSignal
Definition: featureSetWrappers.h:445
bool isIndexed() const
Definition: featureSetWrappers.h:520
Definition: featureSetWrappers.h:260
Derived * This()
Definition: featureSetWrappers.h:46
DtFeatureSetWrapper(const boost::shared_ptr< OtherFS > &fs)
Definition: featureSetWrappers.h:605
DtFeatureSetWrapper(Inner *fs)
Definition: featureSetWrappers.h:485
void operator()() const
Definition: featureSetWrappers.h:456
void cacheData(const boost::optional< DtFeatureGeometry > &area, DtFeatureCacheProgressCallback *progress) const
Definition: featureSetWrappers.h:535
FS::Feature Feature
Definition: featureSetWrappers.h:666
Definition: featureSetWrappers.h:33
void setupCallbacks(const CPtr &fs)
Definition: featureSetWrappers.h:419
FS FeatureSet
Definition: featureSetWrappers.h:55
Definition: featureSet.h:62
FS::Feature Feature
Definition: featureSetWrappers.h:480
boost::weak_ptr< LoadedSignal > sig
Definition: featureSetWrappers.h:452
FeatureSet::DetachScopeGuard myLoadedSignalDetacher
Definition: featureSetWrappers.h:467
FS * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:562
LoadedCaller(const boost::shared_ptr< LoadedSignal > &sig)
Definition: featureSetWrappers.h:453
bool empty() const
Definition: featureSetWrappers.h:515
void operator()() const
Definition: featureSetWrappers.h:167
FS * clone() const
Definition: featureSetWrappers.h:570
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:189
FeatureSet * filter(const DtQuery &query, DtLoadType load) const
Definition: featureSetWrappers.h:239
void cacheEstimate(double &time, double &size, const boost::optional< DtFeatureGeometry > &area) const
Definition: featureSetWrappers.h:122
void detach()
Definition: featureSetWrappers.h:345
FeatureSet * filter(const DtQuery &query, const boost::optional< DtFeatureGeometry > &geometry, DtLoadType load) const
Definition: featureSetWrappers.h:225
bool loaded(double timeout=0.0) const
Definition: featureSetWrappers.h:542
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:401
bool isIndexed() const
Definition: featureSetWrappers.h:104
Definition: featureSetWrappers.h:447
void forEachFeatureParallel(const ForEachFunction &func) const
Definition: featureSetWrappers.h:552
tbb::spin_rw_mutex Mutex
Definition: featureSetWrappers.h:735
boost::shared_ptr< CallbackRecord > Ptr
Definition: featureSetWrappers.h:257
boost::shared_ptr< Inner > getMutablePtr() const
Definition: featureSetWrappers.h:698
boost::shared_ptr< Inner > mySet
Definition: featureSetWrappers.h:655