| 1 | /*************************************************************************** |
| 2 | data.h |
| 3 | ------------------- |
| 4 | Brewing data |
| 5 | ------------------- |
| 6 | Copyright 2001-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 are met: |
| 11 | |
| 12 | 1. Redistributions of source code must retain the above copyright notice, |
| 13 | this list of conditions and the following disclaimer. |
| 14 | |
| 15 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 16 | this list of conditions and the following disclaimer in the documentation |
| 17 | and/or other materials provided with the distribution. |
| 18 | |
| 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' |
| 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | POSSIBILITY OF SUCH DAMAGE. |
| 30 | ***************************************************************************/ |
| 31 | |
| 32 | #ifndef DATA_H |
| 33 | #define DATA_H |
| 34 | |
| 35 | #include <QList> |
| 36 | #include <QString> |
| 37 | |
| 38 | #include "configstate.h" |
| 39 | #include "grain.h" |
| 40 | #include "hop.h" |
| 41 | #include "misc.h" |
| 42 | #include "style.h" |
| 43 | |
| 44 | class QDomElement; |
| 45 | |
| 46 | struct UEntry { |
| 47 | // hop utilization table entry structure |
| 48 | unsigned time; |
| 49 | unsigned utilization; |
| 50 | }; |
| 51 | |
| 52 | class Data { |
| 53 | public: |
| 54 | friend class DatabaseTool; |
| 55 | |
| 56 | ~Data(); |
| 57 | static Data *instance(); |
| 58 | void initialize(const ConfigState &state); |
| 59 | |
| 60 | // load the data |
| 61 | bool loadData(const QString &filename, bool quiet=false); |
| 62 | // save the data |
| 63 | bool saveData(const QString &filename); |
| 64 | |
| 65 | // get/set the default size volume |
| 66 | const Volume &defaultSize() const; |
| 67 | void setDefaultSize(const Volume &v); |
| 68 | // get/set the default style |
| 69 | const Style &defaultStyle() const; |
| 70 | void setDefaultStyle(const QString &s); |
| 71 | void setDefaultStyle(const Style &s); |
| 72 | // get/set default hop type |
| 73 | const QString &defaultHopType() const; |
| 74 | void setDefaultHopType(const QString &t); |
| 75 | // get/set the default grain units |
| 76 | const Unit &defaultGrainUnit() const; |
| 77 | void setDefaultGrainUnit(Unit &u); |
| 78 | // get/set the default hop units |
| 79 | const Unit &defaultHopUnit() const; |
| 80 | void setDefaultHopUnit(Unit &u); |
| 81 | // get/set the default misc units |
| 82 | const Unit &defaultMiscUnit() const; |
| 83 | void setDefaultMiscUnit(Unit &u); |
| 84 | // get/set the default temperature unit |
| 85 | const Unit &defaultTempUnit() const; |
| 86 | void setDefaultTempUnit(Unit &u); |
| 87 | |
| 88 | // return stringlists of data |
| 89 | QStringList stylesList(); |
| 90 | QStringList grainsList(); |
| 91 | QStringList hopsList(); |
| 92 | QStringList miscList(); |
| 93 | |
| 94 | // return given data |
| 95 | Style style(const QString &name); |
| 96 | Grain grain(const QString &name); |
| 97 | Hop hop(const QString &name); |
| 98 | Misc misc(const QString &name); |
| 99 | |
| 100 | // does data exist |
| 101 | bool hasStyle(const QString &name); |
| 102 | bool hasGrain(const QString &name); |
| 103 | bool hasHop(const QString &name); |
| 104 | bool hasMisc(const QString &name); |
| 105 | |
| 106 | // insert data |
| 107 | void insertStyle(const Style &style); |
| 108 | void insertGrain(const Grain &grain); |
| 109 | void insertHop(const Hop &hop); |
| 110 | void insertMisc(const Misc &misc); |
| 111 | |
| 112 | // clear data |
| 113 | void clearStyles(); |
| 114 | void clearGrains(); |
| 115 | void clearHops(); |
| 116 | void clearMiscs(); |
| 117 | |
| 118 | // get utilization based on time |
| 119 | double utilization(unsigned time); |
| 120 | // add entry to utilization table |
| 121 | void addUEntry(const UEntry &entry); |
| 122 | // efficiency |
| 123 | double efficiency(); |
| 124 | void setEfficiency(double e); |
| 125 | // steep yield |
| 126 | double steepYield(); |
| 127 | void setSteepYield(double y); |
| 128 | // set ibu calc method |
| 129 | bool tinseth(); |
| 130 | void setTinseth(bool tinseth); |
| 131 | // set srm calc method |
| 132 | bool morey(); |
| 133 | void setMorey(bool morey); |
| 134 | |
| 135 | private: |
| 136 | Data(); |
| 137 | Data(const Data&); |
| 138 | Data &operator=(const Data&); |
| 139 | |
| 140 | private: |
| 141 | friend class DataReader; |
| 142 | friend class DataWriter; |
| 143 | static Data *instance_; |
| 144 | |
| 145 | Volume defaultsize_; |
| 146 | Style defaultstyle_; |
| 147 | QString defaulthoptype_; |
| 148 | Unit *defaultgrainunit_; |
| 149 | Unit *defaulthopunit_; |
| 150 | Unit *defaultmiscunit_; |
| 151 | Unit *defaulttempunit_; |
| 152 | |
| 153 | GrainMap grainmap_; |
| 154 | HopMap hopmap_; |
| 155 | MiscMap miscmap_; |
| 156 | StyleMap stylemap_; |
| 157 | |
| 158 | QList<UEntry> utable_; |
| 159 | double steepyield_; |
| 160 | double efficiency_; |
| 161 | bool tinseth_; |
| 162 | bool morey_; |
| 163 | }; |
| 164 | |
| 165 | // Inlined Methods /////////////////////////////////////////////////////////// |
| 166 | |
| 167 | inline const QString &Data::defaultHopType() const { return defaulthoptype_; } |
| 168 | |
| 169 | inline void Data::setDefaultHopType(const QString &t) { defaulthoptype_ = t; } |
| 170 | |
| 171 | inline const Volume &Data::defaultSize() const { return defaultsize_; } |
| 172 | |
| 173 | inline void Data::setDefaultSize(const Volume &v) { defaultsize_ = v; } |
| 174 | |
| 175 | inline const Style &Data::defaultStyle() const { return defaultstyle_; } |
| 176 | |
| 177 | inline void Data::setDefaultStyle(const Style &s) { defaultstyle_ = s; } |
| 178 | |
| 179 | inline const Unit &Data::defaultGrainUnit() const { return *defaultgrainunit_; } |
| 180 | |
| 181 | inline void Data::setDefaultGrainUnit(Unit &u) { defaultgrainunit_ = &u; } |
| 182 | |
| 183 | inline const Unit &Data::defaultHopUnit() const { return *defaulthopunit_; } |
| 184 | |
| 185 | inline void Data::setDefaultHopUnit(Unit &u) { defaulthopunit_ = &u; } |
| 186 | |
| 187 | inline const Unit &Data::defaultMiscUnit() const { return *defaultmiscunit_; } |
| 188 | |
| 189 | inline void Data::setDefaultMiscUnit(Unit &u) { defaultmiscunit_ = &u; } |
| 190 | |
| 191 | inline const Unit &Data::defaultTempUnit() const { return *defaulttempunit_; } |
| 192 | |
| 193 | inline void Data::setDefaultTempUnit(Unit &u) { defaulttempunit_ = &u; } |
| 194 | |
| 195 | inline QStringList Data::stylesList() { return stylemap_.keys(); } |
| 196 | |
| 197 | inline QStringList Data::grainsList() { return grainmap_.keys(); } |
| 198 | |
| 199 | inline QStringList Data::hopsList() { return hopmap_.keys(); } |
| 200 | |
| 201 | inline QStringList Data::miscList() { return miscmap_.keys(); } |
| 202 | |
| 203 | inline bool Data::hasStyle(const QString &name) { return stylemap_.contains(name); } |
| 204 | |
| 205 | inline bool Data::hasGrain(const QString &name) { return grainmap_.contains(name); } |
| 206 | |
| 207 | inline bool Data::hasHop(const QString &name) { return hopmap_.contains(name); } |
| 208 | |
| 209 | inline bool Data::hasMisc(const QString &name) { return miscmap_.contains(name); } |
| 210 | |
| 211 | inline void Data::insertStyle(const Style &style) |
| 212 | { stylemap_.insert(style.name(), style); } |
| 213 | |
| 214 | inline void Data::insertGrain(const Grain &grain) |
| 215 | { grainmap_.insert(grain.name(), grain); } |
| 216 | |
| 217 | inline void Data::insertHop(const Hop &hop) |
| 218 | { hopmap_.insert(hop.name(), hop); } |
| 219 | |
| 220 | inline void Data::insertMisc(const Misc &misc) |
| 221 | { miscmap_.insert(misc.name(), misc); } |
| 222 | |
| 223 | inline void Data::clearStyles() { stylemap_.clear(); } |
| 224 | |
| 225 | inline void Data::clearGrains() { grainmap_.clear(); } |
| 226 | |
| 227 | inline void Data::clearHops() { hopmap_.clear(); } |
| 228 | |
| 229 | inline void Data::clearMiscs() { miscmap_.clear(); } |
| 230 | |
| 231 | inline double Data::efficiency() { return efficiency_; } |
| 232 | |
| 233 | inline void Data::setEfficiency(double e) { efficiency_ = e; } |
| 234 | |
| 235 | inline double Data::steepYield() { return steepyield_; } |
| 236 | |
| 237 | inline void Data::setSteepYield(double y) { steepyield_ = y; } |
| 238 | |
| 239 | inline bool Data::tinseth() { return tinseth_; } |
| 240 | |
| 241 | inline void Data::setTinseth(bool tinseth) { tinseth_ = tinseth; } |
| 242 | |
| 243 | inline bool Data::morey() { return morey_; } |
| 244 | |
| 245 | inline void Data::setMorey(bool morey) { morey_ = morey; } |
| 246 | |
| 247 | #endif // DATA_H |