/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Converter.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */ /* Updated: 2022/08/18 08:54:04 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "Converter.hpp" using std::cout; using std::endl; Converter::Converter(void) { cout << "Converter default constructor called " << endl; } Converter::Converter(string str) { if (str[0] == '\'' || str[0] == '"') { _c = str[1]; cout << "Char: " << _c << endl; _d = static_cast(_c); } else { cout << "Char: "; _d = std::strtod(str.c_str(), 0); _c = static_cast(_d); if (_d < 0 || _d > 255) cout << "Invalid" << endl; else if (isnan(_d)) cout << "Impossible" << endl; else if (!std::isprint(_c)) cout << "Not Printable" << endl; else cout << "'" << _c << "'" << endl; } cout << "Integer: "; _i = static_cast(_d); if (_d < std::numeric_limits::min() || _d > std::numeric_limits::max()) cout << "Off limits -> "; if (std::isnan(_d)) cout << "Impossible" << endl; else cout << _i << endl; _f = static_cast(_d); if (_d == 0 || _d / static_cast(_d) == 1) { cout << "Double: " << std::setprecision(1) << std::fixed << _d<< endl; cout << "Float: " << std::setprecision(1) << std::fixed << _f << "f" << endl; } else { cout << "Double: " << _d << endl; cout << "Float: " << _f << "f" << endl; } } Converter::Converter(Converter const &src) { (void)src; cout << "Converter copy constructor called" << endl; } Converter &Converter::operator=(Converter const &src) { (void)src; cout << "Converter assignment operator called" << endl; return (*this); } Converter::~Converter(void) { cout << "Converter default destructor called" << endl; }