Files
pilotclient/src/blackmisc/network/entityflags.h

118 lines
5.4 KiB
C++

/* Copyright (C) 2015
* 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_NETWORK_ENTITRFLAGS_H
#define BLACKMISC_NETWORK_ENTITRFLAGS_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/statusmessage.h"
#include <QFlags>
#include <QMetaType>
#include <QString>
namespace BlackMisc
{
namespace Network
{
/*!
* What and state of reading from web services
*/
class BLACKMISC_EXPORT CEntityFlags
{
public:
//! Which data to read, requires corresponding readers
enum EntityFlag
{
NoEntity = 0, //!< no data at all
DbInfoObjectEntity = 1 << 0, //!< info about DB data (kind of metadata)
SharedInfoObjectEntity = 1 << 1, //!< info about shared DB data (metadata)
AircraftIcaoEntity = 1 << 2, //!< ICAO codes for aircraft
AirlineIcaoEntity = 1 << 3, //!< ICAO codes for airlines
CountryEntity = 1 << 4, //!< country codes
DistributorEntity = 1 << 5, //!< distributors
LiveryEntity = 1 << 6, //!< liveries
ModelEntity = 1 << 7, //!< models
BookingEntity = 1 << 8, //!< bookings
MetarEntity = 1 << 9, //!< METAR
VatsimDataFile = 1 << 10, //!< the VATSIM data file (multiple data entities)
VatsimStatusFile = 1 << 11, //!< the VATSIM status file (URLs for data files etc.)
AirportEntity = 1 << 12, //!< airports
AllEntities = ((1 << 13) - 1), //!< everything
AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, //!< all ICAO codes
AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, //!< all ICAO codes and countries
DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, //!< Combinded
ModelMatchingEntities = AllIcaoEntities | LiveryEntity | ModelEntity, //!< all needed for model matching
AllDbEntities = AllIcaoAndCountries | DistributorLiveryModel | DbInfoObjectEntity | AirportEntity, //!< All DB stuff
AllDbEntitiesNoInfoObjects = AllIcaoAndCountries | DistributorLiveryModel | AirportEntity, //!< All DB entities, no info objects
AllDbEntitiesNoInfoObjectsNoAirports = AllIcaoAndCountries | DistributorLiveryModel //!< All DB entities, no info objects and airports
};
Q_DECLARE_FLAGS(Entity, EntityFlag)
//! State of operation
enum ReadState
{
StartRead, //!< reading has been started
ReadFinished, //!< reading done
ReadFinishedRestricted, //!< finished a timestamp restricted read
ReadFailed, //!< reading failed
ReadSkipped //!< read skipped, e.g. because network is down
};
//! Convert to string
static QString flagToString(EntityFlag flag);
//! Convert to string
static QString flagToString(BlackMisc::Network::CEntityFlags::Entity flag);
//! Representing single entity?
static bool isSingleEntity(BlackMisc::Network::CEntityFlags::Entity flag);
//! Represented number of entities
static int numberOfEntities(BlackMisc::Network::CEntityFlags::Entity flag);
//! Convert to string
static QString flagToString(ReadState flag);
//! Flag to severity
static BlackMisc::CStatusMessage::StatusSeverity flagToSeverity(ReadState state);
//! To flag
static EntityFlag entityToEntityFlag(Entity entity);
//! Return single entity and remove it from entities
static Entity iterateDbEntities(Entity &entities);
//! Read state representing warning or above?
static bool isWarningOrAbove(ReadState state);
//! Representing at least one DB entity
static bool anySwiftDbEntity(Entity entities);
//! Get by name
static Entity singleEntityByName(const QString &name);
//! As set of single entities
static QSet<Entity> asSingleEntities(Entity entities);
//! Register metadata
static void registerMetadata();
};
} // namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Network::CEntityFlags::EntityFlag)
Q_DECLARE_METATYPE(BlackMisc::Network::CEntityFlags::Entity)
Q_DECLARE_METATYPE(BlackMisc::Network::CEntityFlags::ReadState)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Network::CEntityFlags::Entity)
#endif // guard