1
0

🔨」 fix: moved all function declaration into the cpp file

This commit is contained in:
2025-03-29 16:51:31 +01:00
parent 0e7e6d87b2
commit e5bf6c151c
4 changed files with 64 additions and 41 deletions

View File

@ -6,12 +6,47 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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");
}