/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ScalarConverter.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/03 19:59:17 by adjoly #+# #+# */ /* Updated: 2025/04/09 10:31:41 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "ScalarConverter.hpp" #include "GetType.hpp" #include "PrintNb.hpp" #include "StrTo.hpp" void _log(std::string emoji, std::string what, std::string who, std::string str) { #ifdef VERBOSE if (who.empty()) std::cout << "「" << emoji << "」" << what << ": " << str << std::endl; else std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str << std::endl; #else (void)emoji, (void)what, (void)who, (void)str; #endif } ScalarConverter::ScalarConverter(void) { _log("➕", "ScalarConverter", "", "default constructor called"); } ScalarConverter::ScalarConverter(const ScalarConverter &cpy) { _log("➕", "ScalarConverter", "", "copy constructor called"); if (this != &cpy) { *this = cpy; } } ScalarConverter::~ScalarConverter(void) { _log("➖", "ScalarConverter", "", "destructor called"); } ScalarConverter &ScalarConverter::operator=(const ScalarConverter &) { return *this; } void _ConvertNan(const std::string &str) { std::string nb; if (str[0] == 'n') nb = "nan"; else if (str[0] == '-') nb = "-inf"; else nb = "+inf"; std::cout << "char: impossible" << std::endl; std::cout << "int: impossible" << std::endl; std::cout << "float: " << nb << "f" << std::endl; std::cout << "double: " << nb << std::endl; } void ScalarConverter::convert(const std::string &s) { nbType type = GetType(s); switch (type) { case CHAR: _Convert(s); break; case INT: _Convert(s); break; case FLOAT: _Convert(s); break; case DOUBLE: _Convert(s); break; case NAN: _ConvertNan(s); break; case NONE: std::cout << s << " does not convert to any type" << std::endl; break; }; }