VR-Vantage API Documentation
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 
86  static StateType* findState(DtSimEntry& entry);
87 
89  boost::signal<void (DtStateView<StateType>*)> signal_stateViewUpdated;
90 
91  DtUniqueID id() const
92  {
93  return mySimEntry.id();
94  }
95 
96  private:
97 
99  DtStateView();
100  DtStateView(const DtStateView&);
102 
103  protected:
104 
106  StateType* myState;
107  };
108 
109  template<class StateType>
111  : DtBaseStateView()
112  , mySimEntry(entry)
113  , myState(0)
114  {
116  if(!myState)
117  {
118  DtTHROW_NEW(DtCorruptedState,
119  "Unable to create DtStateView from DtSimEntry."
120  "Use isCompatible() before creating DtStateView.");
121  }
122  }
123 
124  template<class StateType>
126  {
128  mySimEntry.setUpdateRate(DtSimEntryUpdater::NoUpdates, this);
129  }
130 
131  template<class StateType>
133  {
134  mySimEntry.forceUpdate(this);
135  }
136 
137  template<class StateType>
139  {
140  mySimEntry.setUpdateRate(rate, this);
141  }
142 
143  template<class StateType>
145  {
146  signal_stateViewUpdated(this);
147  }
148 
149  template<class StateType>
151  {
152  bool bRet = false;
153  StateType* type = DtStateView<StateType>::findState(entry);
154  if(type)
155  {
156  bRet = true;
157  }
158  return bRet;
159  }
160 
161  template <class StateType>
163  {
164  DtSimEntry::SimStateVector::const_iterator pos = entry.simStates().begin();
165  DtSimEntry::SimStateVector::const_iterator endPos = entry.simStates().end();
166  for(; pos != endPos; ++pos)
167  {
168  StateType* tState = dynamic_cast<StateType*>(*pos);
169  if(tState)
170  {
171  return tState;
172  }
173  }
174  return 0;
175  }
176 
177  template<class StateType>
178  const StateType& DtStateView<StateType>::state()
179  {
180  return *myState;
181  }
182 
183  template<class StateType>
184  const StateType& DtStateView<StateType>::state() const
185  {
186  return *myState;
187  }
188 
189 
190 }
191 
192 #endif
193 


Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)