VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtStateView.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2009 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 /******************************************************************************
6 ** $RCSfile: DtStateView.h,v $ $Revision: 1.12 $ $State: Exp $
7 ******************************************************************************/
8 
12 
13 #ifndef DtStateView_H_
14 #define DtStateView_H_
15 
16 #include <vrvCore/vrvCore.h>
18 #include <vrvCore/DtSimEntry.h>
19 #include <boost/signal.hpp>
20 
21 #include <vlutil/vlExceptions.h>
22 
23 namespace makVrv
24 {
25 
29  {
30 
31  public:
32 
34  virtual ~DtBaseStateView();
35 
39  virtual void emitStateViewUpdated() = 0;
40 
41  protected :
42 
45 
46  };
47 
51  template<class StateType>
53  {
54 
55  public:
56 
58  DtStateView(DtSimEntry& entry);
59 
61  virtual ~DtStateView();
62 
65  void forceUpdate();
66 
69 
73  virtual void emitStateViewUpdated();
74 
76  const StateType& state();
77 
79  const StateType& state() const;
80 
82  static bool isCompatible(DtSimEntry& entry);
83 
85  static bool isCompatible(DtSimState& entry);
86 
89  static StateType* findState(DtSimEntry& entry);
90 
92  boost::signal<void (DtStateView<StateType>*)> signal_stateViewUpdated;
93 
94  DtUniqueID id() const
95  {
96  return mySimEntry.id();
97  }
98 
99  private:
100 
102  DtStateView();
103  DtStateView(const DtStateView&);
105 
106  protected:
107 
109  StateType* myState;
110  };
111 
112  template<class StateType>
114  : DtBaseStateView()
115  , mySimEntry(entry)
116  , myState(0)
117  {
119  if(!myState)
120  {
121  DtTHROW_NEW(DtCorruptedState,
122  "Unable to create DtStateView from DtSimEntry."
123  "Use isCompatible() before creating DtStateView.");
124  }
125  }
126 
127  template<class StateType>
129  {
131  mySimEntry.setUpdateRate(DtSimEntryUpdater::NoUpdates, this);
132  }
133 
134  template<class StateType>
136  {
137  mySimEntry.forceUpdate(this);
138  }
139 
140  template<class StateType>
142  {
143  mySimEntry.setUpdateRate(rate, this);
144  }
145 
146  template<class StateType>
148  {
149  signal_stateViewUpdated(this);
150  }
151 
152  template<class StateType>
154  {
155  bool bRet = false;
156  StateType* type = DtStateView<StateType>::findState(entry);
157  if(type)
158  {
159  bRet = true;
160  }
161  return bRet;
162  }
163 
164  template<class StateType>
166  {
167  bool bRet = false;
168  StateType* tState = dynamic_cast<StateType*>(&state);
169  if(tState)
170  {
171  bRet = true;
172  }
173  return bRet;
174  }
175 
176  template <class StateType>
178  {
179  DtSimEntry::SimStateVector::const_iterator pos = entry.simStates().begin();
180  DtSimEntry::SimStateVector::const_iterator endPos = entry.simStates().end();
181  for(; pos != endPos; ++pos)
182  {
183  StateType* tState = dynamic_cast<StateType*>(*pos);
184  if(tState)
185  {
186  return tState;
187  }
188  }
189  return 0;
190  }
191 
192  template<class StateType>
193  const StateType& DtStateView<StateType>::state()
194  {
195  return *myState;
196  }
197 
198  template<class StateType>
199  const StateType& DtStateView<StateType>::state() const
200  {
201  return *myState;
202  }
203 
204 
205 }
206 
207 #endif
208 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)