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 :
private boost::noncopyable
44 typedef boost::shared_ptr<DtFeature>
Ptr;
45 typedef boost::shared_ptr<const DtFeature>
CPtr;
48 typedef boost::variant<
56 static boost::optional<T> ConvertAttribute(
const Attribute& attr)
71 String(
const std::string&);
75 const char* c_str()
const;
78 const std::string& str()
const;
82 bool operator<(
const String&)
const;
88 Key(
const std::string& name,
unsigned index = 0);
89 Key(
const String& name,
unsigned index = 0);
90 Key(
const char* name,
unsigned index = 0);
91 Key(
const Key& key,
unsigned index = 0);
95 bool operator< (
const Key&)
const;
113 static std::string TypeOfAttribute(
const Attribute&);
116 static std::auto_ptr<DtFeature> CreateEmptyFeature();
123 static std::auto_ptr<DtFeature> CreateGeometryFeature(
125 unsigned char red,
unsigned char green,
unsigned char blue);
129 static std::auto_ptr<DtFeature> CreateCopy(
const DtFeature& feature);
156 virtual unsigned numberOfAttributes(
const Key::String &)
const = 0;
159 virtual bool hasAttribute(
const Key & k)
const;
162 virtual boost::optional<Attribute> attribute(
const Key &)
const = 0;
165 template <
typename T>
166 boost::optional<T> attributeAs(
const Key& k)
const
168 if (boost::optional<Attribute> attr = attribute(k))
196 virtual bool isDeleted()
const = 0;
201 template <
typename T>
204 template <
typename From>
205 boost::optional<T> operator()(
const From& from)
const
209 return boost::lexical_cast<T>(from);
211 catch (boost::bad_lexical_cast&)
213 return boost::optional<T>();
219 template <
typename Feature,
typename Inner = Feature>
225 typedef typename Feature::Key
Key;
241 return myFeature.numberOfAttributes(str);
250 const typename Inner::DeleteCallback& callback)
const
252 return myFeature.addDeleteCallback(callback);
291 template <
typename Feature,
typename Inner = Feature>
295 typedef boost::shared_ptr<DtFeatureWrapper>
Ptr;
296 typedef boost::shared_ptr<const DtFeatureWrapper>
CPtr;
300 typedef typename Feature::Key
Key;
313 return myData->feature->geometry();
318 myData->feature->forEachAttribute(func);
323 return myData->feature->numberOfAttributes(str);
328 return myData->feature->attribute(key);
340 const typename Inner::DeleteCallback& callback)
const
345 Mutex::scoped_lock lock(
myData->mutex);
354 DeletedCounter(callback), boost::signals2::at_front);
361 Mutex::scoped_lock lock(
myData->mutex);
373 d->deletedCallback();
381 Mutex::scoped_lock lock(
myData->mutex);
395 :
myData(new Data(typename Inner::
Ptr(feature)))
417 typedef boost::signals2::signal_type<
419 boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type
Signal;
424 struct Data : boost::noncopyable
427 typedef boost::shared_ptr<Data>
SPtr;
428 typedef boost::weak_ptr<Data>
WPtr;
432 Mutex::scoped_lock lock(
mutex);
447 signal.disconnect_all_slots();
451 DtWarn <<
"Exception thrown in delete callback" << std::endl;
456 explicit Data(
const typename Inner::Ptr& f)
488 data->deletedCallback();