DuxReiNummariae 1.1.0-alpha.19
Simple and powerful budgeting application
Loading...
Searching...
No Matches
drn::conversion::ConversionMap Class Referencefinal

A container for mapping from one currency code to the conversion ratio of another. More...

#include <ConversionMap.hpp>

Inheritance diagram for drn::conversion::ConversionMap:
Collaboration diagram for drn::conversion::ConversionMap:

Public Member Functions

 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.

Detailed Description

A container for mapping from one currency code to the conversion ratio of another.

Constructor & Destructor Documentation

◆ 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
lastFetchedThe point at which the conversions were last fetched.
ratiosThe mapping of rations from one currency to another.
Here is the call graph for this function:

Member Function Documentation

◆ 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
ErrorThrown if the conversion between the source and target currencies does not exist.
Parameters
fromThe source currency for the conversion.
toThe 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
fromThe 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 AllowExpiredConversion & shouldAllowExpired = AllowExpiredConversion{false} ) const
nodiscardnoexcept

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
fromThe currency code representing the source currency to convert from.
toThe currency code representing the target currency to convert to.
shouldAllowExpiredSpecifies 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ 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
ErrorWhen the supplied from and to currency codes are the same, but the conversion ratio is not an identity.
Parameters
fromThe source currency for the conversion.
toThe target currency for the conversion.
ratioThe numerical rate of conversion from the source currency to the target currency.
isRateLookedUpA 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.