File indexing completed on 2022-11-29 18:12:00

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Pino Toscano <toscano.pino@tiscali.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KALZIUMNUMERATIONTYPE_H
0008 #define KALZIUMNUMERATIONTYPE_H
0009 
0010 class KalziumNumerationType;
0011 
0012 #include <QByteArray>
0013 #include <QStringList>
0014 
0015 /**
0016  * Factory for KalziumNumerationType classes.
0017  *
0018  * @author Pino Toscano
0019  */
0020 class KalziumNumerationTypeFactory
0021 {
0022 public:
0023     /**
0024      * Get the instance of this factory.
0025      */
0026     static KalziumNumerationTypeFactory *instance();
0027 
0028     /**
0029      * Returns the KalziumNumerationType with the @p id specified.
0030      * It will gives 0 if none found.
0031      */
0032     KalziumNumerationType *build(int id) const;
0033     /**
0034      * Returns the KalziumNumerationType whose name is the @p id
0035      * specified.
0036      * It will gives 0 if none found.
0037      */
0038     KalziumNumerationType *build(const QByteArray &id) const;
0039 
0040     /**
0041      * Returns a list with the names of the numeration types we
0042      * support.
0043      */
0044     QStringList numerations() const;
0045 
0046 private:
0047     KalziumNumerationTypeFactory();
0048 
0049     QList<KalziumNumerationType *> m_numerations;
0050 };
0051 
0052 /**
0053  * Base class for a numeration type.
0054  * It's quite simple, as a numeration doesn't have many data to represent.
0055  *
0056  * @author Pino Toscano
0057  */
0058 class KalziumNumerationType
0059 {
0060 public:
0061     /**
0062      * Get its instance.
0063      */
0064     static KalziumNumerationType *instance();
0065 
0066     virtual ~KalziumNumerationType();
0067 
0068     /**
0069      * Returns the ID of this numeration type.
0070      * Mainly used when saving/loading.
0071      */
0072     virtual QByteArray name() const = 0;
0073     /**
0074      * Returns the description of this numeration type.
0075      * Used in all the visible places.
0076      */
0077     virtual QString description() const = 0;
0078 
0079     /**
0080      * Returns the @p num 'th item of this numeration type.
0081      */
0082     virtual QString item(const int num) const;
0083     /**
0084      * Returns all the items of this numeration type.
0085      */
0086     virtual QStringList items() const;
0087 
0088 protected:
0089     KalziumNumerationType();
0090 
0091     QStringList m_items;
0092 };
0093 
0094 /**
0095  * The class representing no numeration.
0096  * This could look a bit weird, but this way makes quite modular even disabling
0097  * the numeration.
0098  *
0099  * @author Pino Toscano
0100  */
0101 class KalziumNoneNumerationType : public KalziumNumerationType
0102 {
0103 public:
0104     static KalziumNoneNumerationType *instance();
0105 
0106     QByteArray name() const override;
0107     QString description() const override;
0108 
0109     QString item(const int num) const override;
0110     QStringList items() const override;
0111 
0112 private:
0113     KalziumNoneNumerationType();
0114 };
0115 
0116 /**
0117  * The numeration "International Union of Pure and Applied Chemistry" (IUPAC).
0118  *
0119  * @author Pino Toscano
0120  */
0121 class KalziumIUPACNumerationType : public KalziumNumerationType
0122 {
0123 public:
0124     static KalziumIUPACNumerationType *instance();
0125 
0126     QByteArray name() const override;
0127     QString description() const override;
0128 
0129 private:
0130     KalziumIUPACNumerationType();
0131 };
0132 
0133 /**
0134  * The numeration "Chemical Abstract Service" (CAS).
0135  *
0136  * @author Pino Toscano
0137  */
0138 class KalziumCASNumerationType : public KalziumNumerationType
0139 {
0140 public:
0141     static KalziumCASNumerationType *instance();
0142 
0143     QByteArray name() const override;
0144     QString description() const override;
0145 
0146 private:
0147     KalziumCASNumerationType();
0148 };
0149 
0150 /**
0151  * The old IUPAC numeration.
0152  *
0153  * @author Pino Toscano
0154  */
0155 class KalziumOldIUPACNumerationType : public KalziumNumerationType
0156 {
0157 public:
0158     static KalziumOldIUPACNumerationType *instance();
0159 
0160     QByteArray name() const override;
0161     QString description() const override;
0162 
0163 private:
0164     KalziumOldIUPACNumerationType();
0165 };
0166 
0167 #endif // KALZIUMNUMERATIONTYPE_H