Handles currency conversion with automatic exchange rate updates from API.
More...
#include <CurrencyConverter.h>
|
| double | convert (double amount, const std::string &from, const std::string &to) |
| |
| void | updateRate (const std::string ¤cy, double rate) |
| |
| bool | fetchRatesFromAPI (const std::string &base="") |
| | Fetches exchange rates from the configured API.
|
| |
| bool | fetchRatesForCurrencies (const std::vector< std::string > ¤cies, const std::string &base="") |
| | Fetches exchange rates for specific currencies.
|
| |
| void | fetchRatesFromAPIAsync (std::function< void(bool)> callback, const std::string &base="") |
| |
| bool | updateRatesIfNeeded () |
| | Automatically updates rates if cache has expired.
|
| |
| void | setApiUrl (const std::string &url) |
| | Sets a custom API URL (for different exchange rate providers)
|
| |
| void | setApiKey (const std::string &key) |
| | Sets API key for services that require authentication.
|
| |
| bool | isCacheValid () const |
| | Checks if cached rates are still valid.
|
| |
Handles currency conversion with automatic exchange rate updates from API.
Supports fetching exchange rates from external APIs and converting between currencies. Uses cpr (C++ Requests) library for HTTP requests to banking/financial APIs.
◆ convert()
| double CurrencyConverter::convert |
( |
double |
amount, |
|
|
const std::string & |
from, |
|
|
const std::string & |
to |
|
) |
| |
|
inline |
◆ fetchRatesForCurrencies()
| bool CurrencyConverter::fetchRatesForCurrencies |
( |
const std::vector< std::string > & |
currencies, |
|
|
const std::string & |
base = "" |
|
) |
| |
Fetches exchange rates for specific currencies.
- Parameters
-
| currencies | Vector of currency codes to fetch |
| base | Base currency code (default: uses baseCurrency member) |
- Returns
- true if rates were successfully fetched
◆ fetchRatesFromAPI()
| bool CurrencyConverter::fetchRatesFromAPI |
( |
const std::string & |
base = "" | ) |
|
Fetches exchange rates from the configured API.
- Parameters
-
| base | Base currency code (default: uses baseCurrency member) |
- Returns
- true if rates were successfully fetched and updated
◆ fetchRatesFromAPIAsync()
| void CurrencyConverter::fetchRatesFromAPIAsync |
( |
std::function< void(bool)> |
callback, |
|
|
const std::string & |
base = "" |
|
) |
| |
◆ isCacheValid()
| bool CurrencyConverter::isCacheValid |
( |
| ) |
const |
|
inline |
Checks if cached rates are still valid.
- Returns
- true if rates are fresh (within cache timeout)
◆ setApiKey()
| void CurrencyConverter::setApiKey |
( |
const std::string & |
key | ) |
|
|
inline |
Sets API key for services that require authentication.
- Parameters
-
◆ setApiUrl()
| void CurrencyConverter::setApiUrl |
( |
const std::string & |
url | ) |
|
|
inline |
Sets a custom API URL (for different exchange rate providers)
- Parameters
-
◆ updateRate()
| void CurrencyConverter::updateRate |
( |
const std::string & |
currency, |
|
|
double |
rate |
|
) |
| |
|
inline |
◆ updateRatesIfNeeded()
| bool CurrencyConverter::updateRatesIfNeeded |
( |
| ) |
|
Automatically updates rates if cache has expired.
- Returns
- true if rates were updated (or already fresh)
◆ apiKey
| std::string CurrencyConverter::apiKey |
◆ apiUrl
| std::string CurrencyConverter::apiUrl = "https://api.exchangerate-api.com/v4/latest/" |
◆ baseCurrency
| std::string CurrencyConverter::baseCurrency = "USD" |
◆ cacheTimeout
| std::chrono::minutes CurrencyConverter::cacheTimeout {60} |
◆ exchangeRate
| std::map<std::string, double> CurrencyConverter::exchangeRate |
◆ lastUpdate
| std::chrono::system_clock::time_point CurrencyConverter::lastUpdate |
The documentation for this class was generated from the following files: