VR-Forces 4.6.1 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>
18 
19 #include <boost/bind.hpp>
20 
21 namespace makVrv
22 {
25  template<class T>
27  {
28 
29  public:
30 
32  typedef std::map<DtUniqueID, DtStateView<T>* > StateViewMap;
33 
39 
41  virtual ~DtStateViewCollection();
42 
45 
47  size_t size() const;
48 
50  const StateViewMap& stateViewMap() const;
51 
53  bool hasStateView(DtUniqueID id) const;
54 
56  const DtStateView<T>* findStateView(DtUniqueID id) const;
57 
59  boost::signal<void (const DtStateView<T>&)> signal_stateViewAdded;
60 
62  boost::signal<void (const DtStateView<T>&)> signal_stateViewAboutToBeRemoved;
63 
64  protected:
65 
67  bool isCompatible(DtSimObjectEntry& entry);
68 
70  bool isCompatible(DtSimState& entry);
71 
74 
77 
80 
83 
86 
87  protected:
88 
92 
93  };
94 
95 
96  template<class T>
99  : myDe(de)
100  , myStateViewMap()
101  , myRate(rate)
102  {
103  DtSimData& simDataObj = myDe.dataBank().simData();
104 
106  simDataObj.signal_simObjectEntryAdded.connect(boost::bind(
108 
111 
113  simDataObj.signal_simStateAdded.connect(boost::bind(
115 
116  simDataObj.signal_simStateToBeRemoved.connect(boost::bind(
118 
120  }
121 
122  template<class T>
124  {
125  DtSimData& simDataObj = myDe.dataBank().simData();
126 
128  simDataObj.signal_simObjectEntryAdded.disconnect(boost::bind(
130 
131  simDataObj.signal_simObjectEntryToBeRemoved.disconnect(boost::bind(
133 
135  simDataObj.signal_simStateAdded.disconnect(boost::bind(
137 
138  simDataObj.signal_simStateToBeRemoved.disconnect(boost::bind(
140  }
141 
142  template<class T>
144  {
145  if(isCompatible(entry))
146  {
148  onSimObjectEntryAboutToBeRemoved(entry);
149 
151  DtStateView<T>* sview = new DtStateView<T>(entry);
152  sview->setUpdateRate(myRate);
153  myStateViewMap[entry.id()] = sview;
154  signal_stateViewAdded(*sview);
155  }
156  }
157 
158  template<class T>
160  {
161  if(isCompatible(state))
162  {
164  onSimObjectStateEntryAboutToBeRemoved(entry, state);
165 
167  DtStateView<T>* sview = new DtStateView<T>(entry);
168  sview->setUpdateRate(myRate);
169  myStateViewMap[entry.id()] = sview;
170  signal_stateViewAdded(*sview);
171  }
172  }
173 
174  template<class T>
176  DtSimObjectEntry& entry)
177  {
178  if(isCompatible(entry))
179  {
180  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
181  if(iter != myStateViewMap.end())
182  {
183  signal_stateViewAboutToBeRemoved(*iter->second );
184  delete iter->second;
185  myStateViewMap.erase(iter);
186  }
187  }
188  }
189 
190  template<class T>
192  DtSimObjectEntry& entry, DtSimState& state)
193  {
194  if(isCompatible(state))
195  {
196  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
197  if(iter != myStateViewMap.end())
198  {
199  signal_stateViewAboutToBeRemoved(*iter->second );
200  delete iter->second;
201  myStateViewMap.erase(iter);
202  }
203  }
204  }
205 
206  template<class T>
208  {
209  return DtStateView<T>::isCompatible(entry);
210  }
211 
212  template<class T>
214  {
215  return DtStateView<T>::isCompatible(state);
216  }
217 
218  template<class T>
220  {
221  return myStateViewMap.size();
222  }
223 
224  template<class T>
226  {
227  DtSimData::SimEntryMap::const_iterator pos;
228  for(pos=myDe.dataBank().simData().simEntryMap().begin();
229  pos != myDe.dataBank().simData().simEntryMap().end(); ++pos )
230  {
231  DtSimObjectEntry* pEntry = dynamic_cast<DtSimObjectEntry*>(pos->second);
232  if(pEntry)
233  {
234  onSimObjectEntryAdded(*pEntry);
235  }
236  }
237  }
238 
239  template<class T>
241  {
242  myRate = rate;
243 
244  typename StateViewMap::const_iterator pos;
245  for(pos = myStateViewMap.begin(); pos != myStateViewMap.end(); ++pos )
246  {
247  pos->second->setUpdateRate(myRate);
248  }
249  }
250 
251  template<class T>
253  {
254  return myStateViewMap;
255  }
256 
257  template<class T>
259  {
260  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
261  return (iter != myStateViewMap.end());
262  }
263 
264  template<class T>
266  {
267  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
268  if(iter != myStateViewMap.end())
269  {
270  return iter->second;
271  }
272 
273  return 0;
274  }
275 }

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)