70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* BitcoinExchange.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/04/23 19:54:20 by aortigos #+# #+# */
|
|
/* Updated: 2026/04/23 19:54:20 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "BitcoinExchange.hpp"
|
|
|
|
//////////////////
|
|
// Constructors //
|
|
//////////////////
|
|
|
|
BitcoinExchange::BitcoinExchange()
|
|
{
|
|
// std::cout << "BitcoinExchange default constructor called" << std::endl;
|
|
}
|
|
|
|
BitcoinExchange::BitcoinExchange(const BitcoinExchange &other)
|
|
{
|
|
*this = other;
|
|
// std::cout << "BitcoinExchange copy constructor called" << std::endl;
|
|
}
|
|
|
|
BitcoinExchange& BitcoinExchange::operator=(const BitcoinExchange &other)
|
|
{
|
|
if (this != &other)
|
|
{
|
|
this->data = other.data;
|
|
}
|
|
// std::cout << "BitcoinExchange copy assignment operator called" << std::endl;
|
|
return (*this);
|
|
}
|
|
|
|
BitcoinExchange::~BitcoinExchange()
|
|
{
|
|
// std::cout << "BitcoinExchange destructor called" << std::endl;
|
|
}
|
|
|
|
|
|
void BitcoinExchange::readDatabase(std::ifstream &db)
|
|
{
|
|
std::string line;
|
|
std::getline(db, line);
|
|
|
|
if (line != "date,exchange_rate")
|
|
throw std::exception();
|
|
|
|
size_t pos;
|
|
std::string date;
|
|
std::string price;
|
|
|
|
while (std::getline(db, line))
|
|
{
|
|
pos = line.find(',');
|
|
if (pos == std::string::npos)
|
|
continue ;
|
|
date = line.substr(0, pos);
|
|
price = line.substr(pos + 1);
|
|
|
|
|
|
this->data[date] = std::strtod(price.c_str(), NULL);
|
|
}
|
|
|
|
} |