VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
simpleFeature.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <features/feature.h>
8 
9 #include <tbb/spin_mutex.h>
10 #include <tbb/spin_rw_mutex.h>
11 
12 #include <boost/signals2.hpp>
13 #include <boost/foreach.hpp>
14 
15 namespace MAKVRinTerra
16 {
23  : public DtFeature
24  , public DtObjectDebugger<DtSimpleFeature>
25  {
26  public:
27  typedef boost::shared_ptr<DtSimpleFeature> Ptr;
28  typedef boost::shared_ptr<const DtSimpleFeature> CPtr;
29 
31  {
32  }
33 
34  explicit DtSimpleFeature(const DtFeatureGeometry& geom) : myGeometry(geom)
35  {
36  }
37 
38  template <DtFeatureGeometry::Type T>
39  explicit DtSimpleFeature(const typename DtFeatureGeometry::Handle<T>& h)
40  : myGeometry(h)
41  {
42  }
43 
44  explicit DtSimpleFeature(const DtFeature & f) : myGeometry(f.geometry())
45  {
47  }
48 
49  void addAttribute(const Key & k, Attribute attr)
50  {
51  AttributeVector & vec = myAttributeVectorMap[k.name];
52  if (vec.size() <= k.index)
53  vec.resize(k.index + 1);
54  vec[k.index] = attr;
55  }
56 
58  {
59  return myGeometry;
60  }
61 
62  unsigned numberOfAttributes(const Key::String & name) const
63  {
64  AttributeVectorMap::const_iterator set = myAttributeVectorMap.find(name);
65  if (set != myAttributeVectorMap.end())
66  return set->second.size();
67 
68  return 0;
69  }
70 
71  boost::optional<Attribute> attribute(const Key & k) const
72  {
73  AttributeVectorMap::const_iterator set = myAttributeVectorMap.find(k.name);
74  if (set != myAttributeVectorMap.end())
75  if (k.index < set->second.size())
76  return set->second[k.index];
77 
78  return boost::optional<Attribute>();
79  }
80 
82  {
83  typedef AttributeVectorMap::const_iterator MapIterator;
84 
85  for (MapIterator set=myAttributeVectorMap.begin(); set != myAttributeVectorMap.end(); ++set)
86  for (unsigned setIndex=0; setIndex < set->second.size(); ++setIndex)
87  f(Key(set->first, setIndex), set->second[setIndex]);
88  }
89 
91  {
92  return DetachCallback();
93  }
94 
95  bool isDeleted() const
96  {
97  return false;
98  }
99 
100  private:
101  typedef std::vector<Attribute> AttributeVector;
102  typedef std::map<DtFeature::Key::String, AttributeVector> AttributeVectorMap;
103 
106  };
107 
108  template <typename F = DtFeature>
110  : public F
111  , public DtObjectDebugger< DtDeletableFeature<F> >
112  {
113  public:
114  typedef typename F::DetachCallback DetachCallback;
115  typedef typename F::DeleteCallback DeleteCallback;
116 
117  explicit DtDeletableFeature(bool deleted = false)
118  : deleted(deleted)
119  {
120  }
121 
122  bool isDeleted() const
123  {
124  Mutex::scoped_lock lock(mutex);
125  return deleted;
126  }
127 
129  {
130  Mutex::scoped_lock lock(mutex);
131  if (deleted)
132  {
133  lock.release();
134  callback();
135  return DetachCallback();
136  }
137 
138  Connection conn(signal.connect(callback, boost::signals2::at_front));
139  return boost::bind(&Connection::disconnect, conn);
140  }
141 
142  void setDeleted()
143  {
144  Mutex::scoped_lock lock(mutex);
145  if (!deleted)
146  {
147  deleted = true;
148  lock.release();
149 
150  signal();
151  signal.disconnect_all_slots();
152  }
153  }
154 
155  private:
156  typedef tbb::spin_mutex Mutex;
157 
158  typedef boost::signals2::signal_type<
159  void (),
160  boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type Signal;
161 
162  typedef boost::signals2::connection Connection;
163 
164  mutable Mutex mutex;
165  mutable Signal signal;
166  bool deleted;
167  };
168 }
169 
DetachCallback addDeleteCallback(const DeleteCallback &) const
Add a user supplied callback to the feature to be called when the feature is deleted.
Definition: simpleFeature.h:90
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:36
boost::signals2::connection Connection
Definition: simpleFeature.h:162
DetachCallback addDeleteCallback(const DeleteCallback &callback) const
Definition: simpleFeature.h:128
boost::optional< Attribute > attribute(const Key &k) const
Get attribute at a certain key.
Definition: simpleFeature.h:71
Key used to lookup attributes.
Definition: feature.h:66
std::map< DtFeature::Key::String, AttributeVector > AttributeVectorMap
Definition: simpleFeature.h:102
DtFeatureGeometry geometry() const
Get the geometry associated with this feature.
Definition: simpleFeature.h:57
DtSimpleFeature(const DtFeatureGeometry &geom)
Definition: simpleFeature.h:34
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Default on in debug, off in release.
Definition: objectCounter.h:31
Definition: featureGeometry.h:54
DtDeletableFeature(bool deleted=false)
Definition: simpleFeature.h:117
DtSimpleFeature(const typename DtFeatureGeometry::Handle< T > &h)
Definition: simpleFeature.h:39
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type Signal
Definition: simpleFeature.h:160
Basic implementation of DtFeature interface.
Definition: simpleFeature.h:22
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
DtSimpleFeature()
Definition: simpleFeature.h:30
boost::shared_ptr< const DtSimpleFeature > CPtr
Definition: simpleFeature.h:28
bool isDeleted() const
Check to see if feature has been deleted.
Definition: simpleFeature.h:95
String name
Definition: feature.h:99
unsigned index
Definition: feature.h:100
DtSimpleFeature(const DtFeature &f)
Definition: simpleFeature.h:44
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:149
Mutex mutex
Definition: simpleFeature.h:164
F::DeleteCallback DeleteCallback
Definition: simpleFeature.h:115
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
boost::function< void()> DeleteCallback
User supplied callback called when feature is deleted.
Definition: feature.h:181
void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: simpleFeature.h:81
void setDeleted()
Definition: simpleFeature.h:142
F::DetachCallback DetachCallback
Definition: simpleFeature.h:114
#define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type)
Definition: objectCounter.h:275
AttributeVectorMap myAttributeVectorMap
Definition: simpleFeature.h:104
Definition: simpleFeature.h:109
virtual void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: feature.h:155
Signal signal
Definition: simpleFeature.h:165
unsigned numberOfAttributes(const Key::String &name) const
Definition: simpleFeature.h:62
tbb::spin_mutex Mutex
Definition: simpleFeature.h:156
bool isDeleted() const
Definition: simpleFeature.h:122
Represents a GIS feature.
Definition: feature.h:37
bool deleted
Definition: simpleFeature.h:166
std::vector< Attribute > AttributeVector
Definition: simpleFeature.h:101
boost::shared_ptr< DtSimpleFeature > Ptr
Definition: simpleFeature.h:27
void addAttribute(const Key &k, Attribute attr)
Definition: simpleFeature.h:49
DtFeatureGeometry myGeometry
Definition: simpleFeature.h:105
Represents a feature geometry.
Definition: featureGeometry.h:35
boost::variant< std::string, long long, bool, double > Attribute
boost::variant type for accessing attributes.
Definition: feature.h:46

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)