File: grain.cpp

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 (127 lines) | stat: -rw-r--r-- 3,668 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
/***************************************************************************
  grain.cpp
  -------------------
  A grain class
  -------------------
  Copyright 1999-2008, David Johnson
  Please see the header file for copyright and license information
 ***************************************************************************/

#include "resource.h"
#include "grain.h"

using namespace Resource;

const QByteArray Grain::EXTRACT_STRING = QT_TRANSLATE_NOOP("grain", "Extract");
const QByteArray Grain::MASHED_STRING  = QT_TRANSLATE_NOOP("grain", "Mashed");
const QByteArray Grain::STEEPED_STRING = QT_TRANSLATE_NOOP("grain", "Steeped");
const QByteArray Grain::GRAIN_STRING   = QT_TRANSLATE_NOOP("grain", "Grain");
const QByteArray Grain::ADJUNCT_STRING = QT_TRANSLATE_NOOP("grain", "Adjunct");
const QByteArray Grain::SUGAR_STRING   = QT_TRANSLATE_NOOP("grain", "Sugar");
const QByteArray Grain::OTHER_STRING   = QT_TRANSLATE_NOOP("grain", "Other");

//////////////////////////////////////////////////////////////////////////////
// Grain()
// -------
// Constructor

Grain::Grain()
    : name_(QObject::tr("Generic")), weight_(), extract_(1.025), color_(1.0),
      type_(GRAIN_STRING), use_(OTHER_STRING), yield_(0.0), hcu_(0.0)
{ ; }

Grain::Grain(const QString &name, const Weight &weight, const double &extract,
             const double &color, const QString &typ, const QString &use)
    : name_(name), weight_(weight), extract_(extract), color_(color),
      type_(typ), use_(use)
{
    recalc();
}

Grain::~Grain() { ; }

//////////////////////////////////////////////////////////////////////////////
// Grain(const Grain&)
// --------------------
// Copy Constructor

Grain::Grain(const Grain &g)
    : name_(g.name_), weight_(g.weight_), extract_(g.extract_),
      color_(g.color_), type_(g.type_), use_(g.use_), yield_(g.yield_),
      hcu_(g.hcu_)
{ ; }

//////////////////////////////////////////////////////////////////////////////
// operator=()
// -----------
// Assignment operator

Grain Grain::operator=(const Grain &g)
{
    if (this != &g) {
        name_ = g.name_;
        weight_ = g.weight_;
        extract_ = g.extract_;
        color_ = g.color_;
        type_ = g.type_;
        use_ = g.use_;
        yield_ = g.yield_;
        hcu_ = g.hcu_;
    }
    return *this;
}

//////////////////////////////////////////////////////////////////////////////
// operator==()
// ------------
// Equivalence operator

bool Grain::operator==(const Grain &g) const
{
    return (name_ == g.name_)
        && (weight_ == g.weight_)
        && (extract_ == g.extract_)
        && (color_ == g.color_)
        && (type_ == g.type_)
        && (use_ == g.use_);
}

///////////////////////////////////////////////////////////////////////////////
// typeStringList()
// ----------------
// Return string list of grain types

QStringList Grain::typeStringList()
{
    return (QStringList()
            << GRAIN_STRING
            << EXTRACT_STRING
            << ADJUNCT_STRING
            << SUGAR_STRING
            << OTHER_STRING);
}

///////////////////////////////////////////////////////////////////////////////
// useStringList()
// -----------
// Return string list of usage types

QStringList Grain::useStringList()
{
    return (QStringList()
            << EXTRACT_STRING
            << MASHED_STRING
            << STEEPED_STRING
            << OTHER_STRING);
}

///////////////////////////////////////////////////////////////////////////////
// recalc()
// --------
// Recalculate internal values

void Grain::recalc()
{
    yield_ = weight_.amount(Weight::pound) * (extract_ - 1.000);
    hcu_ = weight_.amount(Weight::pound) * color_;
}