File: data.h

package info (click to toggle)
qbrew 0.4.1-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,724 kB
  • ctags: 1,355
  • sloc: cpp: 7,503; sh: 414; makefile: 18
file content (247 lines) | stat: -rw-r--r-- 7,698 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/***************************************************************************
  data.h
  -------------------
  Brewing data
  -------------------
  Copyright 2001-2008 David Johnson
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.
 ***************************************************************************/

#ifndef DATA_H
#define DATA_H

#include <QList>
#include <QString>

#include "configstate.h"
#include "grain.h"
#include "hop.h"
#include "misc.h"
#include "style.h"

class QDomElement;

struct UEntry {
    // hop utilization table entry structure
    unsigned time;
    unsigned utilization;
};

class Data {
public:
    friend class DatabaseTool;

    ~Data();
    static Data *instance();
    void initialize(const ConfigState &state);

    // load the data
    bool loadData(const QString &filename, bool quiet=false);
    // save the data
    bool saveData(const QString &filename);

    // get/set the default size volume
    const Volume &defaultSize() const;
    void setDefaultSize(const Volume &v);
    // get/set the default style
    const Style &defaultStyle() const;
    void setDefaultStyle(const QString &s);
    void setDefaultStyle(const Style &s);
    // get/set default hop type
    const QString &defaultHopType() const;
    void setDefaultHopType(const QString &t);
    // get/set the default grain units
    const Unit &defaultGrainUnit() const;
    void setDefaultGrainUnit(Unit &u);
    // get/set the default hop units
    const Unit &defaultHopUnit() const;
    void setDefaultHopUnit(Unit &u);
    // get/set the default misc units
    const Unit &defaultMiscUnit() const;
    void setDefaultMiscUnit(Unit &u);
    // get/set the default temperature unit
    const Unit &defaultTempUnit() const;
    void setDefaultTempUnit(Unit &u);

    // return stringlists of data
    QStringList stylesList();
    QStringList grainsList();
    QStringList hopsList();
    QStringList miscList();

    // return given data
    Style style(const QString &name);
    Grain grain(const QString &name);
    Hop hop(const QString &name);
    Misc misc(const QString &name);

    // does data exist
    bool hasStyle(const QString &name);
    bool hasGrain(const QString &name);
    bool hasHop(const QString &name);
    bool hasMisc(const QString &name);

    // insert data
    void insertStyle(const Style &style);
    void insertGrain(const Grain &grain);
    void insertHop(const Hop &hop);
    void insertMisc(const Misc &misc);

    // clear data
    void clearStyles();
    void clearGrains();
    void clearHops();
    void clearMiscs();

    // get utilization based on time
    double utilization(unsigned time);
    // add entry to utilization table
    void addUEntry(const UEntry &entry);
    // efficiency
    double efficiency();
    void setEfficiency(double e);
    // steep yield
    double steepYield();
    void setSteepYield(double y);
    // set ibu calc method
    bool tinseth();
    void setTinseth(bool tinseth);
    // set srm calc method
    bool morey();
    void setMorey(bool morey);

private:
    Data();
    Data(const Data&);
    Data &operator=(const Data&);

private:
    friend class DataReader;
    friend class DataWriter;
    static Data *instance_;

    Volume defaultsize_;
    Style defaultstyle_;
    QString defaulthoptype_;
    Unit *defaultgrainunit_;
    Unit *defaulthopunit_;
    Unit *defaultmiscunit_;
    Unit *defaulttempunit_;

    GrainMap grainmap_;
    HopMap hopmap_;
    MiscMap miscmap_;
    StyleMap stylemap_;

    QList<UEntry> utable_;
    double steepyield_;
    double efficiency_;
    bool tinseth_;
    bool morey_;
};

// Inlined Methods ///////////////////////////////////////////////////////////

inline const QString &Data::defaultHopType() const { return defaulthoptype_; }

inline void Data::setDefaultHopType(const QString &t) { defaulthoptype_ = t; }

inline const Volume &Data::defaultSize() const { return defaultsize_; }

inline void Data::setDefaultSize(const Volume &v) { defaultsize_ = v; }

inline const Style &Data::defaultStyle() const { return defaultstyle_; }

inline void Data::setDefaultStyle(const Style &s) { defaultstyle_ = s; }

inline const Unit &Data::defaultGrainUnit() const { return *defaultgrainunit_; }

inline void Data::setDefaultGrainUnit(Unit &u) { defaultgrainunit_ = &u; }

inline const Unit &Data::defaultHopUnit() const { return *defaulthopunit_; }

inline void Data::setDefaultHopUnit(Unit &u) { defaulthopunit_ = &u; }

inline const Unit &Data::defaultMiscUnit() const { return *defaultmiscunit_; }

inline void Data::setDefaultMiscUnit(Unit &u) { defaultmiscunit_ = &u; }

inline const Unit &Data::defaultTempUnit() const { return *defaulttempunit_; }

inline void Data::setDefaultTempUnit(Unit &u) { defaulttempunit_ = &u; }

inline QStringList Data::stylesList() { return stylemap_.keys(); }

inline QStringList Data::grainsList() { return grainmap_.keys(); }

inline QStringList Data::hopsList() { return hopmap_.keys(); }

inline QStringList Data::miscList() { return miscmap_.keys(); }

inline bool Data::hasStyle(const QString &name) { return stylemap_.contains(name); }

inline bool Data::hasGrain(const QString &name) { return grainmap_.contains(name); }

inline bool Data::hasHop(const QString &name) { return hopmap_.contains(name); }

inline bool Data::hasMisc(const QString &name) { return miscmap_.contains(name); }

inline void Data::insertStyle(const Style &style)
    { stylemap_.insert(style.name(), style); }

inline void Data::insertGrain(const Grain &grain)
    { grainmap_.insert(grain.name(), grain); }

inline void Data::insertHop(const Hop &hop)
    { hopmap_.insert(hop.name(), hop); }

inline void Data::insertMisc(const Misc &misc)
    { miscmap_.insert(misc.name(), misc); }

inline void Data::clearStyles() { stylemap_.clear(); }

inline void Data::clearGrains() { grainmap_.clear(); }

inline void Data::clearHops() { hopmap_.clear(); }

inline void Data::clearMiscs() { miscmap_.clear(); }

inline double Data::efficiency() { return efficiency_; }

inline void Data::setEfficiency(double e) { efficiency_ = e; }

inline double Data::steepYield() { return steepyield_; }

inline void Data::setSteepYield(double y) { steepyield_ = y; }

inline bool Data::tinseth() { return tinseth_; }

inline void Data::setTinseth(bool tinseth) { tinseth_ = tinseth; }

inline bool Data::morey() { return morey_; }

inline void Data::setMorey(bool morey) { morey_ = morey; }

#endif // DATA_H