diff --git a/ex00/BitcoinExchange.cpp b/ex00/BitcoinExchange.cpp index dbe3fce..cf970ee 100644 --- a/ex00/BitcoinExchange.cpp +++ b/ex00/BitcoinExchange.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 10:39:45 by adjoly #+# #+# */ -/* Updated: 2025/06/30 10:54:14 by adjoly ### ########.fr */ +/* Updated: 2025/07/03 13:58:35 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -210,7 +210,7 @@ BitcoinExchange::BitcoinExchange(char *av) : _is(av), _filename(av) { try { _csv = new CsvParser(); } catch (std::exception &e) { - throw e; + throw std::runtime_error("there is a issue with the data.csv"); } if (!_is.is_open()) { @@ -294,18 +294,14 @@ std::pair BitcoinExchange::_parseLine(void) { void BitcoinExchange::_printPair(std::pair pair) { auto map = _csv->getCsv(); - auto it = std::find_if(map.begin(), map.end(), CompareDate(pair.first)); - if (it == map.end()) { - delete _csv; - throw std::out_of_range("out of range"); + auto itDate = map.begin(); + for (auto it = range(map)) { + if (it->first >= pair.first) { + break; + } + itDate = it; } - float i = it->second * pair.second; + float i = itDate->second * pair.second; std::cout << pair.first << " => " << pair.second << " = " << i << std::endl; } - -CompareDate::CompareDate(Date date) : _date(date) {} - -bool CompareDate::operator()(const std::pair &pair) const { - return pair.first >= _date; -} diff --git a/ex00/BitcoinExchange.hpp b/ex00/BitcoinExchange.hpp index a0889c9..67c6d02 100644 --- a/ex00/BitcoinExchange.hpp +++ b/ex00/BitcoinExchange.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 10:38:49 by adjoly #+# #+# */ -/* Updated: 2025/06/03 12:09:58 by adjoly ### ########.fr */ +/* Updated: 2025/07/03 13:54:16 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,13 +106,3 @@ class BitcoinExchange { std::pair _parseLine(void); void _printPair(std::pair); }; - -class CompareDate { - public: - CompareDate(Date); - - bool operator()(const std::pair &pair) const; - - private: - Date _date; -}; diff --git a/ex00/main.cpp b/ex00/main.cpp index 4f515da..6abe654 100644 --- a/ex00/main.cpp +++ b/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 10:34:50 by adjoly #+# #+# */ -/* Updated: 2025/06/30 10:52:15 by adjoly ### ########.fr */ +/* Updated: 2025/07/03 13:52:10 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ int main(int ac, char **av) { try { btc = new BitcoinExchange(av[1]); btc->print(); - } catch (std::runtime_error &e) { + } catch (std::exception &e) { btc = NULL; std::cout << e.what() << std::endl; }