🎉」 init: hello world !

This commit is contained in:
2025-08-15 14:48:31 +02:00
commit e72927e52c
13 changed files with 618 additions and 0 deletions

71
ex00/ScalarConverter.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include "ScalarConverter.hpp"
#include "PrintValue.hpp"
ScalarConverter::ScalarConverter(void) {
}
ScalarConverter::ScalarConverter(const ScalarConverter &cpy) {
if (this != &cpy) {
*this = cpy;
}
}
ScalarConverter::~ScalarConverter(void) {
}
ScalarConverter &ScalarConverter::operator=(const ScalarConverter &) {
return *this;
}
bool _isNan(const std::string &str) {
if (str == "nan" || str == "nanf" || str == "-inf" || str == "-inff" ||
str == "+inf" || str == "+inff" || str == "inf" || str == "inff")
return true;
return false;
}
e_type _getType(const std::string &s)
{
if (_isNan(s))
return NAN;
if (s.length() == 1 && !isdigit(s[0]))
return CHAR;
char *err;
(void)strtol(s.c_str(), &err, 10);
if (*err == 0)
return INT;
(void)strtod(s.c_str(), &err);
if (*err == 0)
return DOUBLE;
if (*err == 'f' && *(err + 1) == 0)
return FLOAT;
return NONE;
}
void ScalarConverter::convert(const std::string &s)
{
switch (_getType(s))
{
case CHAR:
_printChar(s);
break;
case INT:
_printInt(s);
break;
case FLOAT:
_printFloat(s);
break;
case DOUBLE:
_printDouble(s);
break;
case NAN:
_printNan(s);
break;
default:
std::cerr << "'" << s << "' does not convert to any of the availables types" << std::endl;
}
}