From 03e16e37e7ead47bacc8e4ac8e9b410669238893 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 12 Jul 2015 17:27:18 +0200 Subject: [PATCH] refs #445, simulator info for database operations --- .../blackmiscfreefunctions_simmeta.cpp | 2 + src/blackmisc/simulation/simulatorinfo.cpp | 73 ++++++++++++++++ src/blackmisc/simulation/simulatorinfo.h | 86 +++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 src/blackmisc/simulation/simulatorinfo.cpp create mode 100644 src/blackmisc/simulation/simulatorinfo.h diff --git a/src/blackmisc/blackmiscfreefunctions_simmeta.cpp b/src/blackmisc/blackmiscfreefunctions_simmeta.cpp index 6824bc0d1..988b25670 100644 --- a/src/blackmisc/blackmiscfreefunctions_simmeta.cpp +++ b/src/blackmisc/blackmiscfreefunctions_simmeta.cpp @@ -13,6 +13,7 @@ #include "blackmisc/simulation/airspaceaircraftsnapshot.h" #include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/simulatorsetup.h" +#include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" #include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h" #include "blackmisc/simulation/fscommon/vpilotmodelruleset.h" @@ -43,5 +44,6 @@ void BlackMisc::Simulation::registerMetadata() CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); CSimulatorSetup::registerMetadata(); + CSimulatorInfo::registerMetadata(); CAirspaceAircraftSnapshot::registerMetadata(); } diff --git a/src/blackmisc/simulation/simulatorinfo.cpp b/src/blackmisc/simulation/simulatorinfo.cpp new file mode 100644 index 000000000..c130aafb5 --- /dev/null +++ b/src/blackmisc/simulation/simulatorinfo.cpp @@ -0,0 +1,73 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "simulatorinfo.h" + +using namespace BlackMisc; + +namespace BlackMisc +{ + namespace Simulation + { + CSimulatorInfo::CSimulatorInfo() + { } + + CSimulatorInfo::CSimulatorInfo(Simulator s) : m_simulator(static_cast(s)) + { } + + CSimulatorInfo::CSimulatorInfo(bool fsx, bool fs9, bool xp) : + m_simulator(boolToFlag(fsx, fs9, xp)) + { } + + bool CSimulatorInfo::isUnspecified() const + { + return m_simulator < 1; + } + + QString CSimulatorInfo::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + Simulator s = getSimulator(); + QString str; + if (s.testFlag(FSX)) { str.append("FSX "); } + if (s.testFlag(FS9)) { str.append("FS9 "); } + if (s.testFlag(XP)) { str.append("XPlane "); } + return str.trimmed(); + } + + CSimulatorInfo::Simulator CSimulatorInfo::boolToFlag(bool fsx, bool fs9, bool xp) + { + Simulator s = fsx ? FSX : None; + if (fs9) { s |= FS9; } + if (xp) { s |= XP; } + return s; + } + + CSimulatorInfo::Simulator CSimulatorInfo::identifierToFlag(const QString &identifier) + { + QString i(identifier.toLower().trimmed()); + if (i.isEmpty()) { return None; } + + Simulator s = None; + if (i.contains("fsx")) + { + s |= FSX; + } + if (i.contains("fs9")) + { + s |= FS9; + } + if (i.contains("xplane") || i.contains("xp")) + { + s |= XP; + } + return s; + } + } // ns +} // ns diff --git a/src/blackmisc/simulation/simulatorinfo.h b/src/blackmisc/simulation/simulatorinfo.h new file mode 100644 index 000000000..2ba995a56 --- /dev/null +++ b/src/blackmisc/simulation/simulatorinfo.h @@ -0,0 +1,86 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_SIMULATORINFO_H +#define BLACKMISC_SIMULATION_SIMULATORINFO_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/valueobject.h" + +namespace BlackMisc +{ + namespace Simulation + { + //! Simple hardcoded info about the corresponding simulator. + //! * in an ideal world this class would not exist, all would depend on flexible plugins \sa CSimulatorPluginInfo + //! * in a real world the info is needed in a couple of places to specify the simulator + //! ** when data from the swift data store a read, the corresponding simulator is specified + //! ** when model metadata are written to the swift data store the DB simulator info needs to be provided + //! ** when models are indexed from disk it does not know the corresponding driver + //! ** also there is no strict dependency of some functions to the driver. I might not have the XP plugin installed, + //! but need to handle XP data from the swift data store + //! If someone manages to remove this hardocded simulator information and makes it entirely flexible + //! based upon the plugin metadata feel free. + class BLACKMISC_EXPORT CSimulatorInfo : public BlackMisc::CValueObject + { + public: + + //! Simulator + enum SimulatorFlags + { + None = 0, + FSX = 1 << 0, + FS9 = 1 << 1, + XP = 1 << 2 + }; + Q_DECLARE_FLAGS(Simulator, SimulatorFlags) + + //! Default constructor + CSimulatorInfo(); + + //! Constructor + CSimulatorInfo(Simulator s); + + //! Constructor + CSimulatorInfo(bool fsx, bool fs9, bool xp); + + //! Unspecified simulator + bool isUnspecified() const; + + //! Simulator + Simulator getSimulator() const { return static_cast(m_simulator); } + + //! Simulator + void setSimulator(Simulator s) { m_simulator = static_cast(s); } + + //! \copydoc CValueObject::convertToQString + QString convertToQString(bool i18n = false) const; + + //! Bool flags to enum + static Simulator boolToFlag(bool fsx, bool fs9, bool xp); + + //! Identifer, as provided by plugin + static Simulator identifierToFlag(const QString &identifier); + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorInfo) + int m_simulator = static_cast(None); + }; + } // ns +} // ns + +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Simulation::CSimulatorInfo, ( + attr(o.m_simulator) + )) +Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorInfo) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CSimulatorInfo::Simulator) + +#endif // guard