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

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)