openETCS
case study for the European Train Control System developed for the authors dissertation
ControlFlow.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2012
3  Johannes Feuser <feuser@uni-bremen.de>
4  This file is part of the openETCS library.
5 
6  The openETCS library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  any later version.
10 
11  The openETCS library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \author Johannes Feuser <feuser@uni-bremen.de>
22  * \brief control flow classes
23  */
24 
25 #ifndef __OETCS_DF_CONTROLFLOW_H__
26 #define __OETCS_DF_CONTROLFLOW_H__
27 
28 
29 
30 
31 #include <string>
32 #include <vector>
33 #include "EVCStateMachine.h"
34 #include "Error/ExceptionTypes.h"
35 
36 
37 namespace oETCS { namespace DF { class CCondition; } }
38 
39 namespace oETCS { namespace DF { class CAbstractFlow; } }
40 namespace oETCS { namespace DF { class CTransition; } }
41 namespace oETCS { namespace DF { class CEVCStateMachine; } }
42 
43 
44 namespace oETCS {
45 
46 namespace DF {
47 
48 
49 /*!
50  * \brief control flow (state machine) class used in a data flow
51  */
53 {
54  public:
55  /*!
56  * \brief state class within a control flow
57  */
58  class CState
59  {
60  public:
61  /*!
62  * \brief general constructor
63  *
64  * Parameterises the state with all constant members.
65  * The data flow object takes over the posession of the passed data flow object.
66  *
67  * \param[in] pParent pointer to the parent control flow object
68  * \param[in] StateName literal name of the state
69  * \param[in] FunctionBlocks vector with pointers to function blocks, which are executed by this state
70  * \param[in] Flows vector with pointer to flow objects, which connect function blocks in this state
71  * \param[in] bIsFinal optinal flag for a final state
72  * \param[in] bIsFinal optinal flag for the initial state
73  */
74  CState(CControlFlow * const pParent, const std::string & StateName, const ::std::vector< oETCS::DF::CFunctionBlock * >& FunctionBlocks, const ::std::vector< oETCS::DF::CAbstractFlow * >& Flows, const bool & bIsFinal = false, const bool & bIsInitial = false) throw();
75 
76 
77 
78  virtual ~CState() throw();
79 
80 
81 
82  /*!
83  * \brief returns true, if a CFunctionBlock objects is active in a control flow
84  *
85  * \param[in] pFunctionBlock pointer to a function block object to be testetd
86  * \return active state flag
87  */
88  bool IsActiveFunctionBlock(const oETCS::DF::CFunctionBlock * const pFunctionBlock) const throw();
89 
90 
91 
92  /*!
93  * \brief returns true, if a CFlow object is active in a control flow
94  *
95  * \param[in] pFlow pointer to a concerete flow object
96  * \return active flow flag
97  */
98  bool IsActiveFlow(const oETCS::DF::CAbstractFlow * const pFlow) const throw();
99 
100 
101 
102  /*!
103  * \brief executes the state including data flow and possible transitions
104  */
105  void Execute() throw(::oETCS::DF::Error::CException);
106 
107 
108 
109  /*!
110  * \brief literal name of the state
111  */
112  const ::std::string m_Name;
113 
114 
115 
116  /*!
117  * \brief flag for a final state
118  */
119  const bool m_bIsFinal;
120 
121 
122 
123 
124  private:
125  /*!
126  * \brief pointer to the parent control flow object
127  */
129 
130 
131 
132  /*!
133  * \brief vector with pointers to transition objects, which were activated
134  */
135  ::std::vector< oETCS::DF::CTransition* > m_TransitionStack;
136 
137 
138 
139  /*!
140  * \brief vector with pointers to all function block objects, which are executed in a state
141  */
142  const ::std::vector< oETCS::DF::CFunctionBlock* > m_FunctionBlocks;
143 
144 
145 
146  /*!
147  * \brief vector with pointer to all flows/connections used in a control flow state
148  */
149  ::std::vector< oETCS::DF::CAbstractFlow* > m_Flows;
150 
151 
152 
153  friend class oETCS::DF::CCondition;
154 
155  }; // class CState
156 
157 
158 
159 
160  /*!
161  * \brief general constructor
162  *
163  * \param[in] pStateMachine pointer to the contenting state machine
164  */
165  explicit CControlFlow(oETCS::DF::CEVCStateMachine * const pStateMachine) throw();
166 
167 
168 
169  /*!
170  * \brief destructor
171  */
172  virtual ~CControlFlow() throw();
173 
174 
175 
176  /*!
177  * \brief registers a new state object in a control flow
178  *
179  * \param[in] pState pointer to state object to be registered
180  * \param[in] bIsInitial optional flag, if state is the initial state
181  */
182  void AddState(CState * const pState, const bool& bIsInitial) throw();
183 
184 
185 
186  /*!
187  * \brief returns true, if a CFunctionBlock objects is active in a control flow
188  *
189  * \param[in] pFunctionBlock pointer to a function block object to be testetd
190  * \return active state flag
191  */
192  bool IsActiveFunctionBlock(const oETCS::DF::CFunctionBlock * const pFunctionBlock) const throw();
193 
194 
195 
196  /*!
197  * \brief returns true, if a CFlow object is active in a control flow
198  *
199  * \param[in] pFlow pointer to a concerete flow object
200  * \return active flow flag
201  */
202  bool IsActiveFlow(const oETCS::DF::CAbstractFlow * const pFlow) const throw();
203 
204 
205 
206  /*!
207  * \brief gets the current state of the control flow
208  *
209  * \return pointer to the current state object
210  */
211  CState* const GetCurrentState() const throw();
212 
213 
214 
215  /*!
216  * \brief virtual method for computing all outputs and setting the all referenced outputs
217  *
218  * \remark must be implemented by any inheriting class
219  */
220  virtual void Calculate() throw(::oETCS::DF::Error::CException);
221 
222 
223 
224  /*!
225  * \brief storage of the start input value
226  */
227  oETCS::DF::BOOL_INPUT_T m_bStart;
228 
229 
230 
231  /*!
232  * \brief pointers to outputs for active state name
233  */
234  ::std::vector< oETCS::DF::STRING_OUTPUT_T > m_ActiveStateName;
235 
236 
237 
238  /*!
239  * \brief pointers to outputs for running flag
240  */
241  ::std::vector< oETCS::DF::BOOL_OUTPUT_T > m_IsRunning;
242 
243 
244 
245 
246  private:
247  /*!
248  * \brief vector with pointers to all available states in the control flow
249  */
250  ::std::vector< CState* > m_AvailableStates;
251 
252 
253 
254  /*!
255  * \brief pointer to current active state
256  */
258 
259 
260 
261  /*!
262  * \brief pointer to the unique initial state object
263  */
265 
266 
267 
268 
269 }; // class CControlFlow : public oETCS::DF::CFunctionBlock
270 
271 
272 
273 
274 
275 } // namespace oETCS::DF
276 
277 } // namespace oETCS
278 
279 #endif // __ OETCS_DF_CONTROLFLOW_H__

Copyright (C) 2010-2012 Johannes Feuser (feuser@uni-bremen.de)
The openETCS library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
The openETCS library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the openETCS library. If not, see "http://www.gnu.org/licenses/.