VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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  {
106 
109 
113 
116 
118  }
119 
120  template<class T>
122  {
124  myDe.dataBank().simData().signal_simObjectEntryAdded.disconnect(boost::bind(
126 
127  myDe.dataBank().simData().signal_simObjectEntryToBeRemoved.disconnect(boost::bind(
129 
131  myDe.dataBank().simData().signal_simStateAdded.disconnect(boost::bind(
133 
134  myDe.dataBank().simData().signal_simStateToBeRemoved.disconnect(boost::bind(
136  }
137 
138  template<class T>
140  {
141  if(isCompatible(entry))
142  {
144  onSimObjectEntryAboutToBeRemoved(entry);
145 
147  DtStateView<T>* sview = new DtStateView<T>(entry);
148  sview->setUpdateRate(myRate);
149  myStateViewMap[entry.id()] = sview;
150  signal_stateViewAdded(*sview);
151  }
152  }
153 
154  template<class T>
156  {
157  if(isCompatible(state))
158  {
160  onSimObjectStateEntryAboutToBeRemoved(entry, state);
161 
163  DtStateView<T>* sview = new DtStateView<T>(entry);
164  sview->setUpdateRate(myRate);
165  myStateViewMap[entry.id()] = sview;
166  signal_stateViewAdded(*sview);
167  }
168  }
169 
170  template<class T>
172  DtSimObjectEntry& entry)
173  {
174  if(isCompatible(entry))
175  {
176  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
177  if(iter != myStateViewMap.end())
178  {
179  signal_stateViewAboutToBeRemoved(*iter->second );
180  delete iter->second;
181  myStateViewMap.erase(iter);
182  }
183  }
184  }
185 
186  template<class T>
188  DtSimObjectEntry& entry, DtSimState& state)
189  {
190  if(isCompatible(state))
191  {
192  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
193  if(iter != myStateViewMap.end())
194  {
195  signal_stateViewAboutToBeRemoved(*iter->second );
196  delete iter->second;
197  myStateViewMap.erase(iter);
198  }
199  }
200  }
201 
202  template<class T>
204  {
205  return DtStateView<T>::isCompatible(entry);
206  }
207 
208  template<class T>
210  {
211  return DtStateView<T>::isCompatible(state);
212  }
213 
214  template<class T>
216  {
217  return myStateViewMap.size();
218  }
219 
220  template<class T>
222  {
223  DtSimData::SimEntryMap::const_iterator pos;
224  for(pos=myDe.dataBank().simData().simEntryMap().begin();
225  pos != myDe.dataBank().simData().simEntryMap().end(); ++pos )
226  {
227  DtSimObjectEntry* pEntry = 0;
228  if(pEntry = dynamic_cast<DtSimObjectEntry*>(pos->second))
229  {
230  onSimObjectEntryAdded(*pEntry);
231  }
232  }
233  }
234 
235  template<class T>
237  {
238  myRate = rate;
239 
240  typename StateViewMap::const_iterator pos;
241  for(pos = myStateViewMap.begin(); pos != myStateViewMap.end(); ++pos )
242  {
243  pos->second->setUpdateRate(myRate);
244  }
245  }
246 
247  template<class T>
249  {
250  return myStateViewMap;
251  }
252 
253  template<class T>
255  {
256  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
257  return (iter != myStateViewMap.end());
258  }
259 
260  template<class T>
262  {
263  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
264  if(iter != myStateViewMap.end())
265  {
266  return iter->second;
267  }
268 
269  return 0;
270  }
271 }

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)