VR-Forces 4.7 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 
2 
3 
4 
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 
57  DtFeatureGeometry geometry() const
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 
81  void forEachAttribute(ForEachFunction f) const
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 
90  DetachCallback addDeleteCallback(const DeleteCallback&) const
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 

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)