SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLDiscreteEventBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // }
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "NLDiscreteEventBuilder.h"
36 #include <microsim/MSNet.h>
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  : myNet(net) {
57  myActions["SaveTLSStates"] = EV_SAVETLSTATE;
58  myActions["SaveTLSSwitchTimes"] = EV_SAVETLSWITCHES;
59  myActions["SaveTLSSwitchStates"] = EV_SAVETLSWITCHSTATES;
60 }
61 
62 
64 
65 
66 void
68  const std::string& basePath) {
69  bool ok = true;
70  const std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, 0, ok, "");
71  // check whether the type was given
72  if (type == "" || !ok) {
73  throw InvalidArgument("An action's type is not given.");
74  }
75  // get the numerical representation
76  KnownActions::iterator i = myActions.find(type);
77  if (i == myActions.end()) {
78  throw InvalidArgument("The action type '" + type + "' is not known.");
79  }
80  // build the action
81  switch ((*i).second) {
82  case EV_SAVETLSTATE:
83  buildSaveTLStateCommand(attrs, basePath);
84  break;
85  case EV_SAVETLSWITCHES:
86  buildSaveTLSwitchesCommand(attrs, basePath);
87  break;
89  buildSaveTLSwitchStatesCommand(attrs, basePath);
90  break;
91  }
92 }
93 
94 
95 void
97  const std::string& basePath) {
98  bool ok = true;
99  const std::string dest = attrs.getOptStringReporting(SUMO_ATTR_DEST, 0, ok, "");
100  const std::string source = attrs.getOptStringReporting(SUMO_ATTR_SOURCE, 0, ok, "");
101  // check the parameter
102  if (dest == "" || !ok) {
103  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occured.");
104  }
105  if (source == "") {
106  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
107  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
109  new Command_SaveTLSState(logics, OutputDevice::getDevice(dest, basePath));
110  }
111  } else {
112  // get the logic
113  if (!myNet.getTLSControl().knows(source)) {
114  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
115  }
116  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
117  // build the action
118  new Command_SaveTLSState(logics, OutputDevice::getDevice(dest, basePath));
119  }
120 }
121 
122 
123 void
125  const std::string& basePath) {
126  bool ok = true;
127  const std::string dest = attrs.getOptStringReporting(SUMO_ATTR_DEST, 0, ok, "");
128  const std::string source = attrs.getOptStringReporting(SUMO_ATTR_SOURCE, 0, ok, "");
129  // check the parameter
130  if (dest == "" || !ok) {
131  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occured.");
132  }
133  if (source == "") {
134  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
135  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
137  new Command_SaveTLSSwitches(logics, OutputDevice::getDevice(dest, basePath));
138  }
139  } else {
140  // get the logic
141  if (!myNet.getTLSControl().knows(source)) {
142  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
143  }
144  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
145  // build the action
146  new Command_SaveTLSSwitches(logics, OutputDevice::getDevice(dest, basePath));
147  }
148 }
149 
150 
151 void
153  const std::string& basePath) {
154  bool ok = true;
155  const std::string dest = attrs.getOptStringReporting(SUMO_ATTR_DEST, 0, ok, "");
156  const std::string source = attrs.getOptStringReporting(SUMO_ATTR_SOURCE, 0, ok, "");
157  // check the parameter
158  if (dest == "" || !ok) {
159  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occured.");
160  }
161  if (source == "") {
162  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
163  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
165  new Command_SaveTLSSwitchStates(logics, OutputDevice::getDevice(dest, basePath));
166  }
167  } else {
168  // get the logic
169  if (!myNet.getTLSControl().knows(source)) {
170  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
171  }
172  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
173  // build the action
174  new Command_SaveTLSSwitchStates(logics, OutputDevice::getDevice(dest, basePath));
175  }
176 }
177 
178 
179 
180 /****************************************************************************/