Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/mymoney/mymoneymoney.h
Context not available. | |||||
3 | ------------------- | 3 | ------------------- | ||
---|---|---|---|---|---|
4 | copyright : (C) 2000-2002 by Michael Edwardes | 4 | copyright : (C) 2000-2002 by Michael Edwardes | ||
5 | email : mte@users.sourceforge.net | 5 | email : mte@users.sourceforge.net | ||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
6 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
7 | 8 | | |||
8 | /*************************************************************************** | 9 | /*************************************************************************** | ||
Context not available. | |||||
16 | #ifndef MYMONEYMONEY_H | 17 | #ifndef MYMONEYMONEY_H | ||
17 | #define MYMONEYMONEY_H | 18 | #define MYMONEYMONEY_H | ||
18 | 19 | | |||
19 | // #include <cmath> | | |||
20 | #include <stddef.h> | | |||
21 | | ||||
22 | //FIXME workaround for dealing with lond double | | |||
23 | #include <gmpxx.h> | | |||
24 | | ||||
25 | // So we can save this object | 20 | // So we can save this object | ||
26 | #include <QChar> | | |||
27 | #include <QString> | | |||
28 | #include <QMetaType> | 21 | #include <QMetaType> | ||
29 | 22 | | |||
30 | #include "kmm_mymoney_export.h" | 23 | #include "kmm_mymoney_export.h" | ||
31 | #include "mymoneyunittestable.h" | 24 | #include "mymoneyunittestable.h" | ||
32 | #include "mymoneyexception.h" | | |||
33 | 25 | | |||
34 | #include <alkimia/alkvalue.h> | 26 | #include <alkimia/alkvalue.h> | ||
35 | 27 | | |||
36 | typedef qint64 signed64; | 28 | typedef qint64 signed64; | ||
37 | typedef quint64 unsigned64; | 29 | typedef quint64 unsigned64; | ||
38 | 30 | | |||
31 | namespace eMyMoney { namespace Money { enum signPosition : int; } } | ||||
39 | 32 | | |||
40 | /** | 33 | /** | ||
41 | * This class represents a value within the MyMoney Engine | 34 | * This class represents a value within the MyMoney Engine | ||
Context not available. | |||||
48 | KMM_MYMONEY_UNIT_TESTABLE | 41 | KMM_MYMONEY_UNIT_TESTABLE | ||
49 | 42 | | |||
50 | public: | 43 | public: | ||
51 | enum fileVersionE { | | |||
52 | FILE_4_BYTE_VALUE = 0, | | |||
53 | FILE_8_BYTE_VALUE | | |||
54 | }; | | |||
55 | | ||||
56 | enum signPosition { | | |||
57 | // keep those in sync with the ones defined in klocale.h | | |||
58 | ParensAround = 0, | | |||
59 | BeforeQuantityMoney = 1, | | |||
60 | AfterQuantityMoney = 2, | | |||
61 | BeforeMoney = 3, | | |||
62 | AfterMoney = 4 | | |||
63 | }; | | |||
64 | | ||||
65 | enum roundingMethod { | | |||
66 | RndNever = 0, | | |||
67 | RndFloor, | | |||
68 | RndCeil, | | |||
69 | RndTrunc, | | |||
70 | RndPromote, | | |||
71 | RndHalfDown, | | |||
72 | RndHalfUp, | | |||
73 | RndRound | | |||
74 | }; | | |||
75 | | ||||
76 | // construction | 44 | // construction | ||
77 | MyMoneyMoney(); | 45 | MyMoneyMoney(); | ||
78 | explicit MyMoneyMoney(const int iAmount, const signed64 denom); | 46 | explicit MyMoneyMoney(const int iAmount, const signed64 denom); | ||
Context not available. | |||||
124 | */ | 92 | */ | ||
125 | static int denomToPrec(signed64 fract); | 93 | static int denomToPrec(signed64 fract); | ||
126 | 94 | | |||
127 | MyMoneyMoney convert(const signed64 denom = 100, const roundingMethod how = RndRound) const; | 95 | MyMoneyMoney convert(const signed64 denom = 100, const AlkValue::RoundingMethod how = AlkValue::RoundRound) const; | ||
128 | static signed64 precToDenom(int prec); | 96 | static signed64 precToDenom(int prec); | ||
129 | double toDouble() const; | 97 | double toDouble() const; | ||
130 | 98 | | |||
131 | static void setThousandSeparator(const QChar &); | 99 | static void setThousandSeparator(const QChar &); | ||
132 | static void setDecimalSeparator(const QChar &); | 100 | static void setDecimalSeparator(const QChar &); | ||
133 | static void setNegativeMonetarySignPosition(const signPosition pos); | 101 | static void setNegativeMonetarySignPosition(const eMyMoney::Money::signPosition pos); | ||
134 | static void setPositiveMonetarySignPosition(const signPosition pos); | 102 | static void setPositiveMonetarySignPosition(const eMyMoney::Money::signPosition pos); | ||
135 | static void setNegativePrefixCurrencySymbol(const bool flags); | 103 | static void setNegativePrefixCurrencySymbol(const bool flags); | ||
136 | static void setPositivePrefixCurrencySymbol(const bool flags); | 104 | static void setPositivePrefixCurrencySymbol(const bool flags); | ||
137 | 105 | | |||
138 | static const QChar thousandSeparator(); | 106 | static const QChar thousandSeparator(); | ||
139 | static const QChar decimalSeparator(); | 107 | static const QChar decimalSeparator(); | ||
140 | static signPosition negativeMonetarySignPosition(); | 108 | static eMyMoney::Money::signPosition negativeMonetarySignPosition(); | ||
141 | static signPosition positiveMonetarySignPosition(); | 109 | static eMyMoney::Money::signPosition positiveMonetarySignPosition(); | ||
142 | static void setFileVersion(const fileVersionE version); | | |||
143 | 110 | | |||
144 | const MyMoneyMoney& operator=(const QString& pszAmount); | 111 | const MyMoneyMoney& operator=(const QString& pszAmount); | ||
145 | const MyMoneyMoney& operator=(const AlkValue& val); | 112 | const MyMoneyMoney& operator=(const AlkValue& val); | ||
Context not available. | |||||
180 | 147 | | |||
181 | static const MyMoneyMoney ONE; | 148 | static const MyMoneyMoney ONE; | ||
182 | static const MyMoneyMoney MINUS_ONE; | 149 | static const MyMoneyMoney MINUS_ONE; | ||
183 | | ||||
184 | private: | | |||
185 | | ||||
186 | static QChar _thousandSeparator; | | |||
187 | static QChar _decimalSeparator; | | |||
188 | static signPosition _negativeMonetarySignPosition; | | |||
189 | static signPosition _positiveMonetarySignPosition; | | |||
190 | static bool _negativePrefixCurrencySymbol; | | |||
191 | static bool _positivePrefixCurrencySymbol; | | |||
192 | static MyMoneyMoney::fileVersionE _fileVersion; | | |||
193 | }; | 150 | }; | ||
194 | 151 | | |||
195 | //============================================================================= | 152 | //============================================================================= | ||
Context not available. | |||||
211 | { | 168 | { | ||
212 | } | 169 | } | ||
213 | 170 | | |||
214 | //////////////////////////////////////////////////////////////////////////////// | | |||
215 | // Name: MyMoneyMoney | | |||
216 | // Purpose: Constructor - constructs object from an amount in a signed64 value | | |||
217 | // Returns: None | | |||
218 | // Throws: Nothing. | | |||
219 | // Arguments: Amount - signed 64 object containing amount | | |||
220 | // denom - denominator of the object | | |||
221 | // | | |||
222 | //////////////////////////////////////////////////////////////////////////////// | | |||
223 | inline MyMoneyMoney::MyMoneyMoney(signed64 Amount, const signed64 denom) | | |||
224 | { | | |||
225 | if (!denom) | | |||
226 | throw MYMONEYEXCEPTION("Denominator 0 not allowed!"); | | |||
227 | | ||||
228 | *this = AlkValue(QString("%1/%2").arg(Amount).arg(denom), _decimalSeparator); | | |||
229 | } | | |||
230 | 171 | | |||
231 | //////////////////////////////////////////////////////////////////////////////// | 172 | //////////////////////////////////////////////////////////////////////////////// | ||
232 | // Name: MyMoneyMoney | 173 | // Name: MyMoneyMoney | ||
Context not available. | |||||
242 | { | 183 | { | ||
243 | } | 184 | } | ||
244 | 185 | | |||
245 | //////////////////////////////////////////////////////////////////////////////// | | |||
246 | // Name: MyMoneyMoney | | |||
247 | // Purpose: Constructor - constructs object from an amount in a integer value | | |||
248 | // Returns: None | | |||
249 | // Throws: Nothing. | | |||
250 | // Arguments: iAmount - integer object containing amount | | |||
251 | // denom - denominator of the object | | |||
252 | // | | |||
253 | //////////////////////////////////////////////////////////////////////////////// | | |||
254 | inline MyMoneyMoney::MyMoneyMoney(const int iAmount, const signed64 denom) | | |||
255 | { | | |||
256 | if (!denom) | | |||
257 | throw MYMONEYEXCEPTION("Denominator 0 not allowed!"); | | |||
258 | *this = AlkValue(iAmount, denom); | | |||
259 | } | | |||
260 | | ||||
261 | //////////////////////////////////////////////////////////////////////////////// | | |||
262 | // Name: MyMoneyMoney | | |||
263 | // Purpose: Constructor - constructs object from an amount in a long integer value | | |||
264 | // Returns: None | | |||
265 | // Throws: Nothing. | | |||
266 | // Arguments: iAmount - integer object containing amount | | |||
267 | // denom - denominator of the object | | |||
268 | // | | |||
269 | //////////////////////////////////////////////////////////////////////////////// | | |||
270 | inline MyMoneyMoney::MyMoneyMoney(const long int iAmount, const signed64 denom) | | |||
271 | { | | |||
272 | if (!denom) | | |||
273 | throw MYMONEYEXCEPTION("Denominator 0 not allowed!"); | | |||
274 | *this = AlkValue(QString("%1/%2").arg(iAmount).arg(denom), _decimalSeparator); | | |||
275 | } | | |||
276 | | ||||
277 | //////////////////////////////////////////////////////////////////////////////// | 186 | //////////////////////////////////////////////////////////////////////////////// | ||
278 | // Name: MyMoneyMoney | 187 | // Name: MyMoneyMoney | ||
279 | // Purpose: Copy Constructor - constructs object from another | 188 | // Purpose: Copy Constructor - constructs object from another | ||
Context not available. |