d01 ok
This commit is contained in:
38
d01/ex06/Karen.cpp
Normal file
38
d01/ex06/Karen.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include "Karen.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
Karen::Karen() {
|
||||||
|
|
||||||
|
_fp[0] = &Karen::_debug;
|
||||||
|
_fp[1] = &Karen::_info;
|
||||||
|
_fp[2] = &Karen::_warning;
|
||||||
|
_fp[3] = &Karen::_error;
|
||||||
|
|
||||||
|
_level[0] = "DEBUG";
|
||||||
|
_level[1] = "INFO";
|
||||||
|
_level[2] = "WARNING";
|
||||||
|
_level[3] = "ERROR";
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
Karen::~Karen() {return;}
|
||||||
|
|
||||||
|
void Karen::complain( std::string level ) {
|
||||||
|
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = sizeof(this->_level) / sizeof(this->_level[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
if (level.compare(this->_level[i]) == 0)
|
||||||
|
(this->*_fp[i])();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Karen::_debug( void ) {std::cout << "debug" << '\n';}
|
||||||
|
void Karen::_info( void ) {std::cout << "info" << '\n';}
|
||||||
|
void Karen::_warning( void ) {std::cout << "warning" << '\n';}
|
||||||
|
void Karen::_error( void ) {std::cout << "error" << '\n';}
|
||||||
27
d01/ex06/Karen.hpp
Normal file
27
d01/ex06/Karen.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef KAREN_HPP
|
||||||
|
# define KAREN_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Karen {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Karen();
|
||||||
|
~Karen();
|
||||||
|
|
||||||
|
void complain( std::string level );
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void (Karen::*_fp[4])();
|
||||||
|
std::string _level[4];
|
||||||
|
|
||||||
|
void _debug( void );
|
||||||
|
void _info( void );
|
||||||
|
void _warning( void );
|
||||||
|
void _error( void );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
62
d01/ex06/Makefile
Normal file
62
d01/ex06/Makefile
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
# . name = value . name is case sensitive #
|
||||||
|
# VARIABLES . or name = value \ . use VPATH only for .c #
|
||||||
|
# . value . or .cpp #
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
|
||||||
|
NAME = karenFilter
|
||||||
|
|
||||||
|
CC = clang++
|
||||||
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3
|
||||||
|
|
||||||
|
VPATH = $(D_SRCS)
|
||||||
|
|
||||||
|
LIBS =
|
||||||
|
|
||||||
|
INCLUDES = -I$(D_HEADERS)
|
||||||
|
|
||||||
|
D_SRCS = .
|
||||||
|
SRCS = main.cpp \
|
||||||
|
Karen.cpp
|
||||||
|
|
||||||
|
D_HEADERS = .
|
||||||
|
HEADERS = Karen.hpp
|
||||||
|
|
||||||
|
D_OBJS = builds
|
||||||
|
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||||
|
|
||||||
|
RM_D_OBJS = rm -rf $(D_OBJS)
|
||||||
|
ifeq "$(D_OBJS)" "."
|
||||||
|
RM_D_OBJS =
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
# . target: prerequisites . $@ : target #
|
||||||
|
# RULES . recipe . $< : 1st prerequisite #
|
||||||
|
# . recipe . $^ : all prerequisites #
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(D_OBJS)/%.o: %.cpp | $(D_OBJS)
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(D_OBJS):
|
||||||
|
mkdir $@
|
||||||
|
|
||||||
|
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJS)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
rm -f $(NAME)
|
||||||
|
$(RM_D_OBJS)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY : all clean fclean re bonus run valgrind
|
||||||
BIN
d01/ex06/karenFilter
Executable file
BIN
d01/ex06/karenFilter
Executable file
Binary file not shown.
41
d01/ex06/main.cpp
Normal file
41
d01/ex06/main.cpp
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include "Karen.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main(int ac, char *av[])
|
||||||
|
{
|
||||||
|
Karen karen;
|
||||||
|
std::string level[4] = { "DEBUG", "INFO", "WARNING", "ERROR" };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (ac != 2)
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (level[i].compare(av[1]) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case (0):
|
||||||
|
std::cout << "[ DEBUG ]" << '\n';
|
||||||
|
karen.complain("DEBUG");
|
||||||
|
std::cout << '\n';
|
||||||
|
case (1):
|
||||||
|
std::cout << "[ INFO ]" << '\n';
|
||||||
|
karen.complain("INFO");
|
||||||
|
std::cout << '\n';
|
||||||
|
case (2):
|
||||||
|
std::cout << "[ WARNING ]" << '\n';
|
||||||
|
karen.complain("WARNING");
|
||||||
|
std::cout << '\n';
|
||||||
|
case (3):
|
||||||
|
std::cout << "[ ERROR ]" << '\n';
|
||||||
|
karen.complain("ERROR");
|
||||||
|
break ;
|
||||||
|
default:
|
||||||
|
std::cout << "[ Probably complaining about insignificant problems ]" << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user