FlightGear next
Version.cpp
Go to the documentation of this file.
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <algorithm>
6#include <ostream>
7#include <string>
8#include <type_traits>
9#include <vector>
10
11#include <simgear/debug/logstream.hxx>
12
13#include "Version.hpp"
14
15namespace yasim {
16
17static const std::vector<std::string> VersionStrings = {
18 "YASIM_VERSION_ORIGINAL",
19 "YASIM_VERSION_32",
20 "2017.2",
21 "2018.1",
22 "YASIM_VERSION_CURRENT",
23};
24
25YASIM_VERSION Version::getByName(const std::string& name)
26{
27 auto it = std::find(VersionStrings.begin(), VersionStrings.end(), name);
28 if (it == VersionStrings.end()) {
29 SG_LOG(SG_FLIGHT,SG_ALERT,"Unknown yasim version '" << name << "' ignored, using YASIM_VERSION_ORIGINAL");
30 return YASIM_VERSION::ORIGINAL;
31 }
32 YASIM_VERSION v = static_cast<YASIM_VERSION>(std::distance(VersionStrings.begin(), it));
33 if (v > YASIM_VERSION::CURRENT) return YASIM_VERSION::CURRENT;
34 else return v;
35}
36
37std::string Version::getName(YASIM_VERSION v)
38{
39 return VersionStrings.at(static_cast<int>(v));
40}
41
42void Version::setVersion( const char * version )
43{
44 const std::string v(version);
45 _version = getByName(v);
46 SG_LOG(SG_FLIGHT,SG_ALERT, "This aircraft uses yasim version '" << v << "' (" << _version << ")\n");
47}
48
49Version::versionUnderlyingType Version::getVersion() const
50{
51 return static_cast<versionUnderlyingType>(_version);
52}
53
54std::ostream& operator<<(std::ostream& os, const YASIM_VERSION& version)
55{
56 using underlying = std::underlying_type<YASIM_VERSION>::type;
57 return os << static_cast<underlying>(version);
58}
59
60} // namespace yasim
const char * name
std::ostream & operator<<(std::ostream &out, Rotor &r)
Definition Rotor.cpp:1352
static const std::vector< std::string > VersionStrings
Definition Version.cpp:17