Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file ODAmitranHandler.cpp
15 : /// @author Michael Behrisch
16 : /// @date 27.03.2014
17 : ///
18 : // An XML-Handler for Amitran OD matrices
19 : /****************************************************************************/
20 : #include <config.h>
21 :
22 : #include <utils/common/MsgHandler.h>
23 : #include "ODMatrix.h"
24 : #include "ODAmitranHandler.h"
25 :
26 :
27 : // ===========================================================================
28 : // method definitions
29 : // ===========================================================================
30 27 : ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
31 54 : : SUMOSAXHandler(file), myMatrix(matrix) {}
32 :
33 :
34 27 : ODAmitranHandler::~ODAmitranHandler() {}
35 :
36 :
37 : void
38 108 : ODAmitranHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
39 108 : bool ok = true;
40 108 : switch (element) {
41 27 : case SUMO_TAG_ACTORCONFIG:
42 27 : myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
43 27 : break;
44 27 : case SUMO_TAG_TIMESLICE:
45 27 : myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
46 27 : myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
47 27 : if (myBegin >= myEnd) {
48 2 : WRITE_ERRORF(TL("Invalid duration for timeSlice starting %."), toString(myBegin));
49 : }
50 : break;
51 27 : case SUMO_TAG_OD_PAIR:
52 27 : myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
53 54 : std::make_pair(myBegin, myEnd), attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
54 27 : attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
55 27 : break;
56 : default:
57 : break;
58 : }
59 108 : }
60 :
61 :
62 : /****************************************************************************/
|