VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtStateViewCollection.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/vrvCore.h>
13 #include <vrvCore/DtStateView.h>
14 #include <vrvCore/DtDe.h>
15 #include <vrvCore/DtUniqueID.h>
17 #include <vrvCore/DtDataBank.h>
19 
20 #include <boost/bind.hpp>
21 
22 namespace makVrv
23 {
26  template<class T>
28  {
29 
30  public:
31 
33  typedef std::map<DtUniqueID, DtStateView<T>* > StateViewMap;
34 
40 
42  virtual ~DtStateViewCollection();
43 
46 
48  size_t size() const;
49 
51  const StateViewMap& stateViewMap() const;
52 
54  bool hasStateView(DtUniqueID id) const;
55 
57  const DtStateView<T>* findStateView(DtUniqueID id) const;
58 
60  boost::signal<void (const DtStateView<T>&)> signal_stateViewAdded;
61 
63  boost::signal<void (const DtStateView<T>&)> signal_stateViewAboutToBeRemoved;
64 
65  protected:
66 
68  bool isCompatible(DtSimObjectEntry& entry);
69 
71  bool isCompatible(DtSimState& entry);
72 
75 
78 
81 
84 
87 
88  protected:
89 
94  };
95 
96 
97  template<class T>
100  : myDe(de)
101  , myStateViewMap()
102  , myRate(rate)
103  {
104  DtSimData& simDataObj = myDe.dataBank().simData();
105 
109 
112 
116 
119 
121  }
122 
123  template<class T>
125  {
126  // myConnections disconnects signal_simObjectEntryAdded,
127  // signal_simObjectEntryToBeRemoved, signal_simStateAdded,
128  // signal_simStateToBeRemoved
129  }
130 
131  template<class T>
133  {
134  if(isCompatible(entry))
135  {
137  onSimObjectEntryAboutToBeRemoved(entry);
138 
140  DtStateView<T>* sview = new DtStateView<T>(entry);
141  sview->setUpdateRate(myRate);
142  myStateViewMap[entry.id()] = sview;
143  signal_stateViewAdded(*sview);
144  }
145  }
146 
147  template<class T>
149  {
150  if(isCompatible(state))
151  {
153  onSimObjectStateEntryAboutToBeRemoved(entry, state);
154 
156  DtStateView<T>* sview = new DtStateView<T>(entry);
157  sview->setUpdateRate(myRate);
158  myStateViewMap[entry.id()] = sview;
159  signal_stateViewAdded(*sview);
160  }
161  }
162 
163  template<class T>
165  DtSimObjectEntry& entry)
166  {
167  if(isCompatible(entry))
168  {
169  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
170  if(iter != myStateViewMap.end())
171  {
172  signal_stateViewAboutToBeRemoved(*iter->second );
173  delete iter->second;
174  myStateViewMap.erase(iter);
175  }
176  }
177  }
178 
179  template<class T>
181  DtSimObjectEntry& entry, DtSimState& state)
182  {
183  if(isCompatible(state))
184  {
185  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
186  if(iter != myStateViewMap.end())
187  {
188  signal_stateViewAboutToBeRemoved(*iter->second );
189  delete iter->second;
190  myStateViewMap.erase(iter);
191  }
192  }
193  }
194 
195  template<class T>
197  {
198  return DtStateView<T>::isCompatible(entry);
199  }
200 
201  template<class T>
203  {
204  return DtStateView<T>::isCompatible(state);
205  }
206 
207  template<class T>
209  {
210  return myStateViewMap.size();
211  }
212 
213  template<class T>
215  {
216  DtSimData::SimEntryMap::const_iterator pos;
217  for(pos=myDe.dataBank().simData().simEntryMap().begin();
218  pos != myDe.dataBank().simData().simEntryMap().end(); ++pos )
219  {
220  DtSimObjectEntry* pEntry = dynamic_cast<DtSimObjectEntry*>(pos->second);
221  if(pEntry)
222  {
223  onSimObjectEntryAdded(*pEntry);
224  }
225  }
226  }
227 
228  template<class T>
230  {
231  myRate = rate;
232 
233  typename StateViewMap::const_iterator pos;
234  for(pos = myStateViewMap.begin(); pos != myStateViewMap.end(); ++pos )
235  {
236  pos->second->setUpdateRate(myRate);
237  }
238  }
239 
240  template<class T>
242  {
243  return myStateViewMap;
244  }
245 
246  template<class T>
248  {
249  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
250  return (iter != myStateViewMap.end());
251  }
252 
253  template<class T>
255  {
256  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
257  if(iter != myStateViewMap.end())
258  {
259  return iter->second;
260  }
261 
262  return 0;
263  }
264 }
boost::signal< void(DtSimObjectEntry &, DtSimState &)> signal_simStateAdded
Signal emitted when a DtSimState is added to a DtSimEntry.
Definition: DtSimData.h:95
void onSimObjectEntryAboutToBeRemoved(DtSimObjectEntry &entry)
Called when a DtSimObjectEntry is about to be removed.
Definition: DtStateViewCollection.h:164
boost::signal< void(DtSimObjectEntry &)> signal_simObjectEntryAdded
Signal emitted when a DtSimObjectEntry is added.
Definition: DtSimData.h:89
bool hasStateView(DtUniqueID id) const
Returns true if a state view with that ID exists.
Definition: DtStateViewCollection.h:247
DtSignalConnectionManager myConnections
Definition: DtStateViewCollection.h:93
UpdateRate
Definition: DtSimEntryUpdater.h:34
DtUniqueID id() const
Return the unique Id of this entry.
void setUpdateRate(DtSimEntryUpdater::UpdateRate rate)
Set the rate of every state view in the container.
Definition: DtStateViewCollection.h:229
The DtSimData is the repository for simulation specific, read only data.
Definition: DtSimData.h:31
void onSimObjectStateEntryAboutToBeRemoved(DtSimObjectEntry &entry, DtSimState &)
Called when a DtSimState is about to be removed from a DtSimObjectEntry.
Definition: DtStateViewCollection.h:180
Contains makVrv::DtStateView class.
virtual ~DtStateViewCollection()
DTOR.
Definition: DtStateViewCollection.h:124
Contains makVrv::DtDe class.
const DtStateView< T > * findStateView(DtUniqueID id) const
Find DtStateView by id.
Definition: DtStateViewCollection.h:254
void onSimObjectStateEntryAdded(DtSimObjectEntry &entry, DtSimState &)
Called when a DtSimState is added to a DtSimObjectEntry.
Definition: DtStateViewCollection.h:148
virtual DtDataBank & dataBank()
The DtDataBank accessor.
DtSimEntryUpdater::UpdateRate myRate
Definition: DtStateViewCollection.h:92
boost::signal< void(DtSimObjectEntry &)> signal_simObjectEntryToBeRemoved
Signal emitted when a DtSimObjectEntry is about to be removed.
Definition: DtSimData.h:92
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
boost::signal< void(const DtStateView< T > &)> signal_stateViewAdded
Signal emitted when a DtStateView is added.
Definition: DtStateViewCollection.h:60
A DtSimObjectEntry is an entry for a persistent simulation object like an entity. ...
Definition: DtSimObjectEntry.h:25
Contains makVrv::DtSimObjectEntry class.
void onSimObjectEntryAdded(DtSimObjectEntry &entry)
Called when a DtSimObjectEntry is added.
Definition: DtStateViewCollection.h:132
const StateViewMap & stateViewMap() const
Return the map of DtStateViews&#39;s in this collection.
Definition: DtStateViewCollection.h:241
A DtStateViewCollection is a collection of DtStateViews of a specific state.
Definition: DtStateViewCollection.h:27
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:24
DtStateViewCollection(DtDe &de, DtSimEntryUpdater::UpdateRate rate)
CTOR.
Definition: DtStateViewCollection.h:98
boost::signal< void(DtSimObjectEntry &, DtSimState &)> signal_simStateToBeRemoved
Signal emitted when a DtSimEntry is about to be removed from a DtSimObjectEntry.
Definition: DtSimData.h:99
unsigned long long DtUniqueID
Definition: DtUniqueID.h:22
bool isCompatible(DtSimObjectEntry &entry)
Returns true if the DtSimEntry contains a state of type T.
Definition: DtStateViewCollection.h:196
Base class to provide boost signal/slot management.
DtDe & myDe
Definition: DtStateViewCollection.h:90
A DtSimState is the base class for all state objects.
Definition: DtSimState.h:22
Contains makVrv::DtUniqueID type.
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
std::map< DtUniqueID, DtStateView< T > * > StateViewMap
Map of unique id&#39;s to DtStateViews&#39;s.
Definition: DtStateViewCollection.h:33
boost::signal< void(const DtStateView< T > &)> signal_stateViewAboutToBeRemoved
Signal emitted when a DtStateView is about to be removed.
Definition: DtStateViewCollection.h:63
DtSimData & simData()
Get simulation data.
Contains makVrv::DtDataBank class.
StateViewMap myStateViewMap
Definition: DtStateViewCollection.h:91
static bool isCompatible(DtSimEntry &entry)
Returns true if the DtSimEntry contains a state of type T.
Definition: DtStateView.h:153
void manageConnection(const boost::signalslib::connection &conn)
Connect a signal.
void populateFromExistingEntries()
Go through existing DtSimEntry&#39;s and populate this container.
Definition: DtStateViewCollection.h:214
size_t size() const
Return the number of the objects in the container.
Definition: DtStateViewCollection.h:208
void setUpdateRate(DtSimEntryUpdater::UpdateRate rate)
Set the rate this view will be updated with state information.
Definition: DtStateView.h:141
Contains DLL export macros.

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)