changed verification method of enum conversions
This commit is contained in:
parent
81ee19819c
commit
b2d8558f1f
2 changed files with 22 additions and 33 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QMetaEnum>
|
||||
|
||||
/*!
|
||||
* \mainpage ScStw Libraries documentation
|
||||
|
@ -222,6 +223,15 @@ public:
|
|||
*/
|
||||
static int firmwareCompare(QString a, QString b);
|
||||
|
||||
/*!
|
||||
* \brief Function to convert a value to an enum
|
||||
*/
|
||||
template <typename Enum>
|
||||
static Enum toEnumValue(const int &value, bool *ok)
|
||||
{
|
||||
QMetaEnum enumeration = QMetaEnum::fromType<Enum>();
|
||||
return static_cast<Enum>(enumeration.keyToValue(enumeration.valueToKey(value), ok));
|
||||
}
|
||||
|
||||
ScStw() : QObject(nullptr) {};
|
||||
private:
|
||||
|
|
|
@ -27,51 +27,30 @@ QString ScStw::baseStationSettingToString(ScStw::BaseStationSetting s) {
|
|||
}
|
||||
|
||||
ScStw::BaseStationSetting ScStw::baseStationSettingfromInt(int i) {
|
||||
if(i < 0 || i > 4)
|
||||
bool ok;
|
||||
BaseStationSetting s = ScStw::toEnumValue<ScStw::BaseStationSetting>(i, &ok);
|
||||
if(!ok)
|
||||
return InvalidSetting;
|
||||
else
|
||||
return BaseStationSetting(i);
|
||||
return s;
|
||||
}
|
||||
|
||||
ScStw::SignalKey ScStw::signalKeyFromInt(int i) {
|
||||
if(i < 9000 || i > 9003)
|
||||
bool ok;
|
||||
ScStw::SignalKey k = ScStw::toEnumValue<ScStw::SignalKey>(i, &ok);
|
||||
if(!ok)
|
||||
return InvalidSignal;
|
||||
else
|
||||
return SignalKey(i);
|
||||
return k;
|
||||
}
|
||||
|
||||
ScStw::SocketCommand ScStw::socketCommandFromInt(int i) {
|
||||
QList<SocketCommand> allCommands = {
|
||||
InitializeSessionCommand,
|
||||
|
||||
StartTimersCommand,
|
||||
StopTimersCommand,
|
||||
ResetTimersCommand,
|
||||
|
||||
GetRaceStateCommand,
|
||||
GetNextStartActionCommand,
|
||||
GetExtensionsCommand,
|
||||
GetTimersCommand,
|
||||
GetNextStartActionDetailsCommand,
|
||||
|
||||
WriteSettingCommand,
|
||||
ReadSettingCommand,
|
||||
|
||||
LoginAthleteCommand,
|
||||
CreateAthleteCommand,
|
||||
DeleteAthleteCommand,
|
||||
GetAtheletesCommand,
|
||||
GetAthleteResultsCommand,
|
||||
|
||||
UpdateFirmwareCommand,
|
||||
UpdateSystemTimeCommand,
|
||||
PairExtensionsCommand
|
||||
};
|
||||
|
||||
if(!allCommands.contains(SocketCommand(i)))
|
||||
bool ok;
|
||||
SocketCommand c = ScStw::toEnumValue<ScStw::SocketCommand>(i, &ok);
|
||||
if(!ok)
|
||||
return InvalidCommand;
|
||||
else
|
||||
return SocketCommand(i);
|
||||
return c;
|
||||
}
|
||||
|
||||
int ScStw::firmwareCompare(QString a, QString b) {
|
||||
|
|
Reference in a new issue