SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSTriggeredReader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The basic class for classes that read triggers
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <microsim/MSNet.h>
33 #include "MSTriggeredReader.h"
34 
35 #ifdef CHECK_MEMORY_LEAKS
36 #include <foreign/nvwa/debug_new.h>
37 #endif // CHECK_MEMORY_LEAKS
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44  : myOffset(0), myWasInitialised(false) {}
45 
46 
48 
49 
50 void
52  myInit();
53  myWasInitialised = true;
54 }
55 
56 
57 bool
59  return myWasInitialised;
60 }
61 
62 
65  if (!isInitialised()) {
66  init();
67  }
68  SUMOTime next = current;
69  // loop until the next action lies in the future
70  while (current == next) {
71  // run the next action
72  // if it could be accomplished...
74  // read the next one
75  if (readNextTriggered()) {
76  // set the time for comparison if a next one exists
77  next = myOffset;
78  } else {
79  // leave if no further exists
80  return 0;
81  }
82  } else {
83  // action could not be accomplished; try next time step
84  return DELTA_T;
85  }
86  }
87  // come back if the next action shall be executed
88  if (myOffset - current <= 0) {
89  // current is delayed;
90  return DELTA_T;
91  }
92  return myOffset - current;
93 }
94 
95 
96 
97 /****************************************************************************/
98