d01 ex05 ok
This commit is contained in:
38
d01/ex05/Karen.cpp
Normal file
38
d01/ex05/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/ex05/Karen.hpp
Normal file
27
d01/ex05/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/ex05/Makefile
Normal file
62
d01/ex05/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 = karen
|
||||||
|
|
||||||
|
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/ex05/karen
Executable file
BIN
d01/ex05/karen
Executable file
Binary file not shown.
24
d01/ex05/main.cpp
Normal file
24
d01/ex05/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "Karen.hpp"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
Karen karen;
|
||||||
|
|
||||||
|
karen.complain("DEBUG");
|
||||||
|
karen.complain("INFO");
|
||||||
|
karen.complain("WARNING");
|
||||||
|
karen.complain("ERROR");
|
||||||
|
|
||||||
|
karen.complain("debug");
|
||||||
|
karen.complain("info");
|
||||||
|
karen.complain("warning");
|
||||||
|
karen.complain("error");
|
||||||
|
|
||||||
|
std::cout << '\n';
|
||||||
|
|
||||||
|
karen.complain("DEBUG");
|
||||||
|
karen.complain("INFO");
|
||||||
|
karen.complain("WARNING");
|
||||||
|
karen.complain("ERROR");
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user