119 lines
2.9 KiB
C++
119 lines
2.9 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* BitcoinExchange.hpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/05/21 10:38:49 by adjoly #+# #+# */
|
|
/* Updated: 2025/06/03 12:09:58 by adjoly ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#define range(x) \
|
|
x.begin(); \
|
|
it != x.end(); \
|
|
it++
|
|
|
|
#define auto __auto_type
|
|
|
|
typedef unsigned int uint32_t;
|
|
typedef unsigned short uint16_t;
|
|
|
|
void _log(std::string emoji, std::string what, std::string who,
|
|
std::string str);
|
|
|
|
class Date {
|
|
public:
|
|
Date(void);
|
|
Date(std::string);
|
|
Date(const Date &);
|
|
~Date(void);
|
|
|
|
Date &operator=(const Date &);
|
|
|
|
uint32_t getYear(void) const;
|
|
uint16_t getMonth(void) const;
|
|
uint16_t getDay(void) const;
|
|
|
|
bool operator==(const Date &) const;
|
|
bool operator!=(const Date &) const;
|
|
|
|
bool operator<(const Date &) const;
|
|
bool operator>(const Date &) const;
|
|
|
|
bool operator<=(const Date &) const;
|
|
bool operator>=(const Date &) const;
|
|
|
|
protected:
|
|
private:
|
|
static const uint32_t _d_in_m[12];
|
|
|
|
bool _isMonthValid(uint16_t) const;
|
|
bool _isDayValid(uint16_t, uint16_t) const;
|
|
|
|
uint32_t _year;
|
|
uint16_t _month;
|
|
uint16_t _day;
|
|
};
|
|
|
|
std::ostream &operator<<(std::ostream &, const Date &);
|
|
|
|
class CsvParser {
|
|
public:
|
|
CsvParser(void);
|
|
CsvParser(const CsvParser &);
|
|
~CsvParser(void);
|
|
|
|
CsvParser &operator=(const CsvParser &);
|
|
|
|
std::map<Date, float> getCsv(void) const;
|
|
|
|
protected:
|
|
private:
|
|
std::ifstream _is;
|
|
std::string _filename;
|
|
|
|
std::map<Date, float> _csv;
|
|
};
|
|
|
|
class BitcoinExchange {
|
|
public:
|
|
BitcoinExchange(void);
|
|
BitcoinExchange(char *av);
|
|
BitcoinExchange(const BitcoinExchange &);
|
|
~BitcoinExchange(void);
|
|
|
|
BitcoinExchange &operator=(const BitcoinExchange &);
|
|
|
|
void print(void);
|
|
|
|
protected:
|
|
private:
|
|
std::ifstream _is;
|
|
std::string _filename;
|
|
std::string _line;
|
|
CsvParser *_csv;
|
|
|
|
std::pair<Date, float> _parseLine(void);
|
|
void _printPair(std::pair<Date, float>);
|
|
};
|
|
|
|
class CompareDate {
|
|
public:
|
|
CompareDate(Date);
|
|
|
|
bool operator()(const std::pair<Date, float> &pair) const;
|
|
|
|
private:
|
|
Date _date;
|
|
};
|