DuxReiNummariae 1.0.0-alpha.23
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.h>

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
 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.
 

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

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

◆ hasConversion()

bool drn::conversion::ConversionMap::hasConversion ( const pecunia::Currency & from,
const pecunia::Currency & to ) const
nodiscard

Determines if the currency conversion ratio exists.

Parameters
fromThe currency code converting from the given currency.
toThe 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:

◆ 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
ErrorWhen the supplied from and to currency codes are the same, but the conversion ratio is not an identity.
Parameters
fromThe currency code the ratio is converting from.
toThe currency code the ratio is converting to.
ratioThe ratio, when multiplied, converts to the given currency.
Here is the call graph for this function:
Here is the caller graph for this function: