」 feat: should have finished ex00

This commit is contained in:
2025-04-09 10:33:31 +02:00
parent 2b51c0baca
commit df7ffd0aeb
10 changed files with 198 additions and 29 deletions

View File

@ -6,11 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/03 19:59:17 by adjoly #+# #+# */
/* Updated: 2025/04/08 14:17:44 by adjoly ### ########.fr */
/* 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) {
@ -40,8 +43,47 @@ ScalarConverter::~ScalarConverter(void) {
_log("", "ScalarConverter", "", "destructor called");
}
ScalarConverter &ScalarConverter::operator=(const ScalarConverter &) { return *this; }
void ScalarConverter::convert(std::string &s) {
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<char>(s);
break;
case INT:
_Convert<int>(s);
break;
case FLOAT:
_Convert<float>(s);
break;
case DOUBLE:
_Convert<double>(s);
break;
case NAN:
_ConvertNan(s);
break;
case NONE:
std::cout << s << " does not convert to any type" << std::endl;
break;
};
}