14 #include <boost/function.hpp>
15 #include <boost/variant.hpp>
16 #include <boost/lexical_cast.hpp>
17 #include <boost/signals2.hpp>
19 #include <tbb/spin_mutex.h>
23 #include <vlutil/vlPrint.h>
25 namespace MAKVRinTerra
37 #ifdef DtObjectDebugger_Enable
44 typedef std::shared_ptr<DtFeature>
Ptr;
45 typedef std::shared_ptr<const DtFeature>
CPtr;
50 typedef boost::variant<
74 String(
const std::string&);
78 const char* c_str()
const;
81 const std::string& str()
const;
85 bool operator<(
const String&)
const;
91 Key(
const std::string& name,
unsigned index = 0);
92 Key(
const String& name,
unsigned index = 0);
93 Key(
const char* name,
unsigned index = 0);
94 Key(
const Key& key,
unsigned index = 0);
98 bool operator< (
const Key&)
const;
116 static std::string TypeOfAttribute(
const Attribute&);
119 static std::unique_ptr<DtFeature> CreateEmptyFeature();
122 static std::unique_ptr<DtFeature> CreateGeometryFeature(
const DtFeatureGeometry&);
126 static std::unique_ptr<DtFeature> CreateGeometryFeature(
128 unsigned char red,
unsigned char green,
unsigned char blue);
132 static std::unique_ptr<DtFeature> CreateCopy(
const DtFeature& feature);
153 typedef boost::function<void (const Key&, const Attribute&)> ForEachFunction;
162 virtual bool hasAttribute(
const Key & k)
const;
165 virtual boost::optional<Attribute>
attribute(
const Key &)
const {
return boost::none;};
168 template <
typename T>
171 if (boost::optional<Attribute> attr = attribute(k))
204 DtFeature(
const DtFeature&) {
throw std::runtime_error(
"DtFeature copy ctor, should not hit! At " __FILE__
":" + __LINE__); };
209 template <
typename T>
212 template <
typename From>
217 return boost::lexical_cast<T>(from);
219 catch (boost::bad_lexical_cast&)
221 return boost::optional<T>();
227 template <
typename Feature,
typename Inner = Feature>
233 typedef typename Feature::Key
Key;
249 return myFeature.numberOfAttributes(str);
258 const typename Inner::DeleteCallback& callback)
const
260 return myFeature.addDeleteCallback(callback);
299 template <
typename Feature,
typename Inner = Feature>
303 typedef std::shared_ptr<DtFeatureWrapper>
Ptr;
304 typedef std::shared_ptr<const DtFeatureWrapper>
CPtr;
308 typedef typename Feature::Key
Key;
321 return myData->feature->geometry();
326 myData->feature->forEachAttribute(func);
331 return myData->feature->numberOfAttributes(str);
336 return myData->feature->attribute(key);
340 #ifdef DtObjectDebugger_Enable
350 const typename Inner::DeleteCallback& callback)
const
355 Mutex::scoped_lock lock(
myData->mutex);
364 DeletedCounter(callback), boost::signals2::at_front);
366 return boost::bind(&Connection::disconnect, conn);
371 Mutex::scoped_lock lock(
myData->mutex);
383 d->deletedCallback();
391 Mutex::scoped_lock lock(
myData->mutex);
405 :
myData(new Data(typename Inner::
Ptr(feature)))
427 typedef boost::signals2::signal_type<
429 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
Signal;
434 struct Data : boost::noncopyable
437 typedef std::shared_ptr<Data>
SPtr;
438 typedef std::weak_ptr<Data>
WPtr;
442 Mutex::scoped_lock lock(
mutex);
457 signal.disconnect_all_slots();
461 DtWarn <<
"Exception thrown in delete callback" << std::endl;
466 explicit Data(
const typename Inner::Ptr& f)
498 data->deletedCallback();
Feature::Attribute Attribute
Definition: feature.h:307
#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:494
boost variant visitor for converting attributes with lexical_cast lexical_cast will not do anything f...
Definition: feature.h:210
Data(const typename Inner::Ptr &f)
Definition: feature.h:466
DtFeatureGeometry geometry() const
Definition: feature.h:319
Key used to lookup attributes. The DtFeature interface is a dictionary that maps Key objects to attri...
Definition: feature.h:67
Inner::DetachCallback DetachCallback
Definition: feature.h:310
bool deleted
Definition: feature.h:506
Inner::DetachCallback DetachCallback
Definition: feature.h:235
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:242
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type Signal
Definition: feature.h:429
Wraps a feature object and makes sure all the callbacks are unhooked correctly In order to wrap a fea...
Definition: feature.h:300
bool isDeleted() const
Definition: feature.h:263
std::string myString
Definition: feature.h:88
DtFeatureWrapper * clone() const
Definition: feature.h:375
Feature::Attribute Attribute
Definition: feature.h:232
const Inner & myFeature
Definition: feature.h:289
std::shared_ptr< const DtFeatureWrapper > CPtr
Definition: feature.h:304
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:339
Feature::Key Key
Definition: feature.h:308
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
DtFeatureRefWrapper(const Inner &feature)
Definition: feature.h:279
void setDeleted()
Definition: feature.h:380
Feature::ForEachFunction ForEachFunction
Definition: feature.h:231
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:349
Inner & wrappedFeature()
Definition: feature.h:418
boost::optional< T > operator()(const From &from) const
Definition: feature.h:213
std::shared_ptr< DtFeature > Ptr
Definition: feature.h:44
DtFeatureWrapper(const Inner &feature)
Definition: feature.h:411
Mutex mutex
Definition: feature.h:502
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:329
boost::signals2::connection Connection
Definition: feature.h:431
boost::function< void()> DetachCallback
Callback used to detach the user from a feature so the users callback is not called anymore...
Definition: feature.h:179
DeletedCounter(const typename Inner::DeleteCallback &cb)
Definition: feature.h:345
bool init(const SPtr &This)
Definition: feature.h:478
std::shared_ptr< Data > SPtr
Definition: feature.h:437
DtFeature()
Definition: feature.h:47
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:199
~DtFeatureWrapper()
Definition: feature.h:312
static boost::optional< T > ConvertAttribute(const Attribute &attr)
Convert an attribute to a type using iostream.
Definition: feature.h:59
String name
Definition: feature.h:100
bool isDeleted() const
Definition: feature.h:369
Feature::ForEachFunction ForEachFunction
Definition: feature.h:306
Connection myConnection
Definition: feature.h:514
unsigned index
Definition: feature.h:101
static const char * TypeName
Definition: feature.h:42
DtFeatureGeometry geometry() const
Definition: feature.h:237
unsigned numberOfAttributes(const typename Key::String &str) const
Definition: feature.h:247
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:150
DtFeatureWrapper(const typename Inner::Ptr &f)
Definition: feature.h:396
const Inner & wrappedFeature() const
Definition: feature.h:419
boost::function< void()> DeleteCallback
User supplied callback called when feature is deleted.
Definition: feature.h:182
Signal signal
Definition: feature.h:505
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:334
DetachCallback addDeleteCallback(const typename Inner::DeleteCallback &callback) const
Definition: feature.h:257
Feature * clone() const
Definition: feature.h:268
Signal mySignal
Definition: feature.h:513
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
~Data()
Definition: feature.h:472
virtual void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: feature.h:156
boost::optional< T > attributeAs(const Key &k) const
Return attribute as a specific type using build in conversion methods.
Definition: feature.h:169
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:192
DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(MAKVRinTerra::DtFeatureWrapper)
std::shared_ptr< const DtFeature > CPtr
Definition: feature.h:45
boost signal for attaching to delete signal
Definition: feature.h:434
DtFeatureWrapper(const DtFeatureWrapper &from)
Copy constructor.
Definition: feature.h:387
void forEachAttribute(ForEachFunction func) const
Definition: feature.h:324
Caller(const SPtr &data)
Definition: feature.h:492
Functor for calling delete signal.
Definition: feature.h:489
const Inner::DeleteCallback callback
Definition: feature.h:344
virtual DtFeatureGeometry geometry() const
Get the geometry associated with this feature. GIS features each typically each associated with one g...
Definition: feature.h:150
Case insensitive string.
Definition: feature.h:70
void operator()() const
Definition: feature.h:346
virtual unsigned numberOfAttributes(const Key::String &) const
Number of attributes with a given key.
Definition: feature.h:159
std::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:512
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
std::weak_ptr< Data > WPtr
Definition: feature.h:438
tbb::spin_mutex Mutex
typename Inner::Ptr& wrappedFeaturePtr() { return myData->feature; } const typename Inner::Ptr& wrapp...
Definition: feature.h:425
Represents a GIS feature. Features consist of a DtFeatureGeometry (2.5D geometric vector data) and a ...
Definition: feature.h:36
DetachCallback detacher
Definition: feature.h:504
Definition: feature.h:228
DtFeatureWrapper(Inner *feature)
Create from instance of wrapped type.
Definition: feature.h:404
Feature::Key Key
Definition: feature.h:233
std::shared_ptr< DtFeatureWrapper > Ptr
Definition: feature.h:303
Inner::Ptr feature
Definition: feature.h:503
boost::optional< Attribute > attribute(const Key &key) const
Definition: feature.h:252
Represents a feature geometry.
Definition: featureGeometry.h:40
virtual boost::optional< Attribute > attribute(const Key &) const
Get attribute at a certain key.
Definition: feature.h:165
DtFeatureRefWrapper(const DtFeatureRefWrapper &from)
Copy constructor.
Definition: feature.h:274
boost::variant< std::string, long long, bool, double > Attribute
boost::variant type for accessing attributes.
Definition: feature.h:47
void deletedCallback()
Definition: feature.h:440
WPtr datawptr
Definition: feature.h:491
DtFeature(const DtFeature &)
Definition: feature.h:204