openETCS
case study for the European Train Control System developed for the authors dissertation
ConstraintChecker.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2011
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 constraint checker file
23  */
24 
25 #include "ConstraintChecker.h"
26 
27 
28 
29 
30 namespace GOPPRR {
31 
32 
34 {
35  // Bouml preserved body begin 00103282
36  // empty destructor
37  // Bouml preserved body end 00103282
38 
39 } // CConstraintChecker::~CConstraintChecker() throw()
40 
41 
42 
43 
44 bool CConstraintChecker::Check(GOPPRR::CProject * const pProject, const ::std::string & OCLConstraints, ::std::ostream * const pOutStream) const throw(::GOPPRR::Error::CException)
45 {
46  // Bouml preserved body begin 000C1982
47  bool bValid(true);
48  ::std::time_t Now = ::std::chrono::system_clock::to_time_t(::std::chrono::system_clock::now());
49 
50 
51 
52  // check, if pointer to project is valid
53  if (pProject == nullptr)
54  {
55  // throw exception
56  throw (::GOPPRR::Error::CParameter("pointer to GOPPRR project not valid"));
57 
58  } // if (pProject == nullptr)
59 
60 
61 
62  // WARNING: below follows the specific implementation for the openETCS meta model
63  unsigned int iEVCGraphs(0);
64  decltype (::GOPPRR::CProject::m_GraphSet.begin()) Graph;
65 
66 
67 
68  // check, if out stream object is available
69  if (pOutStream != nullptr)
70  {
71  // generate header of output
72  (*pOutStream) << "Copyright (C) 2010-2012\n"
73  "Johannes Feuser <feuser@uni-bremen.de>\n"
74  "\n"
75  "Constraint report for static semantics of openETCS meta model\n"
76  "time point (UTC) of generation: " << ::std::asctime(::std::gmtime(&Now)) << "\n\n";
77 
78  } // if (pOutStream != nullptr)
79 
80 
81 
82  // constraint 1: number of EVCStateMachine graphs == 1 -----------------------------------------------
83  for (Graph = pProject->m_GraphSet.begin(); Graph != pProject->m_GraphSet.end(); Graph++)
84  {
85  // check type of current graph
86  if (Graph->second.m_Type == "EVCStateMachine" )
87  {
88  // increase number of instances
89  iEVCGraphs++;
90 
91  } // if (Graph->second.m_Type == "EVCStateMachine" )
92 
93  } // for (Graph = pProject->m_GraphSet.begin(); Graph != pProject->m_GraphSet.end(); Graph++)
94 
95  // check, if not exact one graph instance does exist
96  if (iEVCGraphs != 1)
97  {
98  // set valid flag
99  bValid = false;
100 
101  if (pOutStream != nullptr)
102  {
103  // print error
104  (*pOutStream) << "Contraint 1: number of EVCStateMachine graphs == 1 FAILED" << ::std::endl;
105 
106  } // if (pOutStream != nullptr)
107 
108  } // if (iEVCGraphs != 1) -----------------------------------------------------------------------------
109 
110 
111 
112 
113  if (pOutStream != nullptr)
114  {
115  // print verdict
116  (*pOutStream) << ::std::endl << "VERDICT: " << (bValid ? "PASSED" : "FAILED") << ::std::endl;
117 
118  } // if (pOutStream != nullptr)
119 
120  // return valid flag
121  return (bValid);
122  // Bouml preserved body end 000C1982
123 
124 } // bool CConstraintChecker::Check() const throw(::GOPPRR::Error::CException)
125 
126 
127 
128 
129 
130 
131 } // namespace GOPPRR

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