VR-Forces Developer's Guide
 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 
14 namespace MAKVRinTerra
15 {
22  : public DtFeature
23 #ifdef DtObjectDebugger_Enable
24  , public DtObjectDebugger<DtSimpleFeature>
25 #endif
26  {
27  public:
28  typedef std::shared_ptr<DtSimpleFeature> Ptr;
29  typedef std::shared_ptr<const DtSimpleFeature> CPtr;
30 
32  {
33  }
34 
35  explicit DtSimpleFeature(const DtFeatureGeometry& geom) : myGeometry(geom)
36  {
37  }
38 
39  template <DtFeatureGeometry::Type T>
40  explicit DtSimpleFeature(const typename DtFeatureGeometry::Handle<T>& h)
41  : myGeometry(h)
42  {
43  }
44 
45  explicit DtSimpleFeature(const DtFeature & f) : myGeometry(f.geometry())
46  {
47  f.forEachAttribute(boost::bind(&DtSimpleFeature::addAttribute, this, boost::placeholders::_1, boost::placeholders::_2));
48  }
49 
50  void addAttribute(const Key& k, Attribute attr)
51  {
52  AttributeVector& vec = myAttributeVectorMap[k.name];
53  if (vec.size() <= k.index)
54  {
55  vec.resize(k.index + 1);
56  }
57  vec[k.index] = attr;
58  }
59 
60  virtual DtFeatureGeometry geometry() const override { return myGeometry; }
61 
62  virtual unsigned numberOfAttributes(const Key::String& name) const override
63  {
64  AttributeVectorMap::const_iterator set = myAttributeVectorMap.find(name);
65  if (set != myAttributeVectorMap.end())
66  {
67  return set->second.size();
68  }
69 
70  return 0;
71  }
72 
73  virtual boost::optional<Attribute> attribute(const Key& k) const override
74  {
75  AttributeVectorMap::const_iterator set = myAttributeVectorMap.find(k.name);
76  if (set != myAttributeVectorMap.end())
77  {
78  if (k.index < set->second.size())
79  {
80  return set->second[k.index];
81  }
82  }
83 
84  return boost::optional<Attribute>();
85  }
86 
87  virtual void forEachAttribute(ForEachFunction f) const override
88  {
89  typedef AttributeVectorMap::const_iterator MapIterator;
90 
91  for (MapIterator set = myAttributeVectorMap.begin(); set != myAttributeVectorMap.end(); ++set)
92  {
93  for (unsigned setIndex = 0; setIndex < set->second.size(); ++setIndex)
94  {
95  f(Key(set->first, setIndex), set->second[setIndex]);
96  }
97  }
98  }
99 
100  virtual DetachCallback addDeleteCallback(const DeleteCallback&) const override { return DetachCallback(); }
101 
102  virtual bool isDeleted() const override {
103  return false;
104  }
105 
106  private:
107  typedef std::vector<Attribute> AttributeVector;
108  typedef std::map<DtFeature::Key::String, AttributeVector> AttributeVectorMap;
109 
112  };
113 
114  template <typename F = DtFeature>
116  : public F
117 #ifdef DtObjectDebugger_Enable
118  , public DtObjectDebugger< DtDeletableFeature<F> >
119 #endif
120  {
121  public:
122  typedef typename F::DetachCallback DetachCallback;
123  typedef typename F::DeleteCallback DeleteCallback;
124 
125  explicit DtDeletableFeature(bool deleted = false)
126  : deleted(deleted)
127  {
128  }
129 
130  bool isDeleted() const
131  {
132  Mutex::scoped_lock lock(mutex);
133  return deleted;
134  }
135 
137  {
138  Mutex::scoped_lock lock(mutex);
139  if (deleted)
140  {
141  lock.release();
142  callback();
143  return DetachCallback();
144  }
145 
146  Connection conn(signal.connect(callback, boost::signals2::at_front));
147  return boost::bind(&Connection::disconnect, conn);
148  }
149 
150  void setDeleted()
151  {
152  Mutex::scoped_lock lock(mutex);
153  if (!deleted)
154  {
155  deleted = true;
156  lock.release();
157 
158  signal();
159  signal.disconnect_all_slots();
160  }
161  }
162 
163  private:
164  typedef tbb::spin_mutex Mutex;
165 
166  typedef boost::signals2::signal_type<
167  void (),
168  boost::signals2::keywords::mutex_type<tbb::spin_mutex> >::type Signal;
169 
170  typedef boost::signals2::connection Connection;
171 
172  mutable Mutex mutex;
173  mutable Signal signal;
174  bool deleted;
175  };
176 }
177 
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
boost::signals2::connection Connection
Definition: simpleFeature.h:170
DetachCallback addDeleteCallback(const DeleteCallback &callback) const
Definition: simpleFeature.h:136
Key used to lookup attributes. The DtFeature interface is a dictionary that maps Key objects to attri...
Definition: feature.h:67
virtual bool isDeleted() const override
Check to see if feature has been deleted. Note: this is not related to C++ delete or destructors...
Definition: simpleFeature.h:102
std::shared_ptr< const DtSimpleFeature > CPtr
Definition: simpleFeature.h:29
std::map< DtFeature::Key::String, AttributeVector > AttributeVectorMap
Definition: simpleFeature.h:108
DtSimpleFeature(const DtFeatureGeometry &geom)
Definition: simpleFeature.h:35
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
Definition: featureGeometry.h:61
DtDeletableFeature(bool deleted=false)
Definition: simpleFeature.h:125
DtSimpleFeature(const typename DtFeatureGeometry::Handle< T > &h)
Definition: simpleFeature.h:40
boost::signals2::signal_type< void(), boost::signals2::keywords::mutex_type< tbb::spin_mutex > >::type Signal
Definition: simpleFeature.h:168
Basic implementation of DtFeature interface.
Definition: simpleFeature.h:21
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
DtSimpleFeature()
Definition: simpleFeature.h:31
String name
Definition: feature.h:100
unsigned index
Definition: feature.h:101
DtSimpleFeature(const DtFeature &f)
Definition: simpleFeature.h:45
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:150
virtual DtFeatureGeometry geometry() const override
Get the geometry associated with this feature. GIS features each typically each associated with one g...
Definition: simpleFeature.h:60
Mutex mutex
Definition: simpleFeature.h:172
virtual unsigned numberOfAttributes(const Key::String &name) const override
Definition: simpleFeature.h:62
F::DeleteCallback DeleteCallback
Definition: simpleFeature.h:123
boost::function< void()> DeleteCallback
User supplied callback called when feature is deleted.
Definition: feature.h:182
void setDeleted()
Definition: simpleFeature.h:150
F::DetachCallback DetachCallback
Definition: simpleFeature.h:122
#define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type)
Definition: objectCounter.h:32
AttributeVectorMap myAttributeVectorMap
Definition: simpleFeature.h:110
Definition: simpleFeature.h:115
virtual void forEachAttribute(ForEachFunction f) const
Calls the provided callback on each attribute.
Definition: feature.h:156
Signal signal
Definition: simpleFeature.h:173
virtual DetachCallback addDeleteCallback(const DeleteCallback &) const override
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: simpleFeature.h:100
virtual boost::optional< Attribute > attribute(const Key &k) const override
Get attribute at a certain key.
Definition: simpleFeature.h:73
tbb::spin_mutex Mutex
Definition: simpleFeature.h:164
bool isDeleted() const
Definition: simpleFeature.h:130
Represents a GIS feature. Features consist of a DtFeatureGeometry (2.5D geometric vector data) and a ...
Definition: feature.h:36
bool deleted
Definition: simpleFeature.h:174
std::vector< Attribute > AttributeVector
Definition: simpleFeature.h:107
void addAttribute(const Key &k, Attribute attr)
Definition: simpleFeature.h:50
DtFeatureGeometry myGeometry
Definition: simpleFeature.h:111
Represents a feature geometry.
Definition: featureGeometry.h:40
std::shared_ptr< DtSimpleFeature > Ptr
Definition: simpleFeature.h:28
boost::variant< std::string, long long, bool, double > Attribute
boost::variant type for accessing attributes.
Definition: feature.h:47
virtual void forEachAttribute(ForEachFunction f) const override
Calls the provided callback on each attribute.
Definition: simpleFeature.h:87

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)