openETCS
case study for the European Train Control System developed for the authors dissertation
Language.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 language classes
23  */
24 
25 #ifndef __OETCS_DF_LANGUAGE_H__
26 #define __OETCS_DF_LANGUAGE_H__
27 
28 
29 
30 
31 #include <map>
32 #include "Configuration.h"
33 #include "Error/ExceptionTypes.h"
34 #include <string>
35 #include <vector>
36 #include "Storage.h"
37 
38 
39 namespace oETCS { namespace UT { class CLanguage; } }
40 
41 namespace oETCS { namespace DF { class CEVCStateMachine; } }
42 namespace oETCS { namespace DF { class CBitFlow; } }
43 
44 
45 namespace oETCS {
46 
47 namespace DF {
48 
49 
50 /*!
51  * \brief base class for all language structure classs
52  */
53 class CLanguage
54 {
55  public:
56  /*!
57  * \brief general constructor
58  *
59  * \param[in] pStateMachine pointer to the parent EVC state machine
60  */
61  explicit CLanguage(oETCS::DF::CEVCStateMachine * const pStateMachine) throw();
62 
63 
64 
65  /*!
66  * \brief destructor
67  */
68  virtual ~CLanguage() throw();
69 
70 
71 
72 
73 }; // class CLanguage
74 
75 
76 
77 /*!
78  * \brief class for holding variable values
79  */
81 {
82  public:
83  /*!
84  * \brief enum type for the physical unit type of a variable
85  */
86  enum UNIT_T
87  {
88  /*!
89  * \brief seconds as physical unit
90  */
91  SECONDS = 0,
92 
93  /*!
94  * \brief km/h as physical unit
95  */
97 
98  /*!
99  * \brief meters as physical unit
100  */
101  METERS = 2,
102 
103  /*!
104  * \brief centi meters as physical unit
105  */
107 
108  /*!
109  * \brief per mill as physical unit (unit less)
110  */
111  PER_MILL = 4,
112 
113  /*!
114  * \brief plain integer as physical unit (unit less)
115  */
116  INTEGER = 5,
117 
118  /*!
119  * \brief plain double as physical unit (unit less)
120  */
121  DOUBLE = 6,
122 
123  /*!
124  * \brief plain string as physical unit (unit less)
125  */
126  STRING = 7
127 
128 
129  }; // enum UNIT_T
130 
131 
132  /*!
133  * \brief general constructor
134  *
135  * Parameterises the Packet with all constant members.
136  * The Packet object takes over the posession of all variables/memory
137  * passed by pointer.
138  *
139  * \param[in] pStateMachine pointer to parent EVC state machine
140  * \param[in] iResolution numerical resolution
141  * \param[in] eUnit physical unit
142  * \param[in] bIsConditional optional flag for an conditional iterator
143  * \param{in] lConditionalValue optional value used for the conditional iterator
144  * \param[in] ValueMap optional map of values
145  */
146  explicit CVariable(oETCS::DF::CEVCStateMachine * const pStateMachine, const unsigned int & iResolution, const UNIT_T & eUnit, const unsigned long & lSize, const bool & bIsConditional = false, const long & lConditonalValue = 0, const ::std::map< VARIABLE_VALUE_VECTOR_T, CVariable * >& ValueMap = ::std::map< VARIABLE_VALUE_VECTOR_T, CVariable * >()) throw();
147 
148 
149 
150  /*!
151  * \brief deleted copy constructor
152  *
153  */
154  CVariable(const CVariable& Source) = delete;
155 
156 
157 
158  virtual ~CVariable() throw();
159 
160 
161 
162  /*!
163  * \brief calculates the value
164  *
165  * Calculates the real value, including value map and scaling,
166  * and stores it in the storage object under m_pValueStorage, if
167  * available.
168  */
169  void Calculate() throw(::oETCS::DF::Error::CException);
170 
171 
172 
173  /*!
174  * \brief gets the size of the variable depending on the value stored
175  *
176  * \return size of the variable in bits
177  */
178  unsigned long GetSize() const throw();
179 
180 
181 
182  /*!
183  * \brief sets explicitly the value of a variable by a string
184  *
185  * \param[in] Value new value as string
186  */
187  void SetValue(const ::std::string& Value) throw();
188 
189 
190 
191  /*!
192  * \brief streaming operator for filling a telegram with raw data
193  *
194  * \param[in] Bits vector of boolean holding the the exact amount of bit raw data in little endian format
195  */
196  CVariable& operator<<(const ::std::vector< bool >& Bits) throw(::oETCS::DF::Error::CException);
197 
198 
199 
200  /*!
201  * \brief streaming operator for getting the raw data in a variable
202  *
203  * \param[out] Bits vector of boolean holding the bit raw data in little endian format
204  * \return reference to this instance
205  */
206  CVariable& operator>>(::std::vector< bool >& Bits) throw(::oETCS::DF::Error::CException);
207 
208 
209 
210  /*!
211  * \brief deleted assignment operator
212  *
213  */
214  CVariable & operator=(const CVariable & Source) = delete;
215 
216 
217 
218  /*!
219  * \brief convertion method
220  *
221  * Converts a string (encoded by a prefix) to the
222  * value vector type used by language variables.\n\n
223  * Prefixes:\n
224  * d - double value
225  * s - string value
226  * i - integer value
227  * all other - binary value
228  *
229  * \param[in] Value string with the value to convert
230  * \return converted value vector
231  */
232  static oETCS::DF::VARIABLE_VALUE_VECTOR_T StringToValueVector(const ::std::string& Value) throw();
233 
234 
235 
236  /*!
237  * \brief fixed resolution of a variable
238  */
239  const unsigned int m_iResolution;
240 
241 
242 
243  /*!
244  * \brief unit of variable value
245  */
247 
248 
249 
250  /*!
251  * \brief size of the variable in bit
252  */
253  const unsigned long m_lSize;
254 
255 
256 
257 
258  private:
259  /*!
260  * \brief vector as bit storages for the value of a variable
261  *
262  * Index 0 (m_Value[0]) is the LSB.
263  */
264  ::std::vector< oETCS::DF::VARIABLE_VALUE_T > m_Value;
265 
266 
267 
268  /*!
269  * \brief iteration factor
270  *
271  * Defines how many times a variable object is iterated.
272  */
273  unsigned int m_iIterated;
274 
275 
276 
277  /*!
278  * \brief scalar factor
279  *
280  * Is multiplied with any numerical result of the value calculation
281  */
282  double m_dFactor;
283 
284 
285 
286  /*!
287  * \brief flag for variable being a conditional iterator
288  */
290 
291 
292 
293  /*!
294  * \brief conditional value used, if conditional operator
295  */
297 
298 
299 
300 
301  public:
302  /*!
303  * \brief vector of pointers to bit flows to storages
304  */
305  ::std::vector< oETCS::DF::CBitFlow* > m_BitValues;
306 
307 
308 
309  /*!
310  * \brief vector with pointers to allvariable objecst which are scaled by this instance
311  */
312  ::std::vector< CVariable* > m_ScaledVariables;
313 
314 
315 
316  /*!
317  * \brief vector with pointers to all variables which are iterated by this instance
318  */
319  ::std::vector< CVariable* > m_IteratedVariables;
320 
321 
322 
323 
324  private:
325  /*!
326  * \brief optional map of certain byte values to predefined variables
327  */
328  const ::std::map< oETCS::DF::VARIABLE_VALUE_VECTOR_T, CVariable* > m_ValueMap;
329 
330 
331 
332 
333 // only include the following, if unit test framework is available
334 #ifdef __HAS_UNIT_TEST__
335 
337 
338 #endif // #ifdef __HAS_UNIT_TEST__
339 
340 }; // class CVariable : public oETCS::DF::CLanguage
341 
342 
343 
344 /*!
345  * \brief class for holding packet information
346  */
348 {
349  public:
350  /*!
351  * \brief general constructor
352  *
353  * Parameterises the Packet with all constant members.
354  * The Packet object takes over the posession of all variables/memory
355  * passed by pointer.
356  *
357  * \param[in] pStateMachine pointer to parent EVC state machine
358  * \param[in] cID unique numerical ID of the packet
359  * \param[in] Variables optional vector with pointers to all packets supported
360  */
361  explicit CPacket(oETCS::DF::CEVCStateMachine * const pStateMachine, const unsigned char & cID, const ::std::vector< oETCS::DF::CVariable * >& Variables = ::std::vector< oETCS::DF::CVariable* >(0)) throw();
362 
363 
364 
365  /*!
366  * \brief deleted copy constructor
367  */
368  CPacket(const CPacket & Source) = delete;
369 
370 
371 
372  /*!
373  * \brief destructor
374  */
375  virtual ~CPacket() throw();
376 
377 
378 
379  /*!
380  * \brief gets the size of the packet depending on the variables stored
381  *
382  * \return size of the packet in bits
383  */
384  unsigned long GetSize() const throw();
385 
386 
387 
388  /*!
389  * \brief streaming operator for filling a telegram with raw data
390  *
391  * Bits consumed for packet and underlying variabke reconstruction are
392  * removed from bit stream vector.
393  * The first sizeof(m_cID) bytes are compared with m_cID. If unequal,
394  * the complete bit stream will be ignored.
395  *
396  * \param[inout] Bits vector of boolean holding the bit raw data in little endian format
397  */
398  CPacket& operator<<(::std::vector< bool >& Bits) throw(::oETCS::DF::Error::CException);
399 
400 
401 
402  /*!
403  * \brief streaming operator for getting the raw data in a packet
404  *
405  * \param[out] Bits vector of boolean holding the bit raw data in little endian format
406  * \return reference to this instance
407  */
408  CPacket& operator>>(::std::vector< bool >& Bits) throw();
409 
410 
411 
412  /*!
413  * \brief deleted assignment operator
414  */
415  CPacket operator=(const CPacket& Source) = delete;
416 
417 
418 
419  /*!
420  * \brief numerical unique ID of a packet
421  */
422  const unsigned char m_cID;
423 
424 
425 
426 
427  private:
428  /*!
429  * \brief vector with pointers to all possible included variables in their order
430  */
431  ::std::vector< oETCS::DF::CVariable* > m_Variables;
432 
433 
434 
435 
436 // only include the following, if unit test framework is available
437 #ifdef __HAS_UNIT_TEST__
438 
440 
441 #endif // #ifdef __HAS_UNIT_TEST__
442 
443 }; // class CPacket : public oETCS::DF::CLanguage
444 
445 
446 
447 /*!
448  * \brief class for holding telegram information
449  */
451 {
452  public:
453  /*!
454  * \brief general constructor
455  *
456  * Parameterises the Telegram with all constant members.
457  * The Telegram object takes over the posession of all variables/memory
458  * passed by pointer.
459  *
460  * \param[in] pStateMachine pointer to parent EVC state machine
461  * \param[in] Header vector with pointers to all variables used as header
462  * \param[in] Packets vector with pointers to all packets supported
463  */
464  CTelegram(oETCS::DF::CEVCStateMachine * const pStateMachine, const ::std::vector< oETCS::DF::CVariable * >& Header, const ::std::vector< oETCS::DF::CPacket * >& Packets) throw();
465 
466 
467 
468  /*!
469  * \brief deleted copy constructor
470  *
471  */
472  CTelegram(const CTelegram& Source) = delete;
473 
474 
475 
476  /*!
477  * \brief destructor
478  */
479  virtual ~CTelegram() throw();
480 
481 
482 
483  /*!
484  * \brief gets the size of the telegram depending on the packets stored
485  *
486  * \return size of the telegram in bits
487  */
488  unsigned long GetSize() const throw();
489 
490 
491 
492  /*!
493  * \brief streaming operator for filling a telegram with raw data
494  *
495  * \param[in] Bits vector of boolean holding the bit raw data in little endian format
496  * \return vector with used ETCS Language Packet IDs found
497  */
498  ::std::vector< unsigned char > operator<<(const ::std::vector< bool >& Bits) throw(::oETCS::DF::Error::CException);
499 
500 
501 
502  /*!
503  * \brief streaming operator for getting the raw data in a telegram
504  *
505  * \param[out] Bits vector of boolean holding the bit raw data in little endian format
506  * \return reference to this instance
507  */
508  CTelegram& operator>>(::std::vector< bool >& Bits) throw();
509 
510 
511 
512  /*!
513  * \brief deleted assignment operator
514  */
515  CTelegram & operator=(const CTelegram & Source) = delete;
516 
517 
518 
519 
520  private:
521  /*!
522  * \brief vector with pointers to all possible included packets
523  */
524  ::std::vector< oETCS::DF::CPacket* > m_Packets;
525 
526 
527 
528  /*!
529  * \brief vector with pointers to all variables defining the header of a telegram
530  */
531  const ::std::vector< oETCS::DF::CVariable* > m_Header;
532 
533 
534 
535 
536 // only include the following, if unit test framework is available
537 #ifdef __HAS_UNIT_TEST__
538 
540 
541 #endif // #ifdef __HAS_UNIT_TEST__
542 
543 }; // class CTelegram : public oETCS::DF::CLanguage
544 
545 
546 
547 
548 
549 } // namespace oETCS::DF
550 
551 } // namespace oETCS
552 
553 #endif // __ OETCS_DF_LANGUAGE_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/.