VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtStateView.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef DtStateView_H_
11 #define DtStateView_H_
12 
13 #include <vrvCore/vrvCore.h>
15 #include <vrvCore/DtSimEntry.h>
16 #include <vrvUtil/signalslib.h>
17 
18 #include <vlutil/vlExceptions.h>
19 
20 namespace makVrv
21 {
22 
26  {
27 
28  public:
29 
31  virtual ~DtBaseStateView();
32 
36  virtual void emitStateViewUpdated() = 0;
37 
38  protected :
39 
42 
43  };
44 
48  template<class StateType>
50  {
51 
52  public:
53 
55  DtStateView(DtSimEntry& entry);
56 
58  virtual ~DtStateView();
59 
62  void forceUpdate();
63 
66 
70  virtual void emitStateViewUpdated();
71 
73  const StateType& state();
74 
76  const StateType& state() const;
77 
79  static bool isCompatible(DtSimEntry& entry);
80 
82  static bool isCompatible(DtSimState& entry);
83 
86  static StateType* findState(DtSimEntry& entry);
87 
89  boost::signalslib::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  bool bRet = false;
165  StateType* tState = dynamic_cast<StateType*>(&state);
166  if(tState)
167  {
168  bRet = true;
169  }
170  return bRet;
171  }
172 
173  template <class StateType>
175  {
176  DtSimEntry::SimStateVector::const_iterator pos = entry.simStates().begin();
177  DtSimEntry::SimStateVector::const_iterator endPos = entry.simStates().end();
178  for(; pos != endPos; ++pos)
179  {
180  StateType* tState = dynamic_cast<StateType*>(*pos);
181  if(tState)
182  {
183  return tState;
184  }
185  }
186  return 0;
187  }
188 
189  template<class StateType>
190  const StateType& DtStateView<StateType>::state()
191  {
192  return *myState;
193  }
194 
195  template<class StateType>
196  const StateType& DtStateView<StateType>::state() const
197  {
198  return *myState;
199  }
200 
201 
202 }
203 
204 #endif
205 
const SimStateVector & simStates() const
SimStateVector accessor.
virtual ~DtStateView()
DTOR.
Definition: DtStateView.h:125
UpdateRate
Definition: DtSimEntryUpdater.h:31
StateType * myState
Definition: DtStateView.h:106
DtUniqueID id() const
Return the unique Id of this entry.
DtStateView()
Non-Existant.
static StateType * findState(DtSimEntry &entry)
Returns a pointer to the state type for an entry, if the state is not found a null pointer is returne...
Definition: DtStateView.h:174
A DtBaseStateView is a the base class for all DtStateView&#39;s.
Definition: DtStateView.h:25
A DtSimEntry is a container of DtSimState&#39;s and represents the total state of an simulation object...
Definition: DtSimEntry.h:27
virtual void emitStateViewUpdated()
This will get called by the DtSimEntry when the state for this view has been updated.
Definition: DtStateView.h:144
Definition: DtSimEntryUpdater.h:33
void forceUpdate()
Force a single update which will be sent to all views regardless of update rates. ...
Definition: DtStateView.h:132
Contains makVrv::DtSimEntry class.
#define DT_DLL_VRVCORE
Definition: vrvCore.h:20
A DtStateView is a the interface to simulation state information.
Definition: DtStateView.h:49
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
const StateType & state()
Return the state this is a view onto.
Definition: DtStateView.h:190
Contains makVrv::DtSimEntryUpdater class.
boost::signalslib::signal< void(DtStateView< StateType > *)> signal_stateViewUpdated
Emitted when a this view&#39;s state has been updated.
Definition: DtStateView.h:89
A DtSimState is the base class for all state objects.
Definition: DtSimState.h:19
DtSimEntry & mySimEntry
Definition: DtStateView.h:105
DtStateView & operator=(const DtStateView &)
static bool isCompatible(DtSimEntry &entry)
Returns true if the DtSimEntry contains a state of type T.
Definition: DtStateView.h:150
void setUpdateRate(DtSimEntryUpdater::UpdateRate rate)
Set the rate this view will be updated with state information.
Definition: DtStateView.h:138
DtUniqueID id() const
Definition: DtStateView.h:91
Contains DLL export macros.

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)