~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/misc.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
 * misc.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 _MISC_H
 
20
#define _MISC_H
 
21
 
 
22
#include <string>
 
23
#include <exception>
 
24
#include <QDomNode>
 
25
#include <QDomText>
 
26
#include "xmlnode.h"
 
27
#include "observable.h"
 
28
#include "BeerXMLElement.h"
 
29
 
 
30
class Misc;
 
31
class MiscException;
 
32
 
 
33
class Misc : public Observable, public BeerXMLElement
 
34
{
 
35
public:
 
36
   Misc();
 
37
   Misc(Misc& other);
 
38
   Misc( const XmlNode *node );
 
39
   Misc( const QDomNode& miscNode );
 
40
 
 
41
   friend bool operator<(Misc &m1, Misc &m2);
 
42
   friend bool operator==(Misc &m1, Misc &m2);
 
43
 
 
44
   virtual void toXml(QDomDocument& doc, QDomNode& parent); // From BeerXMLElement
 
45
   //std::string toXml();
 
46
   
 
47
   // Set
 
48
   void setName( const std::string &var );
 
49
   void setType( const std::string &var );
 
50
   void setUse( const std::string &var );
 
51
   void setAmount( double var );
 
52
   void setTime( double var );
 
53
   void setAmountIsWeight( bool var );
 
54
   void setUseFor( const std::string &var );
 
55
   void setNotes( const std::string &var );
 
56
   
 
57
   // Get
 
58
   std::string getName() const;
 
59
   std::string getType() const;
 
60
   std::string getUse() const;
 
61
   double getAmount() const;
 
62
   double getTime() const;
 
63
   bool getAmountIsWeight() const;
 
64
   std::string getUseFor() const;
 
65
   std::string getNotes() const;
 
66
   
 
67
private:
 
68
   
 
69
   // Required fields.
 
70
   std::string name;
 
71
   static const int version = 1;
 
72
   std::string type;
 
73
   std::string use;
 
74
   double time;
 
75
   double amount;
 
76
   
 
77
   // Optional fields.
 
78
   bool amountIsWeight;
 
79
   std::string useFor;
 
80
   std::string notes;
 
81
 
 
82
   // Private methods
 
83
   void setDefaults();
 
84
   bool isValidType( const std::string &var );
 
85
   bool isValidUse( const std::string &var );
 
86
};
 
87
 
 
88
class MiscException : public std::exception
 
89
{
 
90
public:
 
91
   
 
92
   virtual const char* what() const throw()
 
93
   {
 
94
      // Note: this temporary object might get destroyed too early.
 
95
      // I'm not really sure.
 
96
      return std::string("BeerXml MISC error: " + _err + "\n").c_str();
 
97
   }
 
98
   
 
99
   MiscException( std::string message )
 
100
   {
 
101
      _err = message;
 
102
   }
 
103
   
 
104
   ~MiscException() throw() {}
 
105
   
 
106
private:
 
107
   
 
108
   std::string _err;
 
109
};
 
110
 
 
111
struct Misc_ptr_cmp
 
112
{
 
113
   bool operator()( Misc* lhs, Misc* rhs)
 
114
   {
 
115
      return *lhs < *rhs;
 
116
   }
 
117
};
 
118
 
 
119
struct Misc_ptr_equals
 
120
{
 
121
   bool operator()( Misc* lhs, Misc* rhs )
 
122
   {
 
123
      return *lhs == *rhs;
 
124
   }
 
125
};
 
126
 
 
127
#endif  /* _MISC_H */