~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/hop.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
 * hop.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 _HOP_H
 
20
#define _HOP_H
 
21
 
 
22
#include <string>
 
23
#include <exception>
 
24
#include "xmlnode.h"
 
25
#include "observable.h"
 
26
#include <QDomNode>
 
27
#include "BeerXMLElement.h"
 
28
 
 
29
using namespace std;
 
30
 
 
31
class Hop;
 
32
class HopException;
 
33
 
 
34
class Hop : public Observable, public BeerXMLElement
 
35
{
 
36
   public:
 
37
      Hop();
 
38
      Hop( Hop& other );
 
39
      Hop( const XmlNode *node );
 
40
      Hop(const QDomNode& hopNode);
 
41
 
 
42
      friend bool operator<( Hop &h1, Hop &h2 );
 
43
      friend bool operator==( Hop &h1, Hop &h2 );
 
44
 
 
45
      virtual void toXml(QDomDocument& doc, QDomNode& parent); // From BeerXMLElement
 
46
      //std::string toXml();
 
47
      
 
48
      const string& getName() const;
 
49
      int getVersion() const;
 
50
      double getAlpha_pct() const;
 
51
      double getAmount_kg() const;
 
52
      const string& getUse() const;
 
53
      double getTime_min() const;
 
54
      
 
55
      const string& getNotes() const;
 
56
      const string& getType() const;
 
57
      const string& getForm() const;
 
58
      double getBeta_pct() const;
 
59
      double getHsi_pct() const;
 
60
      const string& getOrigin() const;
 
61
      const string& getSubstitutes() const;
 
62
      double getHumulene_pct() const;
 
63
      double getCaryophyllene_pct() const;
 
64
      double getCohumulone_pct() const;
 
65
      double getMyrcene_pct() const;
 
66
      
 
67
      //set
 
68
      void setName( const string &str );
 
69
      void setAlpha_pct( double num );
 
70
      void setAmount_kg( double num );
 
71
      bool setUse( const string &str );
 
72
      void setTime_min( double num );
 
73
      
 
74
      void setNotes( const string &str );
 
75
      bool setType( const string &str );
 
76
      bool setForm( const string &str );
 
77
      void setBeta_pct( double num );
 
78
      void setHsi_pct( double num );
 
79
      void setOrigin( const string &str );
 
80
      void setSubstitutes( const string &str );
 
81
      void setHumulene_pct( double num );
 
82
      void setCaryophyllene_pct( double num );
 
83
      void setCohumulone_pct( double num );
 
84
      void setMyrcene_pct( double num );
 
85
      
 
86
   private:
 
87
      // Mandatory members.
 
88
      string name;
 
89
      const static int version = 1;
 
90
      double alpha_pct;
 
91
      double amount_kg;
 
92
      string use;
 
93
      double time_min;
 
94
      
 
95
      // Optional members.
 
96
      string notes;
 
97
      string type;
 
98
      string form;
 
99
      double beta_pct;
 
100
      double hsi_pct;
 
101
      string origin;
 
102
      string substitutes;
 
103
      double humulene_pct;
 
104
      double caryophyllene_pct;
 
105
      double cohumulone_pct;
 
106
      double myrcene_pct;
 
107
      
 
108
      // Sets every member to zero or blank or whatever.
 
109
      void setDefaults();
 
110
      // Misc functions.
 
111
      static bool isValidUse(const string &str);
 
112
      static bool isValidType(const string &str);
 
113
      static bool isValidForm(const string &str);
 
114
};
 
115
 
 
116
class HopException : public std::exception
 
117
{
 
118
public:
 
119
   
 
120
   virtual const char* what() const throw()
 
121
   {
 
122
      // Note: this temporary object might get destroyed too early.
 
123
      // I'm not really sure.
 
124
      return std::string("BeerXml HOP error: " + _err + "\n").c_str();
 
125
   }
 
126
   
 
127
   HopException( std::string message )
 
128
   {
 
129
      _err = message;
 
130
   }
 
131
   
 
132
   ~HopException() throw() {}
 
133
   
 
134
private:
 
135
   
 
136
   std::string _err;
 
137
};
 
138
 
 
139
struct Hop_ptr_cmp
 
140
{
 
141
   bool operator()( Hop* lhs, Hop* rhs)
 
142
   {
 
143
      return *lhs < *rhs;
 
144
   }
 
145
};
 
146
 
 
147
struct Hop_ptr_equals
 
148
{
 
149
   bool operator()( Hop* lhs, Hop* rhs )
 
150
   {
 
151
      return *lhs == *rhs;
 
152
   }
 
153
};
 
154
 
 
155
#endif // _HOP_H