fichiers organisés
This commit is contained in:
@@ -28,11 +28,16 @@ LIBS =
|
||||
|
||||
INCLUDES = -I$(D_HEADERS)
|
||||
|
||||
D_SRCS = .
|
||||
SRCS = main.cpp
|
||||
D_SRCS = srcs
|
||||
SRCS = main.cpp \
|
||||
convert.cpp \
|
||||
checkChar.cpp \
|
||||
checkInt.cpp \
|
||||
checkFloat.cpp \
|
||||
checkDouble.cpp
|
||||
|
||||
D_HEADERS = .
|
||||
HEADERS =
|
||||
HEADERS = color.h
|
||||
|
||||
D_OBJS = builds
|
||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
||||
|
||||
BIN
d06/ex00/convert
BIN
d06/ex00/convert
Binary file not shown.
@@ -1,8 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "color.h"
|
||||
|
||||
#include <cctype> // isdigit()
|
||||
void convert(std::string str);
|
||||
|
||||
// 2^24 = 16777216;
|
||||
// 2^31 = 2147483648
|
||||
@@ -14,79 +13,6 @@
|
||||
#define MIN_INT_1 "-2147483649"
|
||||
#define MAX_FLOAT_INT_PRECISION "16777216"
|
||||
|
||||
//Char toChar(str) {
|
||||
//
|
||||
//}
|
||||
|
||||
//bool isChar() {}
|
||||
|
||||
bool checkChar(std::string str) {
|
||||
// char c;
|
||||
//
|
||||
std::cout << "in char\n";
|
||||
if (str.length() != 1 || isdigit(str[0]))
|
||||
return false;
|
||||
//
|
||||
// c = toChar(str);
|
||||
// std::cout << "char"RESET" equal to : "B_CYAN << c << RESET << "\n";
|
||||
// fromChar(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkInt(std::string str) {
|
||||
std::cout << "in int\n";
|
||||
if (str.length() == 1 || !isdigit(str[0]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkFloat(std::string str) {
|
||||
std::cout << "in int\n";
|
||||
if (str.length() == 1 || !isdigit(str[0]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool (*checkFunc[])(std::string str) =
|
||||
{
|
||||
checkChar,
|
||||
checkInt,
|
||||
checkFloat
|
||||
};
|
||||
|
||||
void convert(std::string str) {
|
||||
|
||||
int size = sizeof(checkFunc) / sizeof(checkFunc[0]);
|
||||
|
||||
// std::cout << str << " is a "B_YELLOW ;
|
||||
|
||||
for (int it = 0; it < size; it++)
|
||||
if ((*checkFunc[it])(str))
|
||||
break;
|
||||
|
||||
// else if (isInt(str))
|
||||
// {
|
||||
// i = toInt(str);
|
||||
// std::cout << "int"RESET" equal to : "B_CYAN << i << RESET << "\n";
|
||||
// fromInt(i);
|
||||
// }
|
||||
// else if (isFloat(str))
|
||||
// {
|
||||
// f = toFloat(str);
|
||||
// std::cout << "float"RESET" equal to : "B_CYAN << f << RESET << "\n";
|
||||
// fromFloat(f);
|
||||
// }
|
||||
// else if (isDouble(str))
|
||||
// {
|
||||
// d = toDouble(str);
|
||||
// std::cout << "double"RESET" equal to : "B_CYAN << d << RESET << "\n";
|
||||
// fromDouble(d);
|
||||
// }
|
||||
// else
|
||||
// std::cout << B_RED"not valid type"RESET"\n";
|
||||
}
|
||||
|
||||
int main(int ac, char **av) {
|
||||
|
||||
if (ac > 1)
|
||||
|
||||
30
d06/ex00/srcs/checkChar.cpp
Normal file
30
d06/ex00/srcs/checkChar.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype> // isdigit()
|
||||
#include "color.h"
|
||||
|
||||
//Char toChar(str) {
|
||||
//
|
||||
//}
|
||||
|
||||
bool isChar(std::string str) {
|
||||
if (str.length() != 1 || isdigit(str[0]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkChar(std::string str) {
|
||||
|
||||
// char c;
|
||||
|
||||
std::cout << "char\n";
|
||||
|
||||
if (str.length() != 1 || isdigit(str[0]))
|
||||
return false;
|
||||
|
||||
// c = toChar(str);
|
||||
// std::cout << "char"RESET" equal to : "B_CYAN << c << RESET << "\n";
|
||||
// fromChar(c);
|
||||
|
||||
return true;
|
||||
}
|
||||
29
d06/ex00/srcs/checkDouble.cpp
Normal file
29
d06/ex00/srcs/checkDouble.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype> // isdigit()
|
||||
#include "color.h"
|
||||
|
||||
//Char toChar(str) {
|
||||
//
|
||||
//}
|
||||
|
||||
bool isDouble(std::string str) {
|
||||
if (str.length() == 3)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkDouble(std::string str) {
|
||||
|
||||
// double d;
|
||||
|
||||
std::cout << "double\n";
|
||||
|
||||
if (!isDouble(str))
|
||||
return false;
|
||||
|
||||
// d = toDouble(str);
|
||||
// std::cout << "double"RESET" equal to : "B_CYAN << d << RESET << "\n";
|
||||
// fromDouble(d);
|
||||
return true;
|
||||
}
|
||||
30
d06/ex00/srcs/checkFloat.cpp
Normal file
30
d06/ex00/srcs/checkFloat.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype> // isdigit()
|
||||
#include "color.h"
|
||||
|
||||
//Char toChar(str) {
|
||||
//
|
||||
//}
|
||||
|
||||
bool isFloat(std::string str) {
|
||||
if (str.length() == 4)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkFloat(std::string str) {
|
||||
|
||||
// float f;
|
||||
|
||||
std::cout << "in char\n";
|
||||
|
||||
if (!isFloat(str))
|
||||
return false;
|
||||
|
||||
// f = toFloat(str);
|
||||
// std::cout << "float"RESET" equal to : "B_CYAN << f << RESET << "\n";
|
||||
// fromFloat(f);
|
||||
|
||||
return true;
|
||||
}
|
||||
30
d06/ex00/srcs/checkInt.cpp
Normal file
30
d06/ex00/srcs/checkInt.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cctype> // isdigit()
|
||||
#include "color.h"
|
||||
|
||||
//Char toInt(str) {
|
||||
//
|
||||
//}
|
||||
|
||||
bool isInt(std::string str) {
|
||||
if (str.length() == 2)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkInt(std::string str) {
|
||||
|
||||
// int i;
|
||||
|
||||
std::cout << "int\n";
|
||||
|
||||
if (!isInt(str))
|
||||
return false;
|
||||
|
||||
// i = toInt(str);
|
||||
// std::cout << "int"RESET" equal to : "B_CYAN << i << RESET << "\n";
|
||||
// fromInt(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
31
d06/ex00/srcs/convert.cpp
Normal file
31
d06/ex00/srcs/convert.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "color.h"
|
||||
|
||||
bool checkChar(std::string str);
|
||||
bool checkInt(std::string str);
|
||||
bool checkFloat(std::string str);
|
||||
bool checkDouble(std::string str);
|
||||
|
||||
bool isElse(std::string str) {
|
||||
std::cout << str << B_RED " is not valid type for this exercise" RESET "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool (*checkFunc[])(std::string str) =
|
||||
{
|
||||
checkChar,
|
||||
checkInt,
|
||||
checkFloat,
|
||||
checkDouble,
|
||||
isElse
|
||||
};
|
||||
|
||||
void convert(std::string str) {
|
||||
|
||||
int size = sizeof(checkFunc) / sizeof(checkFunc[0]);
|
||||
|
||||
for (int it = 0; it < size; it++)
|
||||
if ((*checkFunc[it])(str))
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user