VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicFeature.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include "features/feature.h"
13 
14 #include <boost/signals2.hpp>
15 #include <boost/foreach.hpp>
16 
17 namespace MAKVRinTerra
18 {
20  template <typename F>
22  : public F
23  , public boost::enable_shared_from_this< DtDynamicFeature<F> >
24  , public DtObjectDebugger< DtDynamicFeature<F> >
25  {
26  public:
27  typedef typename F::ForEachFunction ForEachFunction;
28  typedef typename F::Key Key;
29  typedef typename F::Attribute Attribute;
30  typedef typename F::DeleteCallback DeleteCallback;
31  typedef typename F::DetachCallback DetachCallback;
32 
33  typedef boost::shared_ptr<DtDynamicFeature> Ptr;
34  typedef boost::shared_ptr<const DtDynamicFeature> CPtr;
35 
37  : myDeletedFlag(false)
38  , myGeometry(geom)
39  {
40 
41  }
42 
44  {
45  if (!myDeletedFlag)
47  }
48 
49  DtFeature* clone() const
50  {
51  return new DtFeatureWrapper<F>(
52  const_cast<DtDynamicFeature*>(this)->shared_from_this());
53  }
54 
56  {
57  return myGeometry;
58  }
59 
61  {
62  BOOST_FOREACH(const typename AttributeMap::value_type& pair, myAttributes)
63  func(pair.first, pair.second);
64  }
65 
66  unsigned numberOfAttributes(const typename Key::String & name) const
67  {
68  if (myAttributes.find(name) != myAttributes.end())
69  return 1;
70 
71  return 0;
72  }
73 
74  bool hasAttribute(const Key & k) const
75  {
76  if (k.index == 0 && myAttributes.find(k.name) != myAttributes.end())
77  return true;
78 
79  return false;
80  }
81 
82  boost::optional<Attribute> attribute(const Key & k) const
83  {
84  if (k.index == 0)
85  {
86  typename AttributeMap::const_iterator i = myAttributes.find(k.name);
87  if (i != myAttributes.end())
88  return Attribute(i->second);
89  }
90 
91  return boost::none_t();
92  }
93 
95  {
96  if (!callback)
97  return DetachCallback();
98 
99  Mutex::scoped_lock lock(myMutex, false);
100  if (myDeletedFlag)
101  {
102  lock.release();
103  callback();
104  return DetachCallback();
105  }
106 
107  if (!lock.upgrade_to_writer() && myDeletedFlag)
108  {
109  lock.release();
110  callback();
111  return DetachCallback();
112  }
113 
114  boost::signals2::connection conn(myDeleteSignal.connect(callback, boost::signals2::at_front));
115  return boost::bind(&boost::signals2::connection::disconnect, conn);
116  }
117 
118  bool isDeleted() const
119  {
120  Mutex::scoped_lock lock(myMutex, false);
121  return myDeletedFlag;
122  }
123 
124  void setDeleted()
125  {
126  {
127  Mutex::scoped_lock lock(myMutex, true);
128  if (myDeletedFlag)
129  return;
130 
131  myDeletedFlag = true;
132  }
133 
134  myDeleteSignal();
135  myDeleteSignal.disconnect_all_slots();
136  }
137 
138  protected:
139  typedef tbb::spin_rw_mutex Mutex;
140  mutable Mutex myMutex;
142 
143  typedef boost::signals2::signal<void ()> DeleteSignal;
145 
147 
148  typedef std::map<Key, Attribute> AttributeMap;
150  };
151 }

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)