File indexing completed on 2024-12-01 11:20:28

0001 /***************************************************************************
0002  *   Copyright (C) 2006 David Saxton <david@bluehaze.org>                  *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  ***************************************************************************/
0009 
0010 #ifndef COMPONENTMODELLIBRARY_H
0011 #define COMPONENTMODELLIBRARY_H
0012 
0013 #include <QMap>
0014 #include <QObject>
0015 #include <QStringList>
0016 
0017 typedef QMap<QString, double> DoubleMap;
0018 
0019 class ComponentModel
0020 {
0021 public:
0022     ComponentModel();
0023     ~ComponentModel();
0024 
0025     /**
0026      * Sets the description.
0027      */
0028     void setDescription(const QString &description)
0029     {
0030         m_description = description;
0031     }
0032     /**
0033      * @return A short description.
0034      */
0035     QString description() const
0036     {
0037         return m_description;
0038     }
0039     /**
0040      * @return the value of the property with the given @p name . If the
0041      * property does not exist, then the value 0.0 is returned.
0042      */
0043     double property(const QString &name) const;
0044     /**
0045      * Set the property called @p name to have the value @p value .
0046      */
0047     void setProperty(const QString &name, double value);
0048 
0049 protected:
0050     QString m_name;
0051     QString m_description;
0052     DoubleMap m_property;
0053 };
0054 
0055 typedef QMultiHash<QString, ComponentModel> ComponentModelDict;
0056 
0057 /**
0058 @author David Saxton <david@bluehaze.org>
0059 */
0060 class ComponentModelLibrary : public QObject
0061 {
0062     Q_OBJECT
0063 public:
0064     enum ModelType { None, NPN, PNP };
0065     typedef QMap<ModelType, ComponentModelDict> ComponentModelDictMap;
0066     typedef QMap<ModelType, QStringList> ModelStringListMap;
0067 
0068     /**
0069      * @return The list of IDs for the given ModelType.
0070      * @see modelNames
0071      */
0072     QStringList modelIDs(ModelType modelType) const
0073     {
0074         return m_componentModelIDs[modelType];
0075     }
0076 
0077     static ComponentModelLibrary *self();
0078     ~ComponentModelLibrary() override;
0079 
0080 protected:
0081     /**
0082      * Reads in the component models from disk.
0083      */
0084     void loadModels();
0085 
0086     ComponentModelDictMap m_componentModels;
0087     ModelStringListMap m_componentModelIDs;
0088 
0089 private:
0090     ComponentModelLibrary();
0091     static ComponentModelLibrary *m_pSelf;
0092 };
0093 
0094 #endif