File indexing completed on 2024-05-05 16:49:20

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
0003  * SPDX-FileCopyrightText: 2021 Anjani Kumar <anjanik012@gmail.com>
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #pragma once
0007 #include "kweathercore/kweathercore_export.h"
0008 #include <QDateTime>
0009 #include <QObject>
0010 #include <QString>
0011 #include <memory>
0012 #include <tuple>
0013 #include <vector>
0014 namespace KWeatherCore
0015 {
0016 // code name (FIPS6, UGC...)/code value (002050, AKZ155)
0017 using AreaCodeVec = std::vector<std::pair<QString, QString>>;
0018 using Parameter = std::vector<std::pair<QString, QString>>;
0019 /**
0020  * @short Class represents single CAP
0021  *
0022  * This class contains the parsed CAP FEED entry
0023  *
0024  * @author Han Young <hanyoung@protonmail.com>
0025  * @author Anjani Kumar <anjanik012@gmail.com>
0026  */
0027 class KWEATHERCORE_EXPORT AlertInfo
0028 {
0029     Q_GADGET
0030     Q_PROPERTY(QString headline READ headline WRITE setHeadline)
0031     Q_PROPERTY(QString description READ description WRITE setDescription)
0032     Q_PROPERTY(QString event READ event WRITE setEvent)
0033     Q_PROPERTY(
0034         QDateTime effectiveTime READ effectiveTime WRITE setEffectiveTime)
0035     Q_PROPERTY(QDateTime expireTime READ expireTime WRITE setExpireTime)
0036 
0037 public:
0038     enum class Category {
0039         Unknown = 0,
0040         Geo = 0b1,
0041         Met = 0b10,
0042         Safety = 0b100,
0043         Security = 0b1000,
0044         Rescue = 0b10000,
0045         Fire = 0b100000,
0046         Health = 0b1000000,
0047         Env = 0b10000000,
0048         Transport = 0b100000000,
0049         Infra = 0b1000000000,
0050         CBRNE = 0b10000000000,
0051         Other = 0b100000000000
0052     };
0053     enum class Urgency { Immediate, Expected, Future, Past, Unknown };
0054     enum class Severity { Extreme, Severe, Moderate, Minor, Unknown };
0055     enum class Certainty { Observed, Likely, Possible, Unlikely, Unknown };
0056 
0057     /**
0058      * default constructor
0059      */
0060     AlertInfo();
0061     AlertInfo(const AlertInfo &other);
0062     AlertInfo(AlertInfo &&other);
0063     ~AlertInfo();
0064     /**
0065      * The text denoting the type of the subject
0066      * event of the alert message
0067      */
0068     const QString &event() const;
0069     /**
0070      * areaCodes
0071      * @return pairs of QString, the first one is code type,
0072      * ie. {"UGC", "AKZ017 AKZ020 AKZ021 AKZ022 AKZ023"}
0073      */
0074     const AreaCodeVec &areaCodes() const;
0075     /**
0076      * The effective time of the information of the alert message
0077      */
0078     const QDateTime &effectiveTime() const;
0079     /**
0080      * The onset time of the information of the alert message
0081      */
0082     const QDateTime &onsetTime() const;
0083     /**
0084      * The expire time of the information of the alert message
0085      */
0086     const QDateTime &expireTime() const;
0087     /**
0088      * The text headline of the alert message
0089      */
0090     const QString &headline() const;
0091     /**
0092      * The description of the alert message
0093      */
0094     const QString &description() const;
0095     /**
0096      * The instruction of the alert message
0097      */
0098     const QString &instruction() const;
0099     /**
0100      * The sender of the alert message
0101      */
0102     const QString &sender() const;
0103     /**
0104      * The code denoting the language of the info
0105      * default to "en-US"
0106      * @return Natural language identifier per [RFC 3066].
0107      */
0108     const QString &language() const;
0109     /**
0110      * The category of the alert message
0111      * @return default to Unknown, value is bit or-ed
0112      */
0113     Category category() const;
0114     /**
0115      * The urgency of the alert message
0116      * @return default to Unknown
0117      */
0118     Urgency urgency() const;
0119     /**
0120      * The severity of the alert message
0121      * @return default to Unknown
0122      */
0123     Severity severity() const;
0124     /**
0125      * The certainty of the alert message
0126      * @return default to Unknown
0127      */
0128     Certainty certainty() const;
0129     /**
0130      * The Parameter of the alert message
0131      * refer to CAP protocol v1.2
0132      */
0133     const Parameter &parameter() const;
0134     /**
0135      * Text describe the area of the alert message
0136      */
0137     const QString &areaDesc() const;
0138     /**
0139      * area polygon
0140      * @return latitude longitude pairs
0141      */
0142     const std::vector<std::vector<std::pair<float, float>>> &polygon() const;
0143     void setHeadline(const QString &headline);
0144     void setDescription(const QString &description);
0145     void setInstruction(const QString &instruction);
0146     void setSender(const QString &sender);
0147     void setLanguage(const QString &language);
0148     void setCategory(Category category);
0149     void addCategory(Category category);
0150     void setEvent(const QString &event);
0151     void setAreaCodes(const AreaCodeVec &areaCodes);
0152     void addAreaCode(std::pair<QString, QString> &areaCode);
0153     void setEffectiveTime(const QDateTime &time);
0154     void setOnsetTime(const QDateTime &time);
0155     void setExpireTime(const QDateTime &time);
0156     void setUrgency(Urgency urgency);
0157     void setSeverity(Severity severity);
0158     void setCertainty(Certainty certainty);
0159     void setParameter(const Parameter &parameter);
0160     void addParameter(std::pair<QString, QString> &);
0161     void setAreaDesc(const QString &areaDesc);
0162     void setPolygon(const std::vector<std::vector<std::pair<float, float>>> &area);
0163     void setPolygon(std::vector<std::vector<std::pair<float, float>>> &&area);
0164     void addPolygon(const std::vector<std::pair<float, float>> &area);
0165     void addPolygon(std::vector<std::pair<float, float>> &&area);
0166     AlertInfo &operator=(const AlertInfo &other);
0167     AlertInfo &operator=(AlertInfo &&other);
0168 
0169 private:
0170     class AlertInfoPrivate;
0171     std::unique_ptr<AlertInfoPrivate> d;
0172 };
0173 using Category = KWeatherCore::AlertInfo::Category;
0174 inline Category operator|(Category a, Category b)
0175 {
0176     return static_cast<Category>(static_cast<int>(a) | static_cast<int>(b));
0177 }
0178 
0179 inline Category operator&(Category a, Category b)
0180 {
0181     return static_cast<Category>(static_cast<int>(a) & static_cast<int>(b));
0182 }
0183 
0184 inline Category& operator|=(Category& a, Category b)
0185 {
0186     return a = a | b;
0187 }
0188 }