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 /****************************************************************************/
15 // An XML-Handler for Amitran OD matrices
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
25 #include "ODMatrix.h"
26 #include "ODAmitranHandler.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
33  : SUMOSAXHandler(file), myMatrix(matrix) {}
34 
35 
37 
38 
39 void
41  bool ok = true;
42  switch (element) {
44  myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
45  break;
46  case SUMO_TAG_TIMESLICE:
47  myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
48  myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
49  if (myBegin >= myEnd) {
50  WRITE_ERROR("Invalid duration for timeSlice starting " + toString(myBegin) + ".");
51  }
52  break;
53  case SUMO_TAG_OD_PAIR:
54  myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
55  myBegin, myEnd, attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
56  attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
57  break;
58  default:
59  break;
60  }
61 }
62 
63 
64 /****************************************************************************/
ODAmitranHandler::ODAmitranHandler
ODAmitranHandler(ODMatrix &matrix, const std::string &file)
Constructor.
Definition: ODAmitranHandler.cpp:32
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:42
SUMO_ATTR_ORIGIN
Definition: SUMOXMLDefinitions.h:891
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:493
SUMO_ATTR_AMOUNT
Definition: SUMOXMLDefinitions.h:890
MsgHandler.h
SUMO_ATTR_DESTINATION
Definition: SUMOXMLDefinitions.h:892
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
ODMatrix.h
ODAmitranHandler::~ODAmitranHandler
~ODAmitranHandler()
Destructor.
Definition: ODAmitranHandler.cpp:36
ODAmitranHandler::myEnd
SUMOTime myEnd
Definition: ODAmitranHandler.h:87
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:64
SUMO_TAG_OD_PAIR
Definition: SUMOXMLDefinitions.h:325
SUMO_TAG_TIMESLICE
Definition: SUMOXMLDefinitions.h:322
SUMO_TAG_ACTORCONFIG
Definition: SUMOXMLDefinitions.h:323
ODAmitranHandler::myBegin
SUMOTime myBegin
Definition: ODAmitranHandler.h:86
SUMO_ATTR_STARTTIME
Definition: SUMOXMLDefinitions.h:886
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:40
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SUMO_ATTR_DURATION
Definition: SUMOXMLDefinitions.h:665
config.h
ODAmitranHandler::myMatrix
ODMatrix & myMatrix
The matrix to add demand to.
Definition: ODAmitranHandler.h:82
ODAmitranHandler::myVehicleType
std::string myVehicleType
Definition: ODAmitranHandler.h:84
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245