Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/common/FileBucket.h
193874 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.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2025
17
///
18
// class used for link Elements with their filenames
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <string>
24
#include <vector>
25
26
// ===========================================================================
27
// class definitions
28
// ===========================================================================
29
30
class FileBucket {
31
32
public:
33
/// @brief Files that this bucket can save
34
enum class Type : int {
35
SUMO_CONFIG = 1 << 0, // Bucket for sumo configs (usually only one)
36
NETEDIT_CONFIG = 1 << 1, // Bucket for netedit configs (usually only one)
37
NETCONVERT_CONFIG = 1 << 2, // Bucket for netconvert configs (usually only one)
38
NETWORK = 1 << 3, // Bucket for network elements (usually only one)
39
EDGETYPE = 1 << 4, // Bucket for edge type (usually only one)
40
TLS = 1 << 5, // Bucket for traffic lights (usually only one)
41
DEMAND = 1 << 6, // Bucket for demand elements
42
MEANDATA = 1 << 7, // Bucket for meanData elements
43
ADDITIONAL = 1 << 8, // Bucket for additional elements (always after demand and meanData)
44
DATA = 1 << 9, // Bucket for data elements
45
// prefixes
46
NETEDIT_PREFIX = 1 << 10, // Bucket for netedit prefix
47
SUMO_PREFIX = 1 << 11, // Bucket for sumo prefix
48
NETCONVERT_PREFIX = 1 << 12, // Bucket for netconvert prefix
49
// other
50
NOTHING = 1 << 13, // Element is not saved in bucket
51
};
52
53
/// @brief Constructor for default bucket
54
FileBucket(FileBucket::Type type);
55
56
/// @brief Constructor
57
FileBucket(FileBucket::Type type, const std::string filename);
58
59
/// @brief destructor
60
~FileBucket();
61
62
/// @brief get file type
63
FileBucket::Type getType() const;
64
65
/// @brief get filename
66
const std::string& getFilename() const;
67
68
/// @brief set filename
69
void setFilename(const std::string& filename);
70
71
/// @brief check if this is a default bucket
72
bool isDefaultBucket() const;
73
74
/// @brief function related with Elements
75
/// @{
76
77
/// @brief add element in bucket
78
void addElement(const bool isTemplate);
79
80
/// @brief remove element
81
void removeElement(const bool isTemplate);
82
83
/// @brief add default vClass
84
void addDefaultVType();
85
86
/// @brief remove default vClass
87
void removeDefaultVType();
88
89
/// @brief check number of elements (no templates)
90
int getNumElements() const;
91
92
/// @brief check if this bucket is empty
93
bool isEmpty() const;
94
95
/// @}
96
97
/// @brief vector with all types managed in this get bucket handler
98
static const std::vector<FileBucket::Type> types;
99
100
/// @brief vector with all types and prefixes managed in this get bucket handler
101
static const std::vector<FileBucket::Type> prefixes;
102
103
private:
104
/// @brief type
105
const FileBucket::Type myFileType;
106
107
/// @brief filename
108
std::string myFilename;
109
110
/// @brief number of elements vinculated with this file bucket
111
int myNumElements = 0;
112
113
/// @brief number of templates vinculated with this file bucket
114
int myNumTemplates = 0;
115
116
/// @brief number of default vTypes vinculated with this file bucket
117
int myNumDefaultVTypes = 0;
118
119
/// @brief flag to indicate if this is a default bucket (it cannot be removed)
120
const bool myDefaultBucket;
121
122
/// @brief Invalidated default constructor.
123
FileBucket() = delete;
124
125
/// @brief Invalidated copy constructor.
126
FileBucket(const FileBucket&) = delete;
127
128
/// @brief Invalidated assignment operator
129
FileBucket& operator=(const FileBucket& src) = delete;
130
};
131
132
/// @brief override type bit operator
133
constexpr FileBucket::Type operator|(FileBucket::Type a, FileBucket::Type b) {
134
return static_cast<FileBucket::Type>(static_cast<int>(a) | static_cast<int>(b));
135
}
136
137
/// @brief override type bit operator
138
constexpr bool operator&(FileBucket::Type a, FileBucket::Type b) {
139
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
140
}
141
142