14 #include <boost/shared_ptr.hpp>
15 #include <boost/function.hpp>
16 #include <boost/variant.hpp>
17 #include <boost/lexical_cast.hpp>
18 #include <boost/signals2.hpp>
20 #include <tbb/spin_mutex.h>
24 #include <vlutil/vlPrint.h>
26 namespace MAKVRinTerra
38 #ifdef DtObjectDebugger_Enable
45 typedef boost::shared_ptr<DtFeature>
Ptr;
46 typedef boost::shared_ptr<const DtFeature>
CPtr;
51 typedef boost::variant<
75 String(
const std::string&);
79 const char* c_str()
const;
82 const std::string& str()
const;
86 bool operator<(
const String&)
const;
92 Key(
const std::string& name,
unsigned index = 0);
93 Key(
const String& name,
unsigned index = 0);
94 Key(
const char* name,
unsigned index = 0);
95 Key(
const Key& key,
unsigned index = 0);
99 bool operator< (
const Key&)
const;
117 static std::string TypeOfAttribute(
const Attribute&);
120 static std::auto_ptr<DtFeature> CreateEmptyFeature();
127 static std::auto_ptr<DtFeature> CreateGeometryFeature(
129 unsigned char red,
unsigned char green,
unsigned char blue);
133 static std::auto_ptr<DtFeature> CreateCopy(
const DtFeature& feature);
154 typedef boost::function<void (const Key&, const Attribute&)> ForEachFunction;
163 virtual bool hasAttribute(
const Key & k)
const;
166 virtual boost::optional<Attribute>
attribute(
const Key &)
const {
return boost::none;};
169 template <
typename T>
172 if (boost::optional<Attribute> attr = attribute(k))
205 DtFeature(
const DtFeature&) {
throw std::runtime_error(
"DtFeature copy ctor, should not hit! At " __FILE__
":" + __LINE__); };
210 template <
typename T>
213 template <
typename From>
218 return boost::lexical_cast<T>(from);
220 catch (boost::bad_lexical_cast&)
222 return boost::optional<T>();
228 template <
typename Feature,
typename Inner = Feature>
234 typedef typename Feature::Key
Key;
250 return myFeature.numberOfAttributes(str);
259 const typename Inner::DeleteCallback& callback)
const
261 return myFeature.addDeleteCallback(callback);
300 template <
typename Feature,
typename Inner = Feature>
304 typedef boost::shared_ptr<DtFeatureWrapper>
Ptr;
305 typedef boost::shared_ptr<const DtFeatureWrapper>
CPtr;
309 typedef typename Feature::Key
Key;
322 return myData->feature->geometry();
327 myData->feature->forEachAttribute(func);
332 return myData->feature->numberOfAttributes(str);
337 return myData->feature->attribute(key);
341 #ifdef DtObjectDebugger_Enable
351 const typename Inner::DeleteCallback& callback)
const
356 Mutex::scoped_lock lock(
myData->mutex);
365 DeletedCounter(callback), boost::signals2::at_front);
372 Mutex::scoped_lock lock(
myData->mutex);
384 d->deletedCallback();
392 Mutex::scoped_lock lock(
myData->mutex);
406 :
myData(new Data(typename Inner::
Ptr(feature)))
428 typedef boost::signals2::signal_type<
430 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
Signal;
435 struct Data : boost::noncopyable
438 typedef boost::shared_ptr<Data>
SPtr;
439 typedef boost::weak_ptr<Data>
WPtr;
443 Mutex::scoped_lock lock(
mutex);
458 signal.disconnect_all_slots();
462 DtWarn <<
"Exception thrown in delete callback" << std::endl;
467 explicit Data(
const typename Inner::Ptr& f)
499 data->deletedCallback();
Feature::Attribute Attribute
Definition: feature.h:308
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
void operator()() const
Definition: feature.h:495
boost variant visitor for converting attributes with lexical_cast lexical_cast will not do anything f...
Definition: feature.h:211
Data(const typename Inner::Ptr &f)
Definition: feature.h:467
DtFeatureGeometry geometry() const
Definition: feature.h:320
Key used to lookup attributes. The DtFeature interface is a dictionary that maps Key objects to attri...
Definition: feature.h:68
boost::shared_ptr< DtFeature > Ptr
Definition: feature.h:45
Inner::DetachCallback DetachCallback
Definition: feature.h:311
bool deleted
Definition: feature.h:507
Inner::DetachCallback DetachCallback
Definition: feature.h:236
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:243
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type Signal
Definition: feature.h:430
Wraps a feature object and makes sure all the callbacks are unhooked correctly In order to wrap a fea...
Definition: feature.h:301
bool isDeleted() const
Definition: feature.h:264
std::string myString
Definition: feature.h:89
DtFeatureWrapper * clone() const
Definition: feature.h:376
Feature::Attribute Attribute
Definition: feature.h:233
boost::shared_ptr< const DtFeature > CPtr
Definition: feature.h:46
const Inner & myFeature
Definition: feature.h:290
boost::shared_ptr< Data > SPtr
Definition: feature.h:438
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
Definition: feature.h:340
Feature::Key Key
Definition: feature.h:309
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
DtFeatureRefWrapper(const Inner &feature)
Definition: feature.h:280
void setDeleted()
Definition: feature.h:381
Feature::ForEachFunction ForEachFunction
Definition: feature.h:232
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:350
Inner & wrappedFeature()
Definition: feature.h:419
boost::optional< T > operator()(const From &from) const
Definition: feature.h:214
DtFeatureWrapper(const Inner &feature)
Definition: feature.h:412
Mutex mutex
Definition: feature.h:503
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:330
boost::signals2::connection Connection
Definition: feature.h:432
boost::function< void()> DetachCallback
Callback used to detach the user from a feature so the users callback is not called anymore...
Definition: feature.h:180
DeletedCounter(const typename Inner::DeleteCallback &cb)
Definition: feature.h:346
bool init(const SPtr &This)
Definition: feature.h:479
DtFeature()
Definition: feature.h:48
virtual bool isDeleted() const
Check to see if feature has been deleted. Note: this is not related to C++ delete or destructors...
Definition: feature.h:200
~DtFeatureWrapper()
Definition: feature.h:313
static boost::optional< T > ConvertAttribute(const Attribute &attr)
Convert an attribute to a type using iostream.
Definition: feature.h:60
String name
Definition: feature.h:101
bool isDeleted() const
Definition: feature.h:370
Feature::ForEachFunction ForEachFunction
Definition: feature.h:307
Connection myConnection
Definition: feature.h:515
unsigned index
Definition: feature.h:102
static const char * TypeName
Definition: feature.h:43
DtFeatureGeometry geometry() const
Definition: feature.h:238
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:248
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:151
DtFeatureWrapper(const typename Inner::Ptr &f)
Definition: feature.h:397
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
const Inner & wrappedFeature() const
Definition: feature.h:420
boost::function< void()> DeleteCallback
User supplied callback called when feature is deleted.
Definition: feature.h:183
Signal signal
Definition: feature.h:506
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:335
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:258
Feature * clone() const
Definition: feature.h:269
Signal mySignal
Definition: feature.h:514
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
~Data()
Definition: feature.h:473
virtual void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: feature.h:157
boost::optional< T > attributeAs(const Key &k) const
Return attribute as a specific type using build in conversion methods.
Definition: feature.h:170
virtual DetachCallback addDeleteCallback(const DeleteCallback &callback) const
Add a user supplied callback to the feature to be called when the feature is deleted. If the feature is already deleted the callback may or may not be called by the implementation of this function. The callback is guaranteed to only be called once.
Definition: feature.h:193
DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(MAKVRinTerra::DtFeatureWrapper)
boost signal for attaching to delete signal
Definition: feature.h:435
DtFeatureWrapper(const DtFeatureWrapper &from)
Copy constructor.
Definition: feature.h:388
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:325
Caller(const SPtr &data)
Definition: feature.h:493
Functor for calling delete signal.
Definition: feature.h:490
const Inner::DeleteCallback callback
Definition: feature.h:345
virtual DtFeatureGeometry geometry() const
Get the geometry associated with this feature. GIS features each typically each associated with one g...
Definition: feature.h:151
boost::shared_ptr< Data > myData
all the users of this object will attach their callbacks through this signal it will be called by the...
Definition: feature.h:513
boost::weak_ptr< Data > WPtr
Definition: feature.h:439
Case insensitive string.
Definition: feature.h:71
void operator()() const
Definition: feature.h:347
virtual unsigned numberOfAttributes(const Key::String &) const
Number of attributes with a given key.
Definition: feature.h:160
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
boost::shared_ptr< const DtFeatureWrapper > CPtr
Definition: feature.h:305
boost::shared_ptr< DtFeatureWrapper > Ptr
Definition: feature.h:304
tbb::spin_mutex Mutex
typename Inner::Ptr& wrappedFeaturePtr() { return myData->feature; } const typename Inner::Ptr& wrapp...
Definition: feature.h:426
Represents a GIS feature. Features consist of a DtFeatureGeometry (2.5D geometric vector data) and a ...
Definition: feature.h:37
DetachCallback detacher
Definition: feature.h:505
Definition: feature.h:229
DtFeatureWrapper(Inner *feature)
Create from instance of wrapped type.
Definition: feature.h:405
Feature::Key Key
Definition: feature.h:234
Inner::Ptr feature
Definition: feature.h:504
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:253
Represents a feature geometry.
Definition: featureGeometry.h:39
virtual boost::optional< Attribute > attribute(const Key &) const
Get attribute at a certain key.
Definition: feature.h:166
DtFeatureRefWrapper(const DtFeatureRefWrapper &from)
Copy constructor.
Definition: feature.h:275
boost::variant< std::string, long long, bool, double > Attribute
boost::variant type for accessing attributes.
Definition: feature.h:48
void deletedCallback()
Definition: feature.h:441
WPtr datawptr
Definition: feature.h:492
DtFeature(const DtFeature &)
Definition: feature.h:205