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
43 typedef boost::shared_ptr<DtFeature>
Ptr;
44 typedef boost::shared_ptr<const DtFeature>
CPtr;
49 typedef boost::variant<
73 String(
const std::string&);
77 const char* c_str()
const;
80 const std::string& str()
const;
84 bool operator<(
const String&)
const;
90 Key(
const std::string& name,
unsigned index = 0);
91 Key(
const String& name,
unsigned index = 0);
92 Key(
const char* name,
unsigned index = 0);
93 Key(
const Key& key,
unsigned index = 0);
97 bool operator< (
const Key&)
const;
115 static std::string TypeOfAttribute(
const Attribute&);
118 static std::auto_ptr<DtFeature> CreateEmptyFeature();
125 static std::auto_ptr<DtFeature> CreateGeometryFeature(
127 unsigned char red,
unsigned char green,
unsigned char blue);
131 static std::auto_ptr<DtFeature> CreateCopy(
const DtFeature& feature);
152 typedef boost::function<void (const Key&, const Attribute&)> ForEachFunction;
161 virtual bool hasAttribute(
const Key & k)
const;
164 virtual boost::optional<Attribute>
attribute(
const Key &)
const {
return boost::none;};
167 template <
typename T>
170 if (boost::optional<Attribute> attr = attribute(k))
203 DtFeature(
const DtFeature&) {
throw std::runtime_error(
"DtFeature copy ctor, should not hit! At " __FILE__
":" + __LINE__); };
208 template <
typename T>
211 template <
typename From>
216 return boost::lexical_cast<T>(from);
218 catch (boost::bad_lexical_cast&)
220 return boost::optional<T>();
226 template <
typename Feature,
typename Inner = Feature>
232 typedef typename Feature::Key
Key;
248 return myFeature.numberOfAttributes(str);
257 const typename Inner::DeleteCallback& callback)
const
259 return myFeature.addDeleteCallback(callback);
298 template <
typename Feature,
typename Inner = Feature>
302 typedef boost::shared_ptr<DtFeatureWrapper>
Ptr;
303 typedef boost::shared_ptr<const DtFeatureWrapper>
CPtr;
307 typedef typename Feature::Key
Key;
320 return myData->feature->geometry();
325 myData->feature->forEachAttribute(func);
330 return myData->feature->numberOfAttributes(str);
335 return myData->feature->attribute(key);
347 const typename Inner::DeleteCallback& callback)
const
352 Mutex::scoped_lock lock(
myData->mutex);
361 DeletedCounter(callback), boost::signals2::at_front);
368 Mutex::scoped_lock lock(
myData->mutex);
380 d->deletedCallback();
388 Mutex::scoped_lock lock(
myData->mutex);
402 :
myData(new Data(typename Inner::
Ptr(feature)))
424 typedef boost::signals2::signal_type<
426 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
Signal;
431 struct Data : boost::noncopyable
434 typedef boost::shared_ptr<Data>
SPtr;
435 typedef boost::weak_ptr<Data>
WPtr;
439 Mutex::scoped_lock lock(
mutex);
454 signal.disconnect_all_slots();
458 DtWarn <<
"Exception thrown in delete callback" << std::endl;
463 explicit Data(
const typename Inner::Ptr& f)
495 data->deletedCallback();
Feature::Attribute Attribute
Definition: feature.h:306
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:36
void operator()() const
Definition: feature.h:491
boost variant visitor for converting attributes with lexical_cast lexical_cast will not do anything f...
Definition: feature.h:209
Data(const typename Inner::Ptr &f)
Definition: feature.h:463
DtFeatureGeometry geometry() const
Definition: feature.h:318
Key used to lookup attributes.
Definition: feature.h:66
boost::shared_ptr< DtFeature > Ptr
Definition: feature.h:43
Inner::DetachCallback DetachCallback
Definition: feature.h:309
bool deleted
Definition: feature.h:503
Inner::DetachCallback DetachCallback
Definition: feature.h:234
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:241
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type Signal
Definition: feature.h:426
Wraps a feature object and makes sure all the callbacks are unhooked correctly In order to wrap a fea...
Definition: feature.h:299
bool isDeleted() const
Definition: feature.h:262
std::string myString
Definition: feature.h:87
DtFeatureWrapper * clone() const
Definition: feature.h:372
Feature::Attribute Attribute
Definition: feature.h:231
boost::shared_ptr< const DtFeature > CPtr
Definition: feature.h:44
const Inner & myFeature
Definition: feature.h:288
boost::shared_ptr< Data > SPtr
Definition: feature.h:434
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Default on in debug, off in release.
Definition: objectCounter.h:31
Definition: feature.h:338
Feature::Key Key
Definition: feature.h:307
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
DtFeatureRefWrapper(const Inner &feature)
Definition: feature.h:278
void setDeleted()
Definition: feature.h:377
Feature::ForEachFunction ForEachFunction
Definition: feature.h:230
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:346
Inner & wrappedFeature()
Definition: feature.h:415
boost::optional< T > operator()(const From &from) const
Definition: feature.h:212
DtFeatureWrapper(const Inner &feature)
Definition: feature.h:408
Mutex mutex
Definition: feature.h:499
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:328
boost::signals2::connection Connection
Definition: feature.h:428
boost::function< void()> DetachCallback
Callback used to detach the user from a feature so the users callback is not called anymore...
Definition: feature.h:178
DeletedCounter(const typename Inner::DeleteCallback &cb)
Definition: feature.h:342
bool init(const SPtr &This)
Definition: feature.h:475
DtFeature()
Definition: feature.h:46
virtual bool isDeleted() const
Check to see if feature has been deleted.
Definition: feature.h:198
~DtFeatureWrapper()
Definition: feature.h:311
static boost::optional< T > ConvertAttribute(const Attribute &attr)
Convert an attribute to a type using iostream.
Definition: feature.h:58
String name
Definition: feature.h:99
bool isDeleted() const
Definition: feature.h:366
Feature::ForEachFunction ForEachFunction
Definition: feature.h:305
Connection myConnection
Definition: feature.h:511
unsigned index
Definition: feature.h:100
static const char * TypeName
Definition: feature.h:41
DtFeatureGeometry geometry() const
Definition: feature.h:236
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:246
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:149
DtFeatureWrapper(const typename Inner::Ptr &f)
Definition: feature.h:393
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
const Inner & wrappedFeature() const
Definition: feature.h:416
boost::function< void()> DeleteCallback
User supplied callback called when feature is deleted.
Definition: feature.h:181
Signal signal
Definition: feature.h:502
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:333
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:256
Feature * clone() const
Definition: feature.h:267
Signal mySignal
Definition: feature.h:510
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
~Data()
Definition: feature.h:469
virtual void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: feature.h:155
boost::optional< T > attributeAs(const Key &k) const
Return attribute as a specific type using build in conversion methods.
Definition: feature.h:168
virtual DetachCallback addDeleteCallback(const DeleteCallback &callback) const
Add a user supplied callback to the feature to be called when the feature is deleted.
Definition: feature.h:191
DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(MAKVRinTerra::DtFeatureWrapper)
boost signal for attaching to delete signal
Definition: feature.h:431
DtFeatureWrapper(const DtFeatureWrapper &from)
Copy constructor.
Definition: feature.h:384
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:323
Caller(const SPtr &data)
Definition: feature.h:489
Functor for calling delete signal.
Definition: feature.h:486
const Inner::DeleteCallback callback
Definition: feature.h:341
virtual DtFeatureGeometry geometry() const
Get the geometry associated with this feature.
Definition: feature.h:149
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:509
boost::weak_ptr< Data > WPtr
Definition: feature.h:435
Case insensitive string.
Definition: feature.h:69
void operator()() const
Definition: feature.h:343
virtual unsigned numberOfAttributes(const Key::String &) const
Number of attributes with a given key.
Definition: feature.h:158
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
boost::shared_ptr< const DtFeatureWrapper > CPtr
Definition: feature.h:303
boost::shared_ptr< DtFeatureWrapper > Ptr
Definition: feature.h:302
tbb::spin_mutex Mutex
typename Inner::Ptr& wrappedFeaturePtr() { return myData->feature; } const typename Inner::Ptr& wrapp...
Definition: feature.h:422
Represents a GIS feature.
Definition: feature.h:37
DetachCallback detacher
Definition: feature.h:501
Definition: feature.h:227
DtFeatureWrapper(Inner *feature)
Create from instance of wrapped type.
Definition: feature.h:401
Feature::Key Key
Definition: feature.h:232
Inner::Ptr feature
Definition: feature.h:500
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:251
Represents a feature geometry.
Definition: featureGeometry.h:35
virtual boost::optional< Attribute > attribute(const Key &) const
Get attribute at a certain key.
Definition: feature.h:164
DtFeatureRefWrapper(const DtFeatureRefWrapper &from)
Copy constructor.
Definition: feature.h:273
boost::variant< std::string, long long, bool, double > Attribute
boost::variant type for accessing attributes.
Definition: feature.h:46
void deletedCallback()
Definition: feature.h:437
WPtr datawptr
Definition: feature.h:488
DtFeature(const DtFeature &)
Definition: feature.h:203