A container for mapping from one currency code to the conversion ratio of another.
More...
#include <ConversionMap.h>
|
| 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 |
| Determines if the currency conversion ratio exists.
|
|
const std::chrono::system_clock::time_point & | lastFetched () const noexcept |
| Member access for when the conversions were last set.
|
|
void | setConversion (const pecunia::Currency &from, const pecunia::Currency &to, const pecunia::FloatingPoint ratio) |
| Inserts or updates a conversion ratio entry for a given currency to another.
|
|
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()
bool drn::conversion::ConversionMap::hasConversion |
( |
const pecunia::Currency & | from, |
|
|
const pecunia::Currency & | to ) const |
|
nodiscard |
Determines if the currency conversion ratio exists.
- Parameters
-
from | The currency code converting from the given currency. |
to | The currency code to convert to the given currency. |
- Returns
- Gives true when the currency conversion ratio exits to go from a supplied code to another, false else-wise.
◆ 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.
◆ setConversion()
void drn::conversion::ConversionMap::setConversion |
( |
const pecunia::Currency & | from, |
|
|
const pecunia::Currency & | to, |
|
|
const pecunia::FloatingPoint | ratio ) |
Inserts or updates a conversion ratio entry for a given currency to another.
- Exceptions
-
Error | When the supplied from and to currency codes are the same, but the conversion ratio is not an identity. |
- Parameters
-
from | The currency code the ratio is converting from. |
to | The currency code the ratio is converting to. |
ratio | The ratio, when multiplied, converts to the given currency. |