Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/od/ODAmitranHandler.cpp
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
31
: SUMOSAXHandler(file), myMatrix(matrix) {}
32
33
34
ODAmitranHandler::~ODAmitranHandler() {}
35
36
37
void
38
ODAmitranHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
39
bool ok = true;
40
switch (element) {
41
case SUMO_TAG_ACTORCONFIG:
42
myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
43
break;
44
case SUMO_TAG_TIMESLICE:
45
myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
46
myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
47
if (myBegin >= myEnd) {
48
WRITE_ERRORF(TL("Invalid duration for timeSlice starting %."), toString(myBegin));
49
}
50
break;
51
case SUMO_TAG_OD_PAIR:
52
myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
53
std::make_pair(myBegin, myEnd), attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
54
attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
55
break;
56
default:
57
break;
58
}
59
}
60
61
62
/****************************************************************************/
63
64