ledger-core
Amount.h
1 /*
2  *
3  * Amount
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 30/06/2017.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2016 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 #ifndef LEDGER_CORE_AMOUNT_H
32 #define LEDGER_CORE_AMOUNT_H
33 
34 #include <api/Amount.hpp>
35 #include <api/Currency.hpp>
36 #include <math/BigInt.h>
37 #include <api_impl/BigIntImpl.hpp>
38 
39 namespace ledger {
40  namespace core {
41  class Amount : public api::Amount {
42  public:
43  Amount(const api::Currency& currency, int32_t unitIndex, const BigInt& value);
44  Amount(const api::Currency& currency, int32_t unitIndex, BigInt&& value);
45  std::shared_ptr<api::BigInt> toBigInt() override;
46  api::Currency getCurrency() override;
47  api::CurrencyUnit getUnit() override;
48  std::shared_ptr<api::Amount> toUnit(const api::CurrencyUnit &unit) override;
49  std::string toString() override;
50  int64_t toLong() override;
51  double toDouble() override;
52  std::string format(const api::Locale &locale, const optional<api::FormatRules> &rules) override;
53  std::shared_ptr<api::Amount> toMagnitude(int32_t magnitude) override;
54  std::shared_ptr<ledger::core::BigInt> value() const;
55 
56  private:
57  int32_t getMagnitude() const;
58 
59  private:
60  BigInt _value;
61  int32_t _unitIndex;
62  api::Currency _currency;
63  };
64  }
65 }
66 
67 
68 #endif //LEDGER_CORE_AMOUNT_H
std::shared_ptr< api::Amount > toMagnitude(int32_t magnitude) override
Definition: Amount.cpp:105
double toDouble() override
Definition: Amount.cpp:97
api::Currency getCurrency() override
Definition: Amount.cpp:53
int64_t toLong() override
Definition: Amount.cpp:87
Definition: Locale.hpp:13
api::CurrencyUnit getUnit() override
Definition: Amount.cpp:57
std::shared_ptr< api::BigInt > toBigInt() override
Definition: Amount.cpp:49
Definition: Amount.hpp:28
std::shared_ptr< api::Amount > toUnit(const api::CurrencyUnit &unit) override
Definition: Amount.cpp:61
Definition: Currency.hpp:23
Definition: CurrencyUnit.hpp:15
Definition: Account.cpp:8
std::string toString() override
Definition: Amount.cpp:77
Definition: Amount.h:41
Definition: BigInt.h:56
Definition: optional.hpp:177