VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dynamicFeature.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 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 #ifdef DtObjectDebugger_Enable
25  , public DtObjectDebugger< DtDynamicFeature<F> >
26 #endif
27  {
28  public:
29  typedef typename F::ForEachFunction ForEachFunction;
30  typedef typename F::Key Key;
31  typedef typename F::Attribute Attribute;
32  typedef typename F::DeleteCallback DeleteCallback;
33  typedef typename F::DetachCallback DetachCallback;
34 
35  typedef boost::shared_ptr<DtDynamicFeature> Ptr;
36  typedef boost::shared_ptr<const DtDynamicFeature> CPtr;
37 
39  : myDeletedFlag(false)
40  , myGeometry(geom)
41  {
42 
43  }
44 
46  {
47  if (!myDeletedFlag)
49  }
50 
51  DtFeature* clone() const
52  {
53  return new DtFeatureWrapper<F>(
54  const_cast<DtDynamicFeature*>(this)->shared_from_this());
55  }
56 
58  {
59  return myGeometry;
60  }
61 
63  {
64  BOOST_FOREACH(const typename AttributeMap::value_type& pair, myAttributes)
65  func(pair.first, pair.second);
66  }
67 
68  unsigned numberOfAttributes(const typename Key::String & name) const
69  {
70  if (myAttributes.find(name) != myAttributes.end())
71  return 1;
72 
73  return 0;
74  }
75 
76  bool hasAttribute(const Key & k) const
77  {
78  if (k.index == 0 && myAttributes.find(k.name) != myAttributes.end())
79  return true;
80 
81  return false;
82  }
83 
84  boost::optional<Attribute> attribute(const Key & k) const
85  {
86  if (k.index == 0)
87  {
88  typename AttributeMap::const_iterator i = myAttributes.find(k.name);
89  if (i != myAttributes.end())
90  return Attribute(i->second);
91  }
92 
93  return boost::none_t();
94  }
95 
97  {
98  if (!callback)
99  return DetachCallback();
100 
101  Mutex::scoped_lock lock(myMutex, false);
102  if (myDeletedFlag)
103  {
104  lock.release();
105  callback();
106  return DetachCallback();
107  }
108 
109  if (!lock.upgrade_to_writer() && myDeletedFlag)
110  {
111  lock.release();
112  callback();
113  return DetachCallback();
114  }
115 
116  boost::signals2::connection conn(myDeleteSignal.connect(callback, boost::signals2::at_front));
117  return boost::bind(&boost::signals2::connection::disconnect, conn);
118  }
119 
120  bool isDeleted() const
121  {
122  Mutex::scoped_lock lock(myMutex, false);
123  return myDeletedFlag;
124  }
125 
126  void setDeleted()
127  {
128  {
129  Mutex::scoped_lock lock(myMutex, true);
130  if (myDeletedFlag)
131  return;
132 
133  myDeletedFlag = true;
134  }
135 
136  myDeleteSignal();
137  myDeleteSignal.disconnect_all_slots();
138  }
139 
140  protected:
141  typedef tbb::spin_rw_mutex Mutex;
142  mutable Mutex myMutex;
144 
145  typedef boost::signals2::signal<void ()> DeleteSignal;
147 
149 
150  typedef std::map<Key, Attribute> AttributeMap;
152  };
153 }
AttributeMap myAttributes
Definition: dynamicFeature.h:151
void setDeleted()
Definition: dynamicFeature.h:126
~DtDynamicFeature()
Definition: dynamicFeature.h:45
Key used to lookup attributes. The DtFeature interface is a dictionary that maps Key objects to attri...
Definition: feature.h:68
Wraps a feature object and makes sure all the callbacks are unhooked correctly In order to wrap a fea...
Definition: feature.h:301
Feature object representing a dynamic feature.
Definition: dynamicFeature.h:21
F::Attribute Attribute
Definition: dynamicFeature.h:31
bool isDeleted() const
Definition: dynamicFeature.h:120
DtFeature * clone() const
Definition: dynamicFeature.h:51
DetachCallback addDeleteCallback(const DeleteCallback &callback) const
Definition: dynamicFeature.h:96
DtFeatureGeometry geometry() const
Definition: dynamicFeature.h:57
Default on in debug, off in release.
Definition: objectCounter.h:27
DtDynamicFeature(DtFeatureGeometry geom=DtFeatureGeometry())
Definition: dynamicFeature.h:38
void forEachAttribute(ForEachFunction func) const
Definition: dynamicFeature.h:62
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
DeleteSignal myDeleteSignal
Definition: dynamicFeature.h:146
String name
Definition: feature.h:101
unsigned index
Definition: feature.h:102
boost::function< void(const Key &, const Attribute &)> ForEachFunction
Callback used to iterating through attributes with ForEachAttribute.
Definition: feature.h:151
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
bool myDeletedFlag
Definition: dynamicFeature.h:143
unsigned numberOfAttributes(const typename Key::String &name) const
Definition: dynamicFeature.h:68
Mutex myMutex
Definition: dynamicFeature.h:142
std::map< Key, Attribute > AttributeMap
Definition: dynamicFeature.h:150
tbb::spin_rw_mutex Mutex
Definition: dynamicFeature.h:141
F::DetachCallback DetachCallback
Definition: dynamicFeature.h:33
boost::shared_ptr< DtDynamicFeature > Ptr
Definition: dynamicFeature.h:35
boost::signals2::signal< void()> DeleteSignal
Definition: dynamicFeature.h:145
F::ForEachFunction ForEachFunction
Definition: dynamicFeature.h:29
boost::optional< Attribute > attribute(const Key &k) const
Definition: dynamicFeature.h:84
Case insensitive string.
Definition: feature.h:71
Represents a GIS feature. Features consist of a DtFeatureGeometry (2.5D geometric vector data) and a ...
Definition: feature.h:37
DtFeatureGeometry myGeometry
Definition: dynamicFeature.h:148
F::Key Key
Definition: dynamicFeature.h:30
boost::shared_ptr< const DtDynamicFeature > CPtr
Definition: dynamicFeature.h:36
Represents a feature geometry.
Definition: featureGeometry.h:39
F::DeleteCallback DeleteCallback
Definition: dynamicFeature.h:32
bool hasAttribute(const Key &k) const
Definition: dynamicFeature.h:76

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)