Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/common/FileBucket.cpp
193905 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 FileBucket.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2025
17
///
18
// class used for link Elements with their filenames
19
/****************************************************************************/
20
21
#include "FileBucket.h"
22
#include "UtilExceptions.h"
23
24
// ===========================================================================
25
// static members
26
// ===========================================================================
27
28
const std::vector<FileBucket::Type> FileBucket::types = {
29
FileBucket::Type::SUMO_CONFIG,
30
FileBucket::Type::NETEDIT_CONFIG,
31
FileBucket::Type::NETCONVERT_CONFIG,
32
FileBucket::Type::NETWORK,
33
FileBucket::Type::EDGETYPE,
34
FileBucket::Type::TLS,
35
FileBucket::Type::DEMAND,
36
FileBucket::Type::MEANDATA,
37
FileBucket::Type::ADDITIONAL,
38
FileBucket::Type::DATA
39
};
40
41
const std::vector<FileBucket::Type> FileBucket::prefixes = {
42
FileBucket::Type::NETEDIT_PREFIX,
43
FileBucket::Type::SUMO_PREFIX,
44
FileBucket::Type::NETCONVERT_PREFIX,
45
};
46
47
// ===========================================================================
48
// member method definitions
49
// ===========================================================================
50
51
FileBucket::FileBucket(FileBucket::Type type) :
52
myFileType(type),
53
myDefaultBucket(true) {
54
}
55
56
57
FileBucket::FileBucket(FileBucket::Type type, const std::string filename) :
58
myFileType(type),
59
myFilename(filename),
60
myDefaultBucket(false) {
61
}
62
63
64
FileBucket::~FileBucket() {}
65
66
67
FileBucket::Type
68
FileBucket::getType() const {
69
return myFileType;
70
}
71
72
73
const std::string&
74
FileBucket::getFilename() const {
75
return myFilename;
76
}
77
78
79
void
80
FileBucket::setFilename(const std::string& filename) {
81
myFilename = filename;
82
}
83
84
85
bool
86
FileBucket::isDefaultBucket() const {
87
return myDefaultBucket;
88
}
89
90
91
void
92
FileBucket::addElement(const bool isTemplate) {
93
if (isTemplate) {
94
myNumTemplates++;
95
} else {
96
myNumElements++;
97
}
98
}
99
100
101
void
102
FileBucket::removeElement(const bool isTemplate) {
103
if (isTemplate) {
104
myNumTemplates--;
105
// check that number of elementes are not negative
106
if (myNumTemplates < 0) {
107
throw ProcessError("Number of element negative");
108
}
109
} else {
110
myNumElements--;
111
// check that number of elementes are not negative
112
if (myNumElements < 0) {
113
throw ProcessError("Number of templates negative");
114
}
115
}
116
}
117
118
119
void
120
FileBucket::addDefaultVType() {
121
myNumDefaultVTypes++;
122
}
123
124
125
void
126
FileBucket::removeDefaultVType() {
127
myNumDefaultVTypes--;
128
// check that number of elementes are not negative
129
if (myNumElements < 0) {
130
throw ProcessError("Number of defaultVTypes negative");
131
}
132
}
133
134
135
int
136
FileBucket::getNumElements() const {
137
return myNumElements;
138
}
139
140
141
bool
142
FileBucket::isEmpty() const {
143
return (myNumElements + myNumTemplates) == 0;
144
}
145
146
/****************************************************************************/
147
148