A container for mapping from one currency code to the conversion ratio of another.
More...
#include <ConversionMap.hpp>
|
| | ConversionMap () |
| | Initialisation constructor populated with the unknown currency code conversion rate.
|
| | ConversionMap (std::chrono::system_clock::time_point lastFetched, std::map< pecunia::Currency, std::map< pecunia::Currency, pecunia::FloatingPoint > > ratios) |
| | Initialisation constructor populated with the supplied conversion rates.
|
| const pecunia::FloatingPoint & | conversion (const pecunia::Currency &from, const pecunia::Currency &to) const |
| | Retrieves the conversion ratio between two currencies.
|
| const std::map< pecunia::Currency, pecunia::FloatingPoint > & | conversions (const pecunia::Currency &from) const noexcept |
| | Retrieves the conversion mappings for a specified currency.
|
| bool | hasConversion (const pecunia::Currency &from, const pecunia::Currency &to, const AllowExpiredConversion &shouldAllowExpired=AllowExpiredConversion{false}) const noexcept |
| | Checks if a conversion exists between two specified currencies.
|
| bool | isExpired () const noexcept |
| | Determines whether the conversion data in the map has expired.
|
| const std::chrono::system_clock::time_point & | lastFetched () const noexcept |
| | Member access for when the conversions were last set.
|
| void | updateConversion (const pecunia::Currency &from, const pecunia::Currency &to, const pecunia::FloatingPoint ratio, const RateLookedUp &isRateLookedUp=RateLookedUp{false}) |
| | Updates the conversion ratio between two currencies.
|
A container for mapping from one currency code to the conversion ratio of another.
◆ ConversionMap() [1/2]
| drn::conversion::ConversionMap::ConversionMap |
( |
| ) |
|
Initialisation constructor populated with the unknown currency code conversion rate.
◆ ConversionMap() [2/2]
| drn::conversion::ConversionMap::ConversionMap |
( |
std::chrono::system_clock::time_point | lastFetched, |
|
|
std::map< pecunia::Currency, std::map< pecunia::Currency, pecunia::FloatingPoint > > | ratios ) |
Initialisation constructor populated with the supplied conversion rates.
- Parameters
-
| lastFetched | The point at which the conversions were last fetched. |
| ratios | The mapping of rations from one currency to another. |
◆ conversion()
| const pecunia::FloatingPoint & drn::conversion::ConversionMap::conversion |
( |
const pecunia::Currency & | from, |
|
|
const pecunia::Currency & | to ) const |
|
nodiscard |
Retrieves the conversion ratio between two currencies.
- Exceptions
-
| Error | Thrown if the conversion between the source and target currencies does not exist. |
- Parameters
-
| from | The source currency for the conversion. |
| to | The target currency for the conversion. |
- Returns
- The conversion ratio from the source currency to the target currency.
◆ conversions()
| const std::map< pecunia::Currency, pecunia::FloatingPoint > & drn::conversion::ConversionMap::conversions |
( |
const pecunia::Currency & | from | ) |
const |
|
nodiscardnoexcept |
Retrieves the conversion mappings for a specified currency.
- Parameters
-
| from | The currency for which the conversion mappings are to be retrieved. |
- Returns
- The container holding the conversion ratios for the specified currency.
◆ hasConversion()
Checks if a conversion exists between two specified currencies.
It determines whether a conversion ratio can be found from the given source currency to the target currency. It also ensures that the conversion data is up-to-date and has not expired.
- Parameters
-
| from | The currency code representing the source currency to convert from. |
| to | The currency code representing the target currency to convert to. |
| shouldAllowExpired | Specifies whether expired mappings are permitted when checking for the existence of the conversion. |
- Returns
- True if a valid conversion between the source and target currencies exists, considering the allowance for expired mappings; otherwise, false.
◆ isExpired()
| bool drn::conversion::ConversionMap::isExpired |
( |
| ) |
const |
|
nodiscardnoexcept |
Determines whether the conversion data in the map has expired.
It evaluates if the conversion mappings stored within the map are outdated based on the last time they were fetched.
- Returns
- True if the conversion data has expired and may no longer be considered valid; otherwise, false.
◆ lastFetched()
| const std::chrono::system_clock::time_point & drn::conversion::ConversionMap::lastFetched |
( |
| ) |
const |
|
nodiscardnoexcept |
Member access for when the conversions were last set.
- Returns
- The time-point the fetch occurred.
◆ updateConversion()
| void drn::conversion::ConversionMap::updateConversion |
( |
const pecunia::Currency & | from, |
|
|
const pecunia::Currency & | to, |
|
|
const pecunia::FloatingPoint | ratio, |
|
|
const RateLookedUp & | isRateLookedUp = RateLookedUp{false} ) |
Updates the conversion ratio between two currencies.
- Exceptions
-
| Error | When the supplied from and to currency codes are the same, but the conversion ratio is not an identity. |
- Parameters
-
| from | The source currency for the conversion. |
| to | The target currency for the conversion. |
| ratio | The numerical rate of conversion from the source currency to the target currency. |
| isRateLookedUp | A flag indicating whether the rate was retrieved through a lookup or is predefined. |
- Postcondition
- The conversion mapping for the given from and to currencies will be updated or created.
-
When rate look up flag is true, the internal timestamp for the last fetched rate will be updated.