narnaud
3 years ago
25 changed files with 724 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||
NAME = apocalypse |
|||
SRCS = main.cpp Zombie.cpp newZombie.cpp randomChump.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME): $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all: $(NAME) |
|||
|
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re: fclean all |
|||
|
|||
.PHONY: all clean re |
@ -0,0 +1,28 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Zombie.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:53:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 09:45:30 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Zombie.hpp" |
|||
|
|||
Zombie::Zombie(string name):_name(name) |
|||
{ |
|||
cout << "*" << name << " died.*\n"; |
|||
} |
|||
|
|||
Zombie::~Zombie(void) |
|||
{ |
|||
cout << "*" << this->_name << " really died.*\n"; |
|||
} |
|||
|
|||
void Zombie::announce(void) const |
|||
{ |
|||
cout << this->_name << ": BraiiiiiiinnnzzzZ...\n"; |
|||
} |
@ -0,0 +1,37 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Zombie.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:02:30 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 09:49:11 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
#ifndef ZOMBIE_HPP |
|||
# define ZOMBIE_HPP |
|||
|
|||
# ifndef DEBUG |
|||
# define DEBUG 0 |
|||
# endif |
|||
|
|||
#include <iostream> |
|||
using std::cin; |
|||
using std::cout; |
|||
using std::string; |
|||
|
|||
class Zombie |
|||
{ |
|||
public: |
|||
Zombie(string name); |
|||
~Zombie(); |
|||
void announce(void) const; |
|||
private: |
|||
string _name; |
|||
}; |
|||
|
|||
Zombie *newZombie(string name); |
|||
void randomChump(string name); |
|||
|
|||
#endif |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 07:59:29 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 09:46:09 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
# include "Zombie.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
Zombie *marc = newZombie("Marc"); |
|||
marc->announce(); |
|||
delete marc; |
|||
randomChump("Aurel"); |
|||
if (DEBUG) |
|||
system("leaks apocalypse"); |
|||
return (EXIT_SUCCESS); |
|||
} |
@ -0,0 +1,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* newZombie.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:17:02 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 09:43:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Zombie.hpp" |
|||
|
|||
Zombie *newZombie(string name) |
|||
{ |
|||
Zombie *ret = new Zombie(name); |
|||
return (ret); |
|||
} |
@ -0,0 +1,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* randomChump.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:18:57 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 09:43:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Zombie.hpp" |
|||
|
|||
void randomChump(string name) |
|||
{ |
|||
Zombie zomb = Zombie(name); |
|||
zomb.announce(); |
|||
} |
@ -0,0 +1,19 @@ |
|||
NAME = apocalypse |
|||
SRCS = main.cpp Zombie.cpp zombieHorde.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
CXXFLAGS = -g -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME): $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all: $(NAME) |
|||
|
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re: clean all |
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,35 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Zombie.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:53:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 12:43:16 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Zombie.hpp" |
|||
|
|||
Zombie::Zombie(){} |
|||
|
|||
Zombie::Zombie(string name):_name(name) |
|||
{ |
|||
cout << "*" << _name << " died.*\n"; |
|||
} |
|||
|
|||
Zombie::~Zombie(void) |
|||
{ |
|||
cout << "*" << _name << " really died.*\n"; |
|||
} |
|||
|
|||
void Zombie::announce(void) const |
|||
{ |
|||
cout << _name << ": BraiiiiiiinnnzzzZ...\n"; |
|||
} |
|||
|
|||
void Zombie::setName(string name) |
|||
{ |
|||
_name = name; |
|||
} |
@ -0,0 +1,39 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Zombie.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:02:30 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 12:27:01 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
#ifndef ZOMBIE_HPP |
|||
# define ZOMBIE_HPP |
|||
|
|||
# ifndef DEBUG |
|||
# define DEBUG 0 |
|||
# endif |
|||
# define ZB_AMOUNT 8 |
|||
|
|||
#include <iostream> |
|||
using std::cin; |
|||
using std::cout; |
|||
using std::string; |
|||
|
|||
class Zombie |
|||
{ |
|||
public: |
|||
Zombie(void); |
|||
Zombie(string name); |
|||
~Zombie(); |
|||
void announce(void) const; |
|||
void setName(string name); |
|||
private: |
|||
string _name; |
|||
}; |
|||
|
|||
Zombie *zombieHorde(int amount, string name); |
|||
|
|||
#endif |
Binary file not shown.
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 07:59:29 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 12:44:26 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
# include "Zombie.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
Zombie *zombs = zombieHorde(ZB_AMOUNT, "Zombie"); |
|||
int i = 0; |
|||
|
|||
while (i < ZB_AMOUNT) |
|||
zombs[i++].announce(); |
|||
delete [] zombs; |
|||
if (DEBUG) |
|||
system("leaks apocalypse"); |
|||
return (EXIT_SUCCESS); |
|||
} |
@ -0,0 +1,25 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* zombieHorde.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 08:17:02 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 12:47:20 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Zombie.hpp" |
|||
|
|||
Zombie *zombieHorde(int N, string name) |
|||
{ |
|||
Zombie *ret = new Zombie[N]; |
|||
int n = 0; |
|||
while (n < N) |
|||
{ |
|||
ret[n].setName(name + std::to_string(n)); |
|||
n++; |
|||
} |
|||
return (ret); |
|||
} |
@ -0,0 +1,31 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 11:01:07 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/14 11:08:21 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include <iostream> |
|||
using std::string; |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
int main(void) |
|||
{ |
|||
string str = "HI THIS IS BRAIN"; |
|||
string *stringPTR = &str; |
|||
string &stringREF = str; |
|||
|
|||
cout << &str << endl; |
|||
cout << stringPTR << endl; |
|||
cout << &stringREF << endl; |
|||
|
|||
cout << str << endl; |
|||
cout << *stringPTR << endl; |
|||
cout << stringREF << endl; |
|||
} |
@ -0,0 +1,20 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* HumanA.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 13:34:06 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:10:29 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "HumanA.hpp" |
|||
|
|||
HumanA::HumanA(string name, Weapon & weap ):_name(name),_weapon(weap){} |
|||
|
|||
void HumanA::attack(void) const |
|||
{ |
|||
std::cout << _name << " attacks with their " << _weapon.getType() << endl; |
|||
} |
@ -0,0 +1,28 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* HumanA.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 12:52:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:33:40 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#ifndef HUMANA_HPP |
|||
# define HUMANA_HPP |
|||
|
|||
# include "Weapon.hpp" |
|||
|
|||
class HumanA |
|||
{ |
|||
public: |
|||
HumanA(string name, Weapon &weap); |
|||
void attack(void) const; |
|||
private: |
|||
string _name; |
|||
Weapon &_weapon; |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* HumanB.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/16 09:13:28 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:12:56 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "HumanB.hpp" |
|||
|
|||
|
|||
HumanB::HumanB(string name):_name(name), _weapon(NULL){} |
|||
|
|||
HumanB::HumanB(string name, Weapon &weap):_name(name), _weapon(&weap){} |
|||
|
|||
|
|||
void HumanB::attack(void) const |
|||
{ |
|||
std::cout << _name << " attacks with their "; |
|||
if (_weapon) |
|||
cout << _weapon->getType() << endl; |
|||
else |
|||
cout << "fists\n"; |
|||
} |
|||
|
|||
void HumanB::setWeapon(Weapon &weap) |
|||
{ |
|||
_weapon = &weap; |
|||
} |
@ -0,0 +1,30 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* HumanB.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 12:54:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:33:28 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#ifndef HUMANB_HPP |
|||
# define HUMANB_HPP |
|||
|
|||
# include "Weapon.hpp" |
|||
|
|||
class HumanB |
|||
{ |
|||
public: |
|||
HumanB(string name); |
|||
HumanB(string name, Weapon &weap); |
|||
void attack(void) const; |
|||
void setWeapon(Weapon &weap); |
|||
private: |
|||
string _name; |
|||
Weapon *_weapon; |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,21 @@ |
|||
NAME = warfare |
|||
|
|||
SRCS = main.cpp Weapon.cpp HumanA.cpp HumanB.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME): $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all: $(NAME) |
|||
|
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re: fclean all |
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Weapon.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 12:51:23 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:08:02 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Weapon.hpp" |
|||
|
|||
Weapon::Weapon(string type):_type(type){} |
|||
|
|||
const string &Weapon::getType(void) const |
|||
{ |
|||
return (this->_type); |
|||
} |
|||
|
|||
void Weapon::setType(string type) |
|||
{ |
|||
this->_type = type; |
|||
} |
|||
|
@ -0,0 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Weapon.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 12:50:31 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:04:50 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
#ifndef WEAPON_HPP |
|||
# define WEAPON_HPP |
|||
|
|||
# include <iostream> |
|||
|
|||
using std::string; |
|||
using std::cout; |
|||
using std::cin; |
|||
using std::endl; |
|||
|
|||
class Weapon |
|||
{ |
|||
public: |
|||
Weapon(void); |
|||
Weapon(string type); |
|||
const string &getType(void) const; |
|||
void setType(string type); |
|||
private: |
|||
string _type; |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,34 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/14 12:55:24 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/16 10:02:39 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "HumanA.hpp" |
|||
#include "HumanB.hpp" |
|||
|
|||
int main() |
|||
{ |
|||
{ |
|||
Weapon club = Weapon("crude spiked club"); |
|||
HumanA bob("Bob", club); |
|||
bob.attack(); |
|||
club.setType("some other type of club"); |
|||
bob.attack(); |
|||
} |
|||
{ |
|||
Weapon club = Weapon("crude spiked club"); |
|||
HumanB jim("Jim"); |
|||
jim.setWeapon(club); |
|||
jim.attack(); |
|||
club.setType("some other type of club"); |
|||
jim.attack(); |
|||
} |
|||
return 0; |
|||
} |
@ -0,0 +1,54 @@ |
|||
/*
|
|||
* my_sed(argc,argv) |
|||
* filename = argv[1]; |
|||
* s1 = argv[2]; |
|||
* s2 = argv[3]; |
|||
* input::ifstream ifs; |
|||
* input = open(filename, std::ifstream::in); |
|||
* |
|||
* |
|||
* |
|||
* */ |
|||
|
|||
|
|||
#include <iostream> |
|||
#include <fstream> |
|||
using std::string; |
|||
using std::ifstream; |
|||
using std::ofstream; |
|||
|
|||
|
|||
int main(int argc, char **argv) |
|||
{ |
|||
string text; |
|||
string buffer; |
|||
string filename; |
|||
string oldStr; |
|||
string newStr; |
|||
int oldLen; |
|||
int i = 0, fileLen = 0; |
|||
|
|||
if (argc != 4) |
|||
return (EXIT_FAILURE); |
|||
ifstream input(argv[1]); |
|||
oldStr = argv[2]; |
|||
newStr = argv[3]; |
|||
while (getline(input, buffer)) |
|||
text += buffer; |
|||
input.close(); |
|||
fileLen = text.length(); |
|||
oldLen = oldStr.length(); |
|||
while (i < fileLen) |
|||
{ |
|||
i = text.find(oldStr, i); |
|||
if (i == -1) |
|||
break ; |
|||
text.erase(i, oldLen); |
|||
text.insert(i, newStr); |
|||
} |
|||
filename = argv[1]; |
|||
ofstream output(filename.append(".replace")); |
|||
output << text; |
|||
output.close(); |
|||
return (EXIT_SUCCESS); |
|||
} |
@ -0,0 +1,66 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Harl.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/17 11:14:29 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/17 13:29:12 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Harl.hpp" |
|||
|
|||
Harl::Harl (void) { |
|||
std::cout << "Harl default constructor called " << std::endl; |
|||
} |
|||
|
|||
Harl::Harl (Harl const & src) { |
|||
|
|||
std::cout << "Harl copy constructor called" << std::endl; |
|||
} |
|||
|
|||
Harl & Harl::operator= (Harl const & src) { |
|||
|
|||
std::cout << "Harl assignment operator called" << std::endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Harl::~Harl (void) { |
|||
|
|||
std::cout << "Harl default destructor called" << std::endl; |
|||
} |
|||
|
|||
void Harl::_debug(void) |
|||
{ |
|||
std::cout << "Debug : ..." << std::endl; |
|||
} |
|||
|
|||
void Harl::_info(void) |
|||
{ |
|||
std::cout << "Info: ..." << std::endl; |
|||
} |
|||
|
|||
void Harl::_warning(void) |
|||
{ |
|||
std::cout << "Warning: ..." << std::endl; |
|||
} |
|||
|
|||
void Harl::_error(void) |
|||
{ |
|||
std::cout << "Error: ..." << std::endl; |
|||
} |
|||
|
|||
void Harl::_complain(string level) { |
|||
|
|||
void (Harl::*fcts[])(void) = { |
|||
&Harl::_debug, &Harl::_info, &Harl::_warning, &Harl::_error}; |
|||
string ids = "DIWE"; |
|||
int i = 0; |
|||
while (ids[i] && ids[i] != level[0]) |
|||
i++; |
|||
if (ids[i]) |
|||
(Harl::*fcts[i])(); |
|||
} |
|||
|
@ -0,0 +1,34 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Harl.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/17 11:13:50 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/17 13:12:45 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
using std::string; |
|||
|
|||
class Harl { |
|||
|
|||
public: |
|||
|
|||
Harl (void); |
|||
Harl (Harl const & src); |
|||
~Harl (void); |
|||
Harl & operator= (Harl const & src); |
|||
void _complain(string level); |
|||
|
|||
private: |
|||
void _debug(void); |
|||
void _info(void); |
|||
void _warning(void); |
|||
void _error(void); |
|||
|
|||
}; |
@ -0,0 +1,23 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/17 11:37:33 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/17 12:45:24 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Harl.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
Harl bot; |
|||
bot._complain("DEBUG"); |
|||
bot._complain("INFO"); |
|||
bot._complain("WARNING"); |
|||
bot._complain("ERROR"); |
|||
|
|||
} |
Loading…
Reference in new issue