Line data Source code
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 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 0 : FileBucket::FileBucket(FileBucket::Type type) :
52 0 : myFileType(type),
53 0 : myDefaultBucket(true) {
54 0 : }
55 :
56 :
57 0 : FileBucket::FileBucket(FileBucket::Type type, const std::string filename) :
58 0 : myFileType(type),
59 0 : myFilename(filename),
60 0 : myDefaultBucket(false) {
61 0 : }
62 :
63 :
64 0 : FileBucket::~FileBucket() {}
65 :
66 :
67 : FileBucket::Type
68 0 : FileBucket::getType() const {
69 0 : return myFileType;
70 : }
71 :
72 :
73 : const std::string&
74 0 : FileBucket::getFilename() const {
75 0 : return myFilename;
76 : }
77 :
78 :
79 : void
80 0 : FileBucket::setFilename(const std::string& filename) {
81 0 : myFilename = filename;
82 0 : }
83 :
84 :
85 : bool
86 0 : FileBucket::isDefaultBucket() const {
87 0 : return myDefaultBucket;
88 : }
89 :
90 :
91 : void
92 0 : FileBucket::addElement(const bool isTemplate) {
93 0 : if (isTemplate) {
94 0 : myNumTemplates++;
95 : } else {
96 0 : myNumElements++;
97 : }
98 0 : }
99 :
100 :
101 : void
102 0 : FileBucket::removeElement(const bool isTemplate) {
103 0 : if (isTemplate) {
104 0 : myNumTemplates--;
105 : // check that number of elementes are not negative
106 0 : if (myNumTemplates < 0) {
107 0 : throw ProcessError("Number of element negative");
108 : }
109 : } else {
110 0 : myNumElements--;
111 : // check that number of elementes are not negative
112 0 : if (myNumElements < 0) {
113 0 : throw ProcessError("Number of templates negative");
114 : }
115 : }
116 0 : }
117 :
118 :
119 : void
120 0 : FileBucket::addDefaultVType() {
121 0 : myNumDefaultVTypes++;
122 0 : }
123 :
124 :
125 : void
126 0 : FileBucket::removeDefaultVType() {
127 0 : myNumDefaultVTypes--;
128 : // check that number of elementes are not negative
129 0 : if (myNumElements < 0) {
130 0 : throw ProcessError("Number of defaultVTypes negative");
131 : }
132 0 : }
133 :
134 :
135 : int
136 0 : FileBucket::getNumElements() const {
137 0 : return myNumElements;
138 : }
139 :
140 :
141 : bool
142 0 : FileBucket::isEmpty() const {
143 0 : return (myNumElements + myNumTemplates) == 0;
144 : }
145 :
146 : /****************************************************************************/
|