| 1 | /*************************************************************************** |
| 2 | hop.h |
| 3 | ------------------- |
| 4 | A hop class |
| 5 | ------------------- |
| 6 | Copyright 1999-2008, David Johnson |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions |
| 11 | are met: |
| 12 | |
| 13 | 1. Redistributions of source code must retain the above copyright |
| 14 | notice, this list of conditions and the following disclaimer. |
| 15 | |
| 16 | 2. Redistributions in binary form must reproduce the above copyright |
| 17 | notice, this list of conditions and the following disclaimer in the |
| 18 | documentation and/or other materials provided with the distribution. |
| 19 | |
| 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | ***************************************************************************/ |
| 32 | |
| 33 | #ifndef HOP_H |
| 34 | #define HOP_H |
| 35 | |
| 36 | #include <QList> |
| 37 | #include <QMap> |
| 38 | #include <QString> |
| 39 | |
| 40 | #include "quantity.h" |
| 41 | |
| 42 | class Hop { |
| 43 | public: |
| 44 | // hop strings |
| 45 | // TODO: make sure am comparing lowercase / handle lowercase, because old format uses it!!! |
| 46 | static const QByteArray PELLET_STRING; |
| 47 | static const QByteArray PLUG_STRING; |
| 48 | static const QByteArray WHOLE_STRING; |
| 49 | |
| 50 | // default constructor |
| 51 | Hop(); |
| 52 | // full constructor |
| 53 | Hop(const QString &name, const Weight &weight, |
| 54 | const QString &typ, const double &alpha, |
| 55 | const unsigned &time); |
| 56 | // copy constructor |
| 57 | Hop(const Hop &h); |
| 58 | // operators |
| 59 | Hop operator=(const Hop &h); |
| 60 | bool operator==(const Hop &h) const; |
| 61 | bool operator<(const Hop &h) const; |
| 62 | // destructor |
| 63 | ~Hop(); |
| 64 | |
| 65 | // get/set name |
| 66 | const QString &name() const; |
| 67 | void setName(const QString &name); |
| 68 | // get/set weight |
| 69 | const Weight &weight() const; |
| 70 | void setWeight(const Weight &weight); |
| 71 | // get/set alpha content |
| 72 | void setAlpha(double alpha); |
| 73 | double alpha() const; |
| 74 | //get/set boil time |
| 75 | unsigned time() const; |
| 76 | void setTime(unsigned time); |
| 77 | // get/set type |
| 78 | const QString &type() const; |
| 79 | void setType(const QString &typ); |
| 80 | |
| 81 | // return precalculated value for bitterness |
| 82 | double HBU(); |
| 83 | |
| 84 | // return hop type |
| 85 | static QStringList typeStringList(); |
| 86 | |
| 87 | private: |
| 88 | // recalc values |
| 89 | void recalc(); |
| 90 | |
| 91 | private: |
| 92 | QString name_; |
| 93 | Weight weight_; |
| 94 | QString type_; |
| 95 | double alpha_; |
| 96 | unsigned time_; |
| 97 | double hbu_; |
| 98 | }; |
| 99 | |
| 100 | typedef QList<Hop> HopList; |
| 101 | typedef QMap<QString,Hop> HopMap; |
| 102 | |
| 103 | ////////////////////////////////////////////////////////////////////////////// |
| 104 | // Inlined Operators |
| 105 | |
| 106 | inline bool Hop::operator<(const Hop &h) const |
| 107 | { return (name_ < h.name_); } |
| 108 | |
| 109 | inline void Hop::setName(const QString &name) |
| 110 | { name_ = name; } |
| 111 | |
| 112 | inline const QString &Hop::name() const |
| 113 | { return name_; } |
| 114 | |
| 115 | inline void Hop::setWeight(const Weight &weight) |
| 116 | { weight_ = weight; recalc(); } |
| 117 | |
| 118 | inline const Weight &Hop::weight() const |
| 119 | { return weight_; } |
| 120 | |
| 121 | inline void Hop::setType(const QString &typ) |
| 122 | { type_ = typ; } |
| 123 | |
| 124 | inline const QString &Hop::type() const |
| 125 | { return type_; } |
| 126 | |
| 127 | inline void Hop::setAlpha(double alpha) |
| 128 | { alpha_ = alpha; recalc(); } |
| 129 | |
| 130 | inline double Hop::alpha() const |
| 131 | { return alpha_; } |
| 132 | |
| 133 | inline void Hop::setTime(unsigned time) |
| 134 | { time_ = time; } |
| 135 | |
| 136 | inline unsigned Hop::time() const |
| 137 | { return time_; } |
| 138 | |
| 139 | inline double Hop::HBU() |
| 140 | { return hbu_; } |
| 141 | |
| 142 | #endif // HOP_H |