diff --git a/ex00/Bureaucrat.cpp b/ex00/Bureaucrat.cpp index c7492a0..0580e37 100644 --- a/ex00/Bureaucrat.cpp +++ b/ex00/Bureaucrat.cpp @@ -6,12 +6,47 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */ -/* Updated: 2025/03/08 20:00:23 by adjoly ### ########.fr */ +/* Updated: 2025/03/29 14:58:52 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" +void _log(std::string emoji, std::string what, std::string who, + std::string str) { +#ifdef VERBOSE + if (who.empty()) + std::cout << "「" << emoji << "」" << what << ": " << str << std::endl; + else + std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str + << std::endl; +#else + (void)emoji, (void)what, (void)who, (void)str; +#endif +} + +Bureaucrat::Bureaucrat(void) { + _log("➕", "Bureaucrat", "", "default constructor called"); +} + +Bureaucrat::Bureaucrat(const Bureaucrat &cpy) { + _log("➕", "Bureaucrat", "", "copy constructor called"); + if (&cpy != this) + *this = cpy; +} + +Bureaucrat::Bureaucrat(std::string name, uint8_t grade) + : _name(name), _grade(grade) { + _log("➕", "Bureaucrat", "", "constructor called"); +} + +const std::string &Bureaucrat::getName(void) { return _name; } +uint8_t Bureaucrat::getGrade(void) { return _grade; } + +Bureaucrat::~Bureaucrat(void) { + _log("➖", "Bureaucrat", "", "destructor called"); +} + Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy) { if (&cpy == this) return *this; @@ -19,21 +54,21 @@ Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy) { return *this; } -Bureaucrat &Bureaucrat::operator++(void) { +Bureaucrat &Bureaucrat::operator++(void) { _grade--; if (_grade < MAXGRADE) throw GradeTooHighException(); return *this; } -Bureaucrat &Bureaucrat::operator--(void) { +Bureaucrat &Bureaucrat::operator--(void) { _grade++; if (_grade > MINGRADE) throw GradeTooLowException(); return *this; } -Bureaucrat Bureaucrat::operator++(int) { +Bureaucrat Bureaucrat::operator++(int) { Bureaucrat old = *this; _grade--; @@ -42,7 +77,7 @@ Bureaucrat Bureaucrat::operator++(int) { return (old); } -Bureaucrat Bureaucrat::operator--(int) { +Bureaucrat Bureaucrat::operator--(int) { Bureaucrat old = *this; _grade++; @@ -55,3 +90,12 @@ std::ostream &operator<<(std::ostream &os, Bureaucrat &val) { os << val.getName() << ", bureaucrat grade " << (int)val.getGrade(); return os; } + +const char *Bureaucrat::GradeTooHighException::what() const throw() { + return ("Grade is too high"); + } + +const char *Bureaucrat::GradeTooLowException::what() const throw() { + return ("Grade is too low"); + } + diff --git a/ex00/Bureaucrat.hpp b/ex00/Bureaucrat.hpp index 8664356..cd2b0a3 100644 --- a/ex00/Bureaucrat.hpp +++ b/ex00/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 13:59:43 by adjoly #+# #+# */ -/* Updated: 2025/03/08 19:58:18 by adjoly ### ########.fr */ +/* Updated: 2025/03/29 15:02:17 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,56 +14,35 @@ #include #include +#include #include #include typedef unsigned char uint8_t; -inline void _log(std::string emoji, std::string what, std::string who, - std::string str) { -#ifdef VERBOSE - if (who.empty()) - std::cout << "「" << emoji << "」" << what << ": " << str << std::endl; - else - std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str - << std::endl; -#else - (void)emoji, (void)what, (void)who, (void)str; -#endif -} - #define MAXGRADE 1 #define MINGRADE 150 +void _log(std::string emoji, std::string what, std::string who, + std::string str); + class Bureaucrat { public: - Bureaucrat(void) { - _log("➕", "Bureaucrat", "", "default constructor called"); - } - Bureaucrat(const Bureaucrat &cpy) { - _log("➕", "Bureaucrat", "", "copy constructor called"); - if (&cpy != this) - *this = cpy; - } - Bureaucrat(std::string name, uint8_t grade) : _name(name), _grade(grade) { - _log("➕", "Bureaucrat", "", "constructor called"); - } - ~Bureaucrat(void) { _log("➖", "Bureaucrat", "", "destructor called"); } + Bureaucrat(void); + Bureaucrat(const Bureaucrat &cpy); + Bureaucrat(std::string name, uint8_t grade); + ~Bureaucrat(void); - const std::string &getName(void) { return _name; } - uint8_t getGrade(void) { return _grade; } + const std::string &getName(void); + uint8_t getGrade(void); class GradeTooHighException : public std::exception { public: - virtual const char *what() const throw() { - return ("Grade is too high"); - } + virtual const char *what() const throw(); }; class GradeTooLowException : public std::exception { public: - virtual const char *what() const throw() { - return ("Grade is too low"); - } + virtual const char *what() const throw(); }; // Copy assignement operator diff --git a/ex00/Makefile b/ex00/Makefile index 46eecde..0dad6ce 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -6,7 +6,7 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/25 16:09:27 by adjoly #+# #+# # -# Updated: 2025/03/08 19:55:47 by adjoly ### ########.fr # +# Updated: 2025/03/29 15:01:07 by adjoly ### ########.fr # # # # **************************************************************************** # diff --git a/ex00/main.cpp b/ex00/main.cpp index 566beeb..bcdee4e 100644 --- a/ex00/main.cpp +++ b/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 14:01:11 by adjoly #+# #+# */ -/* Updated: 2025/03/08 20:04:22 by adjoly ### ########.fr */ +/* Updated: 2025/03/29 15:00:18 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */