Eclipse SUMO - Simulation of Urban MObility
ODAmitranHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // An XML-Handler for Amitran OD matrices
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
24 #include "ODMatrix.h"
25 #include "ODAmitranHandler.h"
26 
27 
28 // ===========================================================================
29 // method definitions
30 // ===========================================================================
31 ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
32  : SUMOSAXHandler(file), myMatrix(matrix) {}
33 
34 
36 
37 
38 void
40  bool ok = true;
41  switch (element) {
43  myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
44  break;
45  case SUMO_TAG_TIMESLICE:
46  myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
47  myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
48  if (myBegin >= myEnd) {
49  WRITE_ERROR("Invalid duration for timeSlice starting " + toString(myBegin) + ".");
50  }
51  break;
52  case SUMO_TAG_OD_PAIR:
53  myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
54  myBegin, myEnd, attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
55  attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
56  break;
57  default:
58  break;
59  }
60 }
61 
62 
63 /****************************************************************************/
ODAmitranHandler::ODAmitranHandler
ODAmitranHandler(ODMatrix &matrix, const std::string &file)
Constructor.
Definition: ODAmitranHandler.cpp:31
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
SUMO_ATTR_ORIGIN
@ SUMO_ATTR_ORIGIN
Definition: SUMOXMLDefinitions.h:894
SUMOSAXAttributes::get
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:492
SUMO_ATTR_AMOUNT
@ SUMO_ATTR_AMOUNT
Definition: SUMOXMLDefinitions.h:893
MsgHandler.h
SUMO_ATTR_DESTINATION
@ SUMO_ATTR_DESTINATION
Definition: SUMOXMLDefinitions.h:895
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
ODMatrix.h
ODAmitranHandler::~ODAmitranHandler
~ODAmitranHandler()
Destructor.
Definition: ODAmitranHandler.cpp:35
ODAmitranHandler::myEnd
SUMOTime myEnd
Definition: ODAmitranHandler.h:86
ODAmitranHandler.h
ODMatrix::add
bool add(double vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false)
Builds a single cell from the given values, verifying them.
Definition: ODMatrix.cpp:63
SUMO_TAG_OD_PAIR
@ SUMO_TAG_OD_PAIR
Definition: SUMOXMLDefinitions.h:324
SUMO_TAG_TIMESLICE
@ SUMO_TAG_TIMESLICE
Definition: SUMOXMLDefinitions.h:321
SUMO_TAG_ACTORCONFIG
@ SUMO_TAG_ACTORCONFIG
Definition: SUMOXMLDefinitions.h:322
ODAmitranHandler::myBegin
SUMOTime myBegin
Definition: ODAmitranHandler.h:85
SUMO_ATTR_STARTTIME
@ SUMO_ATTR_STARTTIME
Definition: SUMOXMLDefinitions.h:889
ODMatrix
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:69
ODAmitranHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called when an opening-tag occurs.
Definition: ODAmitranHandler.cpp:39
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
SUMO_ATTR_DURATION
@ SUMO_ATTR_DURATION
Definition: SUMOXMLDefinitions.h:667
config.h
ODAmitranHandler::myMatrix
ODMatrix & myMatrix
The matrix to add demand to.
Definition: ODAmitranHandler.h:81
ODAmitranHandler::myVehicleType
std::string myVehicleType
Definition: ODAmitranHandler.h:83
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283