YASim: refactor Version.cpp
This commit is contained in:
parent
a9786c637c
commit
12bf5cdfa6
2 changed files with 35 additions and 21 deletions
|
@ -4,29 +4,40 @@
|
|||
|
||||
#include "Version.hpp"
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace yasim {
|
||||
|
||||
static const std::vector<std::string> VersionStrings = {
|
||||
"YASIM_VERSION_ORIGINAL",
|
||||
"YASIM_VERSION_32",
|
||||
"2017.2",
|
||||
"2018.1",
|
||||
"YASIM_VERSION_CURRENT",
|
||||
};
|
||||
|
||||
Version::YASIM_VERSION Version::getByName(const std::string& name)
|
||||
{
|
||||
auto it = std::find(VersionStrings.begin(), VersionStrings.end(), name);
|
||||
if (it == VersionStrings.end()) {
|
||||
SG_LOG(SG_FLIGHT,SG_ALERT,"Unknown yasim version '" << name << "' ignored, using YASIM_VERSION_ORIGINAL");
|
||||
return YASIM_VERSION_ORIGINAL;
|
||||
}
|
||||
YASIM_VERSION v = static_cast<YASIM_VERSION>(std::distance(VersionStrings.begin(), it));
|
||||
if (v > YASIM_VERSION_CURRENT) return YASIM_VERSION_CURRENT;
|
||||
else return v;
|
||||
}
|
||||
|
||||
std::string Version::getName(YASIM_VERSION v)
|
||||
{
|
||||
return VersionStrings.at(static_cast<int>(v));
|
||||
}
|
||||
|
||||
void Version::setVersion( const char * version )
|
||||
{
|
||||
const std::string v(version);
|
||||
|
||||
if( v == "YASIM_VERSION_ORIGINAL" ) {
|
||||
_version = YASIM_VERSION_ORIGINAL;
|
||||
} else if( v == "YASIM_VERSION_32" ) {
|
||||
_version = YASIM_VERSION_32;
|
||||
} else if( v == "2017.2" ) {
|
||||
_version = YASIM_VERSION_2017_2;
|
||||
} else if( v == "2018.1" ) {
|
||||
_version = YASIM_VERSION_2018_1;
|
||||
} else if( v == "YASIM_VERSION_CURRENT" ) {
|
||||
_version = YASIM_VERSION_CURRENT;
|
||||
} else {
|
||||
SG_LOG(SG_FLIGHT,SG_ALERT,"unknown yasim version '" << version << "' ignored, using YASIM_VERSION_ORIGINAL");
|
||||
return;
|
||||
}
|
||||
std::cout << "This aircraft uses yasim version '" << v << "'\n";
|
||||
const std::string v(version);
|
||||
_version = getByName(v);
|
||||
SG_LOG(SG_FLIGHT,SG_ALERT, "This aircraft uses yasim version '" << v << "' (" << _version << ")\n");
|
||||
}
|
||||
|
||||
} // namespace yasim
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _VERSION_HPP
|
||||
#define _VERSION_HPP
|
||||
|
||||
#include "yasim-common.hpp"
|
||||
|
||||
namespace yasim {
|
||||
|
||||
class Version {
|
||||
|
@ -8,19 +10,20 @@ public:
|
|||
Version() : _version(YASIM_VERSION_ORIGINAL) {}
|
||||
virtual ~Version() {}
|
||||
|
||||
typedef enum {
|
||||
enum YASIM_VERSION {
|
||||
YASIM_VERSION_ORIGINAL = 0,
|
||||
YASIM_VERSION_32,
|
||||
YASIM_VERSION_2017_2,
|
||||
YASIM_VERSION_2018_1,
|
||||
YASIM_VERSION_CURRENT = YASIM_VERSION_2018_1
|
||||
} YASIM_VERSION;
|
||||
} ;
|
||||
|
||||
void setVersion( const char * version );
|
||||
int getVersion() const { return _version; }
|
||||
bool isVersion( YASIM_VERSION version ) const;
|
||||
bool isVersionOrNewer( YASIM_VERSION version ) const;
|
||||
|
||||
static YASIM_VERSION getByName(const std::string& name);
|
||||
static std::string getName(YASIM_VERSION v);
|
||||
private:
|
||||
YASIM_VERSION _version;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue