openETCS
case study for the European Train Control System developed for the authors dissertation
Condition.cpp
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 condition class for control flows
23  */
24 
25 #include "Condition.h"
26 #include "EVCStateMachine.h"
27 
28 
29 
30 
31 namespace oETCS {
32 
33 namespace DF {
34 
35 
36 CCondition::CCondition(oETCS::DF::CEVCStateMachine * const pStateMachine) throw()
37 :CFunctionBlock(pStateMachine),
38  m_bGuard(false)
39 {
40  // Bouml preserved body begin 00064F82
41  // empty constructor
42  // Bouml preserved body end 00064F82
43 
44 } // CCondition::CCondition() throw()
45 
46 
47 
48 
50 {
51  // Bouml preserved body begin 00065002
52  // empty destructor
53  // Bouml preserved body end 00065002
54 
55 } // CCondition::~CCondition() throw()
56 
57 
58 
59 
60 void CCondition::Calculate() throw(::oETCS::DF::Error::CException)
61 {
62  // Bouml preserved body begin 00065082
63  const ::std::vector< ::oETCS::DF::CTransition* > TRANSITIONS(m_pStateMachine->GetActiveState()->GetTransitions());
64  const ::std::vector< ::oETCS::DF::CDataFlow* > DATA_FLOWS(m_pStateMachine->GetActiveState()->GetCurrentDataFlow());
65  ::std::vector< ::oETCS::DF::CFunctionBlock* > FunctionBlocks(0);
66  const unsigned int NUMBER_TRANSITIONS(TRANSITIONS.size());
67  const unsigned int NUMBER_DATAFLOWS(DATA_FLOWS.size());
68  unsigned int x(0);
69  unsigned int y(0);
70  unsigned int z(0);
71  bool bFound(false);
72 
73 
74 
75 #ifdef __DEBUG_OUTPUT__
76  // DEBUG
77  ::std::cerr << std::this_thread::get_id() << " " << "CCondition::Calculate() ----> method entered " << this << ::std::endl;
78 #endif
79 
80  // check, if this condition was activated
81  if (m_bGuard())
82  {
83 #ifdef __DEBUG_OUTPUT__
84  // DEBUG
85  ::std::cerr << std::this_thread::get_id() << " " << "CCondition::Calculate() ----> condition activated with # transitions " << NUMBER_TRANSITIONS << ::std::endl;
86 #endif
87 
88  // try to find corresponding transition object for this condition
89  for (x = 0; x < NUMBER_TRANSITIONS && !bFound; x++)
90  {
91  // check, if current transition object is related to this condition a control flow in the current data flow and the current state
92  if (TRANSITIONS[x]->GetCondition() == this)
93  {
94  // check all function block objects in current data flow(s) for control flow objects
95  for (y = 0; y < NUMBER_DATAFLOWS && !bFound; y++)
96  {
97  // get current vector of function block pointers
98  FunctionBlocks = DATA_FLOWS[y]->GetFunctionBlocks();
99 
100  // check current all objects in current data flow
101  for (z = 0; z < FunctionBlocks.size() && !bFound; z++)
102  {
103  // check, if current function block is a a control flow
104  if (dynamic_cast< ::oETCS::DF::CControlFlow* >(FunctionBlocks[z]) != 0)
105  {
106  // check, if transition is related to the current state of the current control flow
107  if (dynamic_cast< ::oETCS::DF::CControlFlow* >(FunctionBlocks[z])->GetCurrentState() == TRANSITIONS[x]->GetStartState())
108  {
109  // add transition on stack of parent control flow
110  static_cast< ::oETCS::DF::CControlFlow* >(FunctionBlocks[z])->GetCurrentState()->m_TransitionStack.push_back(TRANSITIONS[x]);
111 
112  // set found flag to true
113  bFound = true;
114 
115  } // if (dynamic_cast< ::oETCS::DF::CControlFlow* >(FunctionBlocks[z])->GetCurrentState() == TRANSITIONS[x]->GetStartState())
116 
117 
118  } // if (dynamic_cast< ::oETCS::DF::CControlFlow* >(FunctionBlocks[z]) != 0)
119 
120  } // for (z = 0; z < FunctionBlocks.size() && !bFound; z++)
121 
122  } // for (y = 0; y < NUMBER_DATAFLOWS && !bFound; y++)
123 
124  } // if (Transitions[x]->GetCondition() == this)
125 
126  } // for (x = 0; x < NUMBER_TRANSITIONS && !bFound; x++)
127 
128  // check, if the related transition was found
129  if (!bFound)
130  {
131  // throw exception
132  throw (::oETCS::DF::Error::CInternal("no matching transition found for control flow condition"));
133 
134  } // if (!bFound)
135 
136  } // if (m_bGuard())
137 
138  // Bouml preserved body end 00065082
139 
140 } // void CCondition::Calculate() throw(::oETCS::DF::Error::CException)
141 
142 
143 
144 
145 
146 
147 } // namespace oETCS::DF
148 
149 } // namespace oETCS

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/.