1 /***************************************************************************
2 grain.h
3 -------------------
4 A grain 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 GRAIN_H
34 #define GRAIN_H
35
36 #include <QList>
37 #include <QMap>
38 #include <QStringList>
39
40 #include "quantity.h"
41
42 class Grain {
43 public:
44 // grain strings
45 static const QByteArray EXTRACT_STRING;
46 static const QByteArray MASHED_STRING;
47 static const QByteArray STEEPED_STRING;
48 static const QByteArray GRAIN_STRING;
49 static const QByteArray ADJUNCT_STRING;
50 static const QByteArray SUGAR_STRING;
51 static const QByteArray OTHER_STRING;
52
53 // default constructor
54 Grain();
55 // constructor
56 Grain(const QString &name, const Weight &quantity, const double &extract,
57 const double &color, const QString &typ, const QString &use);
58 // copy constructor
59 Grain(const Grain &g);
60 // operators
61 Grain operator=(const Grain &g);
62 bool operator==(const Grain &g) const;
63 bool operator<(const Grain &g) const;
64 // destructor
65 ~Grain();
66
67 // get/set name
68 const QString &name() const;
69 void setName(const QString &name);
70 // get/set weight
71 const Weight &weight() const;
72 void setWeight(const Weight &weight);
73 // get/set extract
74 double extract() const;
75 void setExtract(double extract);
76 // get/set color
77 double color() const;
78 void setColor(double color);
79 // get/set type
80 const QString &type() const;
81 void setType(const QString &typ);
82 // get/set usage
83 const QString &use() const;
84 void setUse(const QString &use);
85
86 // return the yield (quantity times extract)
87 double yield() const;
88 // return the HCU (quantity times color)
89 double HCU() const;
90
91 // return a list of use strings
92 static QStringList useStringList();
93 // return a list of type strings
94 static QStringList typeStringList();
95
96 private:
97 // recalc values
98 void recalc();
99
100 private:
101 QString name_;
102 Weight weight_;
103 double extract_;
104 double color_;
105 QString type_;
106 QString use_;
107 double yield_;
108 double hcu_;
109 };
110
111 typedef QList<Grain> GrainList;
112 typedef QMap<QString,Grain> GrainMap;
113
114 //////////////////////////////////////////////////////////////////////////////
115 // Inlined Methods
116
117 inline bool Grain::operator<(const Grain &g) const
118 { return (name_<g.name_); }
119
setName(const QString & name)120 inline void Grain::setName(const QString &name)
121 { name_ = name; }
122
name()123 inline const QString &Grain::name() const
124 { return name_; }
125
setWeight(const Weight & weight)126 inline void Grain::setWeight(const Weight &weight)
127 { weight_ = weight; recalc(); }
128
weight()129 inline const Weight &Grain::weight() const
130 { return weight_; }
131
setExtract(double extract)132 inline void Grain::setExtract(double extract)
133 { extract_ = extract; recalc(); }
134
extract()135 inline double Grain::extract() const
136 { return extract_; }
137
setColor(double color)138 inline void Grain::setColor(double color)
139 { color_ = color; recalc(); }
140
color()141 inline double Grain::color() const
142 { return color_; }
143
setType(const QString & typ)144 inline void Grain::setType(const QString &typ)
145 { type_ = typ; }
146
type()147 inline const QString &Grain::type() const
148 { return type_; }
149
setUse(const QString & use)150 inline void Grain::setUse(const QString &use)
151 { use_ = use; }
152
use()153 inline const QString &Grain::use() const
154 { return use_; }
155
yield()156 inline double Grain::yield() const
157 { return yield_; }
158
HCU()159 inline double Grain::HCU() const
160 { return hcu_; }
161
162 #endif // GRAIN_H
163