NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
traintypes.h
Go to the documentation of this file.
1
6#ifndef carLocTypes_enum
7#define carLocTypes_enum
8
9#include <string>
10#include <stdexcept>
11#include "../util/vector.h"
12#include "../util/error.h"
13#include <map>
14
16namespace TrainTypes {
17
19 static const int carTypeN = 5;
20
21
23 enum class _CarType {
24 cargo,
29 };
30
33
35 static const Vector<CarType> carRechargableTechnologies = {
37 };
38
40 static const Vector<CarType> carNonRechargableTechnologies = {
44 };
45
47 static const std::string carTypeStrings[] = {
48 "Cargo Car",
49 "Diesel Tank",
50 "Battery Tender",
51 "Hydrogen Tender",
52 "Biodiesel Tank"
53 };
54
56 static const CarType carTypeArray[] = {
62 };
63
73 Vector<CarType> carTypeVector;
74 for (auto c : carTypeArray) {
75 carTypeVector.push_back(c);
76 }
77 return carTypeVector;
78 }
79
80
82 static const std::map<std::string, CarType> carTypeMap = {
83 {"Cargo Car", CarType::cargo},
84 {"Fuel Tank", CarType::dieselTender},
85 {"Battery Tender", CarType::batteryTender},
86 {"Hydrogen Tender", CarType::hydrogenTender},
87 {"Biodiesel Tender", CarType::biodieselTender}
88 };
89
100 inline std::string carTypeToStr(CarType type) {
101 return carTypeStrings[static_cast<int>(type)];
102 }
103
116 inline CarType strtoCarType(const std::string& cartype) {
117 auto it = carTypeMap.find(cartype);
118 if (it == carTypeMap.end()) {
119 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongCarType)) +
120 "\nInvalid car type");
121 }
122 return it->second;
123 }
124
137 inline CarType itoCarType(int cartype) {
138 if (cartype < 0 || cartype >= carTypeN) {
139 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongCarType)) +
140 "\nInvalid car type");
141 }
142 return carTypeArray[cartype];
143 }
144
156 inline std::ostream& operator<<(std::ostream& ss, const CarType& obj) {
157 ss << carTypeStrings[static_cast<int>(obj)];
158 return ss;
159 }
160
166 static const int powerTypeN = 7;
168 enum class _PowerType {
169 diesel,
170 electric,
171 biodiesel,
176 };
177
180
182 static const Vector<PowerType> locomotiveRechargableTechnologies = {
187 };
188
190 static const Vector<PowerType> locomotiveNonRechargableTechnologies = {
193 PowerType::dieselElectric // it does not have a battery to store energy in
194 };
195
197 static const Vector<PowerType> locomotiveTankOnly = {
200 PowerType::dieselElectric // it does not have a battery to store energy in
201 };
202
204 static const Vector<PowerType> locomotiveBatteryOnly = {
206 };
207
209 static const Vector<PowerType> locomotiveHybrid = {
214 };
215
217 static const std::string powerTypeStrings[] = {
218 "Diesel Locomotive",
219 "Electric Locomotive",
220 "Biodiesel Locomotive",
221 "Diesel-Electric Locomotive",
222 "Diesel-Hybrid Locomotive",
223 "Hydrogen-Hybrid Locomotive",
224 "Biodiesel-Hybrid Locomotive"
225 };
226
228 static const PowerType powerTypeArray[] = {
232 PowerType::dieselElectric, //3 // all locomotives now are diesel
236 };
237
239 static const std::map<std::string, PowerType> powerTypeMap = {
240 {"Diesel Locomotive", PowerType::diesel},
241 {"Electric Locomotive", PowerType::electric},
242 {"Biodiesel Locomotive", PowerType::biodiesel},
243 {"Diesel-Electric Locomotive", PowerType::dieselElectric},
244 {"Diesel-Hyprid Locomotive", PowerType::dieselHybrid},
245 {"Hydrogen-Hyprid Locomotive", PowerType::hydrogenHybrid},
246 {"biodiesel-Hyprid Locomotive", PowerType::biodieselHybrid}
247 };
248
250 static const std::map<PowerType, CarType> powerToCarMap = {
257 };
258
269 inline std::string PowerTypeToStr(PowerType type) {
270 return powerTypeStrings[static_cast<int>(type)];
271 }
272
285 inline PowerType strToPowerType(std::string powertype) {
286 auto it = powerTypeMap.find(powertype);
287 if (it == powerTypeMap.end()) {
288 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongLocoType)) +
289 "\nInvalid locomotive type");
290 }
291 return it->second;
292 }
293
306 inline PowerType iToPowerType(int powertype) {
307 if (powertype < 0 || powertype >= powerTypeN) {
308 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongLocoType)) +
309 "\nInvalid locomotive type");
310 }
311 return powerTypeArray[powertype];
312 }
313
325 inline std::ostream& operator<<(std::ostream& ss, const PowerType& obj) {
326 ss << powerTypeStrings[static_cast<int>(obj)];
327 return ss;
328 }
329
335 static const int powerMethodN = 2;
339 series,
341 };
342
346 static const std::string powerMethodsStrings[] = {
347 "Not Applicable"
348 "Series Hybrid Power",
349 "Parallel Hybrid Power"
350 };
352 static const LocomotivePowerMethod powerMethodArray[] = {
356 };
357
359 static const std::map<std::string, LocomotivePowerMethod> powerMethodMap = {
360 {"Series Hybrid Power", LocomotivePowerMethod::series},
361 {"Series Hybrid Power", LocomotivePowerMethod::series},
362 {"Parallel Hybrid Power", LocomotivePowerMethod::parallel}
363 };
364
365
378 inline LocomotivePowerMethod strToPowerMethod(std::string powertype) {
379 auto it = powerMethodMap.find(powertype);
380 if (it == powerMethodMap.end()) {
381 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongLocoType)) +
382 "\nInvalid locomotive type");
383 }
384 return it->second;
385 }
386
399 inline LocomotivePowerMethod iToPowerMethod(int powertype) {
400 if (powertype < 0 || powertype >= powerMethodN) {
401 throw std::invalid_argument("Error: " + std::to_string(static_cast<int>(Error::trainWrongLocoType)) +
402 "\nInvalid locomotive type");
403 }
404 return powerMethodArray[powertype];
405 }
406
418 inline std::ostream& operator<<(std::ostream& ss, const LocomotivePowerMethod& obj) {
419 ss << powerMethodsStrings[static_cast<int>(obj)];
420 return ss;
421 }
422
423
429 static const int fuelN = 4;
431 enum class _fuelTypes {
432 diesel,
433 biodiesel,
434 hydrogen,
435 noFuel
436 };
437
440
442 static const std::string fuelStrings[] = {
443 "Diesel Fuel",
444 "Biodiesel Fuel",
445 "Hydrogen-Hyprid Fuel",
446 "No Fuel"
447 };
448
450 static const FuelType fuelArray[] = {
455 };
456
458 static const std::map<std::string, FuelType> fuelMap = {
459 {"Diesel Fuel", FuelType::diesel},
460 {"Biodiesel Fuel", FuelType::biodiesel},
461 {"Hydrogen Fuel", FuelType::hydrogen},
462 {"No Fuel", FuelType::noFuel}
463 };
464
466 static const std::map<PowerType, FuelType> powerToFuelMap = {
473 };
474
476 static const std::map<CarType, FuelType> carToFuelMap = {
482 };
483
484 inline std::string fuelTypeToStr(FuelType type) {
485 return fuelStrings[static_cast<int>(type)];
486 }
487
489 auto it = powerToFuelMap.find(theType);
490 if (it != powerToFuelMap.end()) {
491 return it->second;
492 } else {
493 throw std::invalid_argument("Invalid PowerType");
494 }
495 }
496
497}
498
499#endif // !carLocTypes_enum
A vector.
Definition vector.h:24
@ trainWrongLocoType
@ trainWrongCarType
Definition traintypes.h:16
std::ostream & operator<<(std::ostream &ss, const CarType &obj)
Stream insertion operator.
Definition traintypes.h:156
_fuelTypes FuelType
Type of the fuel.
Definition traintypes.h:439
_LocomotivePowerMethod
Values that represent power types.
Definition traintypes.h:337
_LocomotivePowerMethod LocomotivePowerMethod
Type of the power.
Definition traintypes.h:344
LocomotivePowerMethod strToPowerMethod(std::string powertype)
Converts a string to a power method.
Definition traintypes.h:378
std::string PowerTypeToStr(PowerType type)
Power type to string.
Definition traintypes.h:269
std::string carTypeToStr(CarType type)
Car type to string.
Definition traintypes.h:100
_PowerType
Values that represent power types.
Definition traintypes.h:168
_CarType CarType
Type of the car.
Definition traintypes.h:32
CarType itoCarType(int cartype)
Ito car type.
Definition traintypes.h:137
_fuelTypes
Values that represent fuel types.
Definition traintypes.h:431
PowerType strToPowerType(std::string powertype)
Converts a powertype to a power type.
Definition traintypes.h:285
LocomotivePowerMethod iToPowerMethod(int powertype)
Converts a powertype to a power type.
Definition traintypes.h:399
FuelType getFuelTypeFromPowerType(PowerType theType)
Definition traintypes.h:488
Vector< CarType > getCarTypeVector()
Gets car type vector.
Definition traintypes.h:72
PowerType iToPowerType(int powertype)
Converts a powertype to a power type.
Definition traintypes.h:306
std::string fuelTypeToStr(FuelType type)
Definition traintypes.h:484
_PowerType PowerType
Type of the power.
Definition traintypes.h:179
_CarType
Values that represent car types.
Definition traintypes.h:23
CarType strtoCarType(const std::string &cartype)
Strto car type.
Definition traintypes.h:116