~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/yeast.h

  • Committer: Philip Greggory Lee
  • Date: 2009-08-23 16:53:43 UTC
  • Revision ID: git-v1:f8d1a25135bd92f06c46c562293800e4faa42c61
Made a src/ and ui/ directory and moved everything.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * yeast.h is part of Brewtarget, and is Copyright Philip G. Lee
 
3
 * (rocketman768@gmail.com), 2009.
 
4
 *
 
5
 * Brewtarget is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 
 
10
 * Brewtarget is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#ifndef _YEAST_H
 
20
#define _YEAST_H
 
21
 
 
22
#include <string>
 
23
#include <exception>
 
24
#include "xmlnode.h"
 
25
#include "observable.h"
 
26
#include "BeerXMLElement.h"
 
27
#include <QDomNode>
 
28
 
 
29
class Yeast;
 
30
class YeastException;
 
31
 
 
32
class Yeast : public Observable, public BeerXMLElement
 
33
{
 
34
public:
 
35
   Yeast();
 
36
   Yeast(Yeast& other);
 
37
   Yeast( XmlNode *node );
 
38
   Yeast( const QDomNode& yeastNode );
 
39
 
 
40
   friend bool operator<(Yeast &y1, Yeast &y2);
 
41
   friend bool operator==(Yeast &y1, Yeast &y2);
 
42
 
 
43
   virtual void toXml(QDomDocument& doc, QDomNode& parent); // From BeerXMLElement
 
44
 
 
45
   //std::string toXml();
 
46
   
 
47
   // Set
 
48
   void setName( const std::string& var );
 
49
   void setType( const std::string& var );
 
50
   void setForm( const std::string& var );
 
51
   void setAmount( double var );
 
52
   void setAmountIsWeight( bool var );
 
53
   void setLaboratory( const std::string& var );
 
54
   void setProductID( const std::string& var );
 
55
   void setMinTemperature_c( double var );
 
56
   void setMaxTemperature_c( double var );
 
57
   void setFlocculation( const std::string& var );
 
58
   void setAttenuation_pct( double var );
 
59
   void setNotes( const std::string& var );
 
60
   void setBestFor( const std::string& var );
 
61
   void setTimesCultured( int var );
 
62
   void setMaxReuse( int var );
 
63
   void setAddToSecondary( bool var );
 
64
   
 
65
   // Get
 
66
   std::string getName() const;
 
67
   std::string getType() const;
 
68
   std::string getForm() const;
 
69
   double getAmount() const;
 
70
   bool getAmountIsWeight() const;
 
71
   std::string getLaboratory() const;
 
72
   std::string getProductID() const;
 
73
   double getMinTemperature_c() const;
 
74
   double getMaxTemperature_c() const;
 
75
   std::string getFlocculation() const;
 
76
   double getAttenuation_pct() const;
 
77
   std::string getNotes() const;
 
78
   std::string getBestFor() const;
 
79
   int getTimesCultured() const;
 
80
   int getMaxReuse() const;
 
81
   bool getAddToSecondary() const;
 
82
   
 
83
private:
 
84
   // Required fields.
 
85
   std::string name;
 
86
   static const int version = 1;
 
87
   std::string type;
 
88
   std::string form;
 
89
   double amount;
 
90
   
 
91
   // Optional fields.
 
92
   bool amountIsWeight;
 
93
   std::string laboratory;
 
94
   std::string productID;
 
95
   double minTemperature_c;
 
96
   double maxTemperature_c;
 
97
   std::string flocculation;
 
98
   double attenuation_pct;
 
99
   std::string notes;
 
100
   std::string bestFor;
 
101
   int timesCultured;
 
102
   int maxReuse;
 
103
   bool addToSecondary;
 
104
   
 
105
   // Methods
 
106
   bool isValidType(const std::string& str) const;
 
107
   bool isValidForm(const std::string& str) const;
 
108
   bool isValidFlocculation(const std::string& str) const;
 
109
   void setDefaults();
 
110
};
 
111
 
 
112
class YeastException : public std::exception
 
113
{
 
114
public:
 
115
   
 
116
   virtual const char* what() const throw()
 
117
   {
 
118
      // Note: this temporary object might get destroyed too early.
 
119
      // I'm not really sure.
 
120
      return std::string("BeerXml YEAST error: " + _err + "\n").c_str();
 
121
   }
 
122
   
 
123
   YeastException( std::string message )
 
124
   {
 
125
      _err = message;
 
126
   }
 
127
   
 
128
   ~YeastException() throw() {}
 
129
   
 
130
private:
 
131
   
 
132
   std::string _err;
 
133
};
 
134
 
 
135
struct Yeast_ptr_cmp
 
136
{
 
137
   bool operator()( Yeast* lhs, Yeast* rhs)
 
138
   {
 
139
      return *lhs < *rhs;
 
140
   }
 
141
};
 
142
 
 
143
struct Yeast_ptr_equals
 
144
{
 
145
   bool operator()( Yeast* lhs, Yeast* rhs )
 
146
   {
 
147
      return *lhs == *rhs;
 
148
   }
 
149
};
 
150
 
 
151
#endif  /* _YEAST_H */
 
152