TraCIHandler.cpp
Go to the documentation of this file.00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TraCIHandler.h"
00024
00025 #ifndef NO_TRACI
00026
00027 #include "utils/options/OptionsCont.h"
00028 #include "utils/common/StdDefs.h"
00029
00030 #ifdef CHECK_MEMORY_LEAKS
00031 #include <foreign/nvwa/debug_new.h>
00032 #endif // CHECK_MEMORY_LEAKS
00033
00034
00035
00036
00037
00038 namespace traci {
00039
00040 TraCIHandler::TraCIHandler(const std::string& file)
00041 throw()
00042 :SUMOSAXHandler(file),
00043 totalVehicleCount(0),
00044 currentVehCount(0) {}
00045
00046 TraCIHandler::~TraCIHandler()
00047 throw() {}
00048
00049 void
00050 TraCIHandler::myStartElement(SumoXMLTag element, const SUMOSAXAttributes& attributes)
00051 throw(ProcessError) {
00052 if (element == SUMO_TAG_VEHICLE) {
00053 openVehicleTag(attributes);
00054 }
00055 }
00056
00057 void
00058 TraCIHandler::myEndElement(SumoXMLTag element)
00059 throw(ProcessError) {
00060 if (element == SUMO_TAG_VEHICLE) {
00061 totalVehicleCount += currentVehCount;
00062 }
00063 }
00064
00065 void
00066 TraCIHandler::openVehicleTag(const SUMOSAXAttributes& attributes) {
00067 int repNo;
00068 int period;
00069 int depart;
00070 OptionsCont& optCont = OptionsCont::getOptions();
00071 SUMOTime simStart = string2time(optCont.getString("begin"));
00072 SUMOTime simEnd = string2time(optCont.getString("end"));
00073 if(simEnd<0) {
00074 simEnd = SUMOTime_MAX;
00075 }
00076
00077 currentVehCount = 1;
00078
00079 try {
00080 repNo = attributes.getInt(SUMO_ATTR_REPNUMBER);
00081 period = attributes.getInt(SUMO_ATTR_PERIOD);
00082 } catch (...) {
00083 repNo = 0;
00084 period = 0;
00085 }
00086
00087
00088 try {
00089 depart = attributes.getInt(SUMO_ATTR_DEPART);
00090 } catch (...) {
00091
00092 currentVehCount = 0;
00093
00094 return;
00095 }
00096
00097 while ((depart < simStart) && (repNo >= 0)) {
00098 depart += period;
00099 repNo--;
00100
00101 }
00102
00103
00104 while (((depart + (repNo * period)) > simEnd) && (repNo >= 0)) {
00105 repNo--;
00106
00107
00108 }
00109
00110
00111 currentVehCount += repNo;
00112
00113 }
00114
00115 int
00116 TraCIHandler::getTotalVehicleCount() {
00117 return totalVehicleCount;
00118 }
00119
00120 void
00121 TraCIHandler::resetTotalVehicleCount() {
00122 totalVehicleCount = 0;
00123 }
00124
00125 }
00126
00127 #endif