1 /*---------------------------------------------------------------------------*
2 
3 Copyright (C) 2013-2014 Nintendo. All rights reserved.
4 
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law.  They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 #ifndef NN_EC_MONEY_H_
14 #define NN_EC_MONEY_H_
15 
16 #include <nn/ec/ec_Types.h>
17 
18 namespace nn { namespace ec {
19 
20 //! @addtogroup nn_ec_class
21 //! @{
22 
23 /*!
24 @brief      Class for handling money.
25 */
26 class Money : public RootObject
27 {
28 public:
29     /*!
30 @brief Specifies the maximum length of the amount string.
31     */
32     static const size_t AMOUNT_LENGTH_MAX = 43;
33     /*!
34 @brief Specifies the size of the amount string.
35     */
36     static const size_t AMOUNT_SIZE = AMOUNT_LENGTH_MAX + 1;
37     /*!
38 @brief Specifies the maximum length of an unformatted amount string.
39     */
40     static const size_t VALUE_LENGTH_MAX = 15;
41     /*!
42 @brief Specifies the size of an unformatted amount string.
43     */
44     static const size_t VALUE_SIZE = VALUE_LENGTH_MAX + 1;
45     /*!
46 @brief Specifies the length of the currency code.
47     */
48     static const size_t CURRENCY_LENGTH = 3;
49     /*!
50 @brief Specifies the size of the currency code.
51     */
52     static const size_t CURRENCY_SIZE = CURRENCY_LENGTH + 1;
53 
54     /*!
55 @brief Specifies the maximum digits of the integer part.
56     */
57     static const size_t INTEGER_LENGTH_MAX = 10;
58 
59     /*!
60 @brief Specifies the maximum digits of the fractional part.
61     */
62     static const size_t DECIMAL_LENGTH_MAX = 2;
63 
64     /*!
65 @brief Specifies the invalid amount string that is set when an incorrect amount is specified or an overflow occurs.
66     */
67     static const char* INVALID_AMOUNT; // "##########.##"
68 
69 public:
70     /*!
71 @brief Instantiates the object.
72 
73 @param[in] pValue  Specifies an unformatted amount string.
74 @param[in] pCurrency  Specifies the currency code.
75 @param[in] pAmount  Specifies the amount string.
76     */
77     Money(const char* pValue = NULL, const char* pCurrency = NULL, const char* pAmount = NULL);
78 
79     /*!
80 @brief Gets the unformatted amount string.
81 
82 @return Returns the unformatted amount string.
83     */
84     const char* GetValue() const;
85 
86     /*!
87 @brief Gets the currency code.
88 
89 @return Returns the currency code.
90     */
91     const char* GetCurrency() const;
92 
93     /*!
94 @brief Gets the amount string.
95 
96 The amount string is "##########.##" for <tt>@ref Money</tt> objects created using calculations or integer multiples before <tt>@ref Login</tt>. @n
97 This is because there is no local information before <tt>@ref Login</tt>, so amount strings cannot be generated.
98 
99 @return Returns the amount string.
100     */
101     const char* GetAmount() const;
102 
103     /*!
104 @brief Determines whether the amount is valid.
105 
106 @return Returns <tt>true</tt> if the amount is valid, or <tt>false</tt> otherwise.
107     */
108     bool IsValid() const;
109 
110     /*!
111 @brief Determines whether the amount is <tt>0</tt>.
112 
113 @return Returns <tt>true</tt> if the amount is 0, or <tt>false</tt> otherwise.
114     */
115     bool IsZero() const;
116 
117     /*!
118 @brief Adds the amounts in two <tt>Money</tt> objects.
119 
120 @param[in] money  Specifies the <tt>Money</tt> to add.
121 
122 @return Returns a <tt>Money</tt> object.
123     */
124     const Money operator+(const Money& money) const;
125 
126     /*!
127 @brief Subtracts the amount in one <tt>Money</tt> object from the amount in another <tt>Money</tt> object.
128 
129 @param[in] money  Specifies the <tt>Money</tt> to subtract.
130 
131 @return Returns a <tt>Money</tt> object.
132     */
133     const Money operator-(const Money& money) const;
134 
135     /*!
136 @brief Gets the amount multiplied by an integer.
137 
138 @param[in] quantity  Specifies the quantity.
139 
140 @return Returns a <tt>Money</tt> object.
141     */
142     const Money operator*(u32 quantity) const;
143 
144     /*!
145 @brief Calculates the <tt>Money</tt> object quotient.
146 
147 This function returns <tt>0</tt> if the denominator is <tt>0</tt>.
148 
149 @param[in]  money               The amount that will serve as the denominator.
150 
151 @return     The quotient.
152     */
153     f64 operator/(const Money& money) const;
154 
155     /*!
156 @brief Adds the amounts in two <tt>Money</tt> objects.
157 
158 @param[in] money  Specifies the <tt>Money</tt> to add.
159 
160 @return Returns a <tt>Money</tt> object.
161     */
162     Money& operator+=(const Money& money);
163 
164     /*!
165 @brief Subtracts the amount in one <tt>Money</tt> object from the amount in another <tt>Money</tt> object.
166 
167 @param[in] money  Specifies the <tt>Money</tt> to subtract.
168 
169 @return Returns a <tt>Money</tt> object.
170     */
171     Money& operator-=(const Money& money);
172 
173     /*!
174 @brief Gets the amount multiplied by an integer.
175 
176 @param[in] quantity  Specifies the quantity.
177 
178 @return Returns a <tt>Money</tt> object.
179     */
180     Money& operator*=(u32 quantity);
181 
182     /*!
183 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
184 
185 @param[in] money  Specifies the <tt>Money</tt> to compare.
186 
187 @return Returns the result of an equality (<tt>==</tt>) operation.
188     */
189     bool operator==(const Money& money) const;
190 
191     /*!
192 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
193 
194 @param[in] money  Specifies the <tt>Money</tt> to compare.
195 
196 @return Returns the result of an inequality (<tt>!=</tt>) operation.
197     */
198     bool operator!=(const Money& money) const;
199 
200     /*!
201 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
202 
203 @param[in] money  Specifies the <tt>Money</tt> to compare.
204 
205 @return Returns the result of a greater than (<tt>></tt>) operation.
206     */
207     bool operator>(const Money& money) const;
208 
209     /*!
210 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
211 
212 @param[in] money  Specifies the <tt>Money</tt> to compare.
213 
214 @return Returns the result of a less than (<tt><</tt>) operation.
215     */
216     bool operator<(const Money& money) const;
217 
218     /*!
219 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
220 
221 @param[in] money  Specifies the <tt>Money</tt> to compare.
222 
223 @return Returns the result of a greater-than-or-equal-to (<tt>>=</tt>) operation.
224     */
225     bool operator>=(const Money& money) const;
226 
227     /*!
228 @brief Compares the amount in one <tt>Money</tt> object to the amount in another <tt>Money</tt> object.
229 
230 @param[in] money  Specifies the <tt>Money</tt> to compare.
231 
232 @return Returns the result of a less-than-or-equal-to (<tt><=</tt>) operation.
233     */
234     bool operator<=(const Money& money) const;
235 
236     /*!
237 @brief Creates a <tt>Money</tt> object from an unformatted money string.
238 
239 The money string and currency code are not set when the user is not logged in.
240 
241 @param[in] pValue  Specifies an unformatted amount string.
242 
243 @return Returns a <tt>Money</tt> object.
244     */
245     static Money Make(const char* pValue);
246 
247 private:
248     //
249     char m_amount[AMOUNT_SIZE];
250     //
251     char m_value[VALUE_SIZE];
252     //
253     u32 m_currency;
254 };
255 
256 //! @}
257 
258 }} // namespace nn::ec
259 
260 #endif // NN_EC_MONEY_H_
261