added some converter functions

This commit is contained in:
Dorian Zedler 2020-04-06 22:06:14 +02:00
parent b752bdeed2
commit a9e9e4fd0f
Signed by: dorian
GPG key ID: 989DE36109AFA354
2 changed files with 50 additions and 0 deletions

View file

@ -2,3 +2,40 @@
const char *ScStw::SOCKET_MESSAGE_START_KEY = "<message>"; const char *ScStw::SOCKET_MESSAGE_START_KEY = "<message>";
const char *ScStw::SOCKET_MESSAGE_END_KEY = "</message>"; const char *ScStw::SOCKET_MESSAGE_END_KEY = "</message>";
const QMap<QString, ScStw::BaseStationSetting> ScStw::baseStationSettings = {
{"ReadySoundEnable", ScStw::ReadySoundEnableSetting},
{"ReadySoundDelay", ScStw::ReadySoundDelaySetting},
{"AtYourMarksSoundEnable", ScStw::AtYourMarksSoundEnableSetting},
{"AtYourMarksSoundDelay", ScStw::AtYourMarksSoundDelaySetting},
{"SoundVolume", ScStw::SoundVolumeSetting}
};
ScStw::BaseStationSetting ScStw::baseStationSettingFromString(QString s) {
if(!ScStw::baseStationSettings.contains(s))
return ScStw::InvalidSetting;
return ScStw::baseStationSettings[s];
}
QString ScStw::baseStationSettingToString(ScStw::BaseStationSetting s) {
for(QString key: ScStw::baseStationSettings.keys()) {
if(ScStw::baseStationSettings[key] == s)
return key;
}
return "Invalid";
}
ScStw::BaseStationSetting ScStw::baseStationSettingfromInt(int i) {
if(i < 0 || i > 4)
return InvalidSetting;
else
return BaseStationSetting(i);
}
ScStw::SignalKey ScStw::signalKeyFromInt(int i) {
if(i < 9000 || i > 9003)
return InvalidSignal;
else
return SignalKey(i);
}

View file

@ -2,6 +2,7 @@
#define SCSTW_HPP #define SCSTW_HPP
#include <QObject> #include <QObject>
#include <QMap>
class ScStw : public QObject { class ScStw : public QObject {
Q_OBJECT Q_OBJECT
@ -14,6 +15,7 @@ public:
Q_ENUM(RaceState) Q_ENUM(RaceState)
enum SignalKey { enum SignalKey {
InvalidSignal = -1,
RaceStateChanged = 9000, RaceStateChanged = 9000,
TimersChanged = 9001, TimersChanged = 9001,
ExtensionsChanged = 9002, ExtensionsChanged = 9002,
@ -25,6 +27,7 @@ public:
Q_ENUM(NextStartAction) Q_ENUM(NextStartAction)
enum BaseStationSetting { enum BaseStationSetting {
InvalidSetting = -1,
ReadySoundEnableSetting, ReadySoundEnableSetting,
ReadySoundDelaySetting, ReadySoundDelaySetting,
AtYourMarksSoundEnableSetting, AtYourMarksSoundEnableSetting,
@ -46,6 +49,16 @@ public:
static const char* SOCKET_MESSAGE_START_KEY; static const char* SOCKET_MESSAGE_START_KEY;
static const char* SOCKET_MESSAGE_END_KEY; static const char* SOCKET_MESSAGE_END_KEY;
static const QMap<QString, ScStw::BaseStationSetting> baseStationSettings;
static BaseStationSetting baseStationSettingfromInt(int i);
static BaseStationSetting baseStationSettingFromString(QString s);
static QString baseStationSettingToString(BaseStationSetting s);
static SignalKey signalKeyFromInt(int i);
private: private:
ScStw() : QObject(nullptr) {}; ScStw() : QObject(nullptr) {};
}; };