VR-Forces 4.1 Class Documentation
DtStateViewCollection.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2009 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 /******************************************************************************
6 ** $RCSfile: DtStateViewCollection.h,v $ $Revision: 1.13 $ $State: Exp $
7 ******************************************************************************/
8 
12 
13 #ifndef DtStateViewCollection_H_
14 #define DtStateViewCollection_H_
15 
16 #include <vrvCore/vrvCore.h>
17 #include <vrvCore/DtStateView.h>
18 #include <vrvCore/DtDe.h>
19 #include <vrvCore/DtUniqueID.h>
21 #include <vrvCore/DtDataBank.h>
22 
23 #include <boost/bind.hpp>
24 
25 namespace makVrv
26 {
29  template<class T>
31  {
32 
33  public:
34 
36  typedef std::map<DtUniqueID, DtStateView<T>* > StateViewMap;
37 
43 
45  virtual ~DtStateViewCollection();
46 
49 
51  size_t size() const;
52 
54  const StateViewMap& stateViewMap() const;
55 
57  bool hasStateView(DtUniqueID id) const;
58 
60  const DtStateView<T>* findStateView(DtUniqueID id) const;
61 
63  boost::signal<void (const DtStateView<T>&)> signal_stateViewAdded;
64 
66  boost::signal<void (const DtStateView<T>&)> signal_stateViewAboutToBeRemoved;
67 
68  protected:
69 
71  bool isCompatible(DtSimObjectEntry& entry);
72 
75 
78 
81 
82  protected:
83 
87 
88  };
89 
90 
91  template<class T>
94  : myDe(de)
95  , myStateViewMap()
96  , myRate(rate)
97  {
99  myDe.dataBank().simData().signal_simObjectEntryAdded.connect(boost::bind(
101 
102  myDe.dataBank().simData().signal_simObjectEntryToBeRemoved.connect(boost::bind(
104 
106  myDe.dataBank().simData().signal_simStateAdded.connect(boost::bind(
108 
109  myDe.dataBank().simData().signal_simStateToBeRemoved.connect(boost::bind(
111 
113  }
114 
115  template<class T>
117  {
119  myDe.dataBank().simData().signal_simObjectEntryAdded.disconnect(boost::bind(
121 
122  myDe.dataBank().simData().signal_simObjectEntryToBeRemoved.disconnect(boost::bind(
124 
126  myDe.dataBank().simData().signal_simStateAdded.disconnect(boost::bind(
128 
129  myDe.dataBank().simData().signal_simStateToBeRemoved.disconnect(boost::bind(
131  }
132 
133  template<class T>
135  {
136  if(isCompatible(entry))
137  {
139  onSimObjectEntryAboutToBeRemoved(entry);
140 
142  DtStateView<T>* sview = new DtStateView<T>(entry);
143  sview->setUpdateRate(myRate);
144  myStateViewMap[entry.id()] = sview;
145  signal_stateViewAdded(*sview);
146  }
147  }
148 
149  template<class T>
151  DtSimObjectEntry& entry)
152  {
153  if(isCompatible(entry))
154  {
155  typename StateViewMap::iterator iter = myStateViewMap.find(entry.id());
156  if(iter != myStateViewMap.end())
157  {
158  signal_stateViewAboutToBeRemoved(*iter->second );
159  delete iter->second;
160  myStateViewMap.erase(iter);
161  }
162  }
163  }
164 
165  template<class T>
167  {
168  return DtStateView<T>::isCompatible(entry);
169  }
170 
171  template<class T>
173  {
174  return myStateViewMap.size();
175  }
176 
177  template<class T>
179  {
180  DtSimData::SimEntryMap::const_iterator pos;
181  for(pos=myDe.dataBank().simData().simEntryMap().begin();
182  pos != myDe.dataBank().simData().simEntryMap().end(); ++pos )
183  {
184  DtSimObjectEntry* pEntry = 0;
185  if(pEntry = dynamic_cast<DtSimObjectEntry*>(pos->second))
186  {
187  onSimObjectEntryAdded(*pEntry);
188  }
189  }
190  }
191 
192  template<class T>
194  {
195  myRate = rate;
196 
197  typename StateViewMap::const_iterator pos;
198  for(pos = myStateViewMap.begin(); pos != myStateViewMap.end(); ++pos )
199  {
200  pos->second->setUpdateRate(myRate);
201  }
202  }
203 
204  template<class T>
206  {
207  return myStateViewMap;
208  }
209 
210  template<class T>
212  {
213  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
214  return (iter != myStateViewMap.end());
215  }
216 
217  template<class T>
219  {
220  typename StateViewMap::const_iterator iter = myStateViewMap.find(id);
221  if(iter != myStateViewMap.end())
222  {
223  return iter->second;
224  }
225 
226  return 0;
227  }
228 }
229 
230 #endif
231 

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)