mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Ref T203, platform class (OS)
This commit is contained in:
158
src/blackmisc/platform.h
Normal file
158
src/blackmisc/platform.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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_PLATFORM_H
|
||||
#define BLACKMISC_PLATFORM_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/db/datastore.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMetaEnum>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* Platform (i.e. a platform swift supports)
|
||||
*/
|
||||
class BLACKMISC_EXPORT CPlatform : public CValueObject<CPlatform>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexPlatform = CPropertyIndex::GlobalIndexCPlatform
|
||||
};
|
||||
|
||||
//! OS
|
||||
enum PlatformFlag
|
||||
{
|
||||
UnknownOs = 0,
|
||||
Win32 = 1 << 0,
|
||||
Win64 = 1 << 1,
|
||||
Linux = 1 << 2,
|
||||
MacOS = 1 << 3,
|
||||
Independent = 1 << 4,
|
||||
AllWindows = Win32 | Win64,
|
||||
All = AllWindows | Linux | MacOS,
|
||||
All32 = Win32,
|
||||
All64 = Win64 | Linux | MacOS
|
||||
};
|
||||
Q_DECLARE_FLAGS(Platform, PlatformFlag)
|
||||
|
||||
//! Constructor
|
||||
CPlatform() {}
|
||||
|
||||
//! Constructor
|
||||
CPlatform(const QString &p);
|
||||
|
||||
//! Constructor
|
||||
CPlatform(Platform p);
|
||||
|
||||
//! Platform
|
||||
Platform getPlatform() const { return static_cast<Platform>(m_platform); }
|
||||
|
||||
//! Platform flag
|
||||
PlatformFlag getPlatformFlag() const;
|
||||
|
||||
//! Matches any other platform
|
||||
bool matchesAny(const CPlatform &otherPlatform) const;
|
||||
|
||||
//! Number of supported platforms
|
||||
int numberPlatforms() const;
|
||||
|
||||
//! Single platform?
|
||||
bool isSinglePlatform() const;
|
||||
|
||||
//! Any Windows
|
||||
bool isAnyWindows() const;
|
||||
|
||||
//! Name of platform
|
||||
QString getPlatformName() const;
|
||||
|
||||
//! Set platform
|
||||
void setPlatform(Platform p) { m_platform = p; }
|
||||
|
||||
//! Unknown?
|
||||
bool isUnknown() const { return m_platform == static_cast<int>(UnknownOs); }
|
||||
|
||||
//! Set platform
|
||||
void setPlatform(const QString &p) { setPlatform(stringToPlatform(p)); }
|
||||
|
||||
//! Representing icon
|
||||
CIcon toIcon() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const CPlatform &compareValue) const;
|
||||
|
||||
//! Convert to QString
|
||||
operator QString() { return this->toQString(); }
|
||||
|
||||
//! Convert to enum
|
||||
static Platform stringToPlatform(const QString &str);
|
||||
|
||||
//! Convert to enum
|
||||
const static CPlatform &stringToPlatformObject(const QString &str);
|
||||
|
||||
//! Current platform
|
||||
static const CPlatform ¤tPlatform();
|
||||
|
||||
//! Win32
|
||||
static const CPlatform &win32();
|
||||
|
||||
//! Win64
|
||||
static const CPlatform &win64();
|
||||
|
||||
//! Linux
|
||||
static const CPlatform &linux();
|
||||
|
||||
//! Mac OS
|
||||
static const CPlatform &macOS();
|
||||
|
||||
//! Unknown OS
|
||||
static const CPlatform &unknownOs();
|
||||
|
||||
//! All OS
|
||||
static const CPlatform &allOs();
|
||||
|
||||
//! Independent OS
|
||||
static const CPlatform &independent();
|
||||
|
||||
private:
|
||||
int m_platform = static_cast<int>(UnknownOs); //!< platform
|
||||
|
||||
BLACK_METACLASS(
|
||||
CPlatform,
|
||||
BLACK_METAMEMBER(platform)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CPlatform)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CPlatform::Platform)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CPlatform::PlatformFlag)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::CPlatform::Platform)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user