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> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 13:59:45 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" #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) { Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy) {
if (&cpy == this) if (&cpy == this)
return *this; return *this;
@ -19,21 +54,21 @@ Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy) {
return *this; return *this;
} }
Bureaucrat &Bureaucrat::operator++(void) { Bureaucrat &Bureaucrat::operator++(void) {
_grade--; _grade--;
if (_grade < MAXGRADE) if (_grade < MAXGRADE)
throw GradeTooHighException(); throw GradeTooHighException();
return *this; return *this;
} }
Bureaucrat &Bureaucrat::operator--(void) { Bureaucrat &Bureaucrat::operator--(void) {
_grade++; _grade++;
if (_grade > MINGRADE) if (_grade > MINGRADE)
throw GradeTooLowException(); throw GradeTooLowException();
return *this; return *this;
} }
Bureaucrat Bureaucrat::operator++(int) { Bureaucrat Bureaucrat::operator++(int) {
Bureaucrat old = *this; Bureaucrat old = *this;
_grade--; _grade--;
@ -42,7 +77,7 @@ Bureaucrat Bureaucrat::operator++(int) {
return (old); return (old);
} }
Bureaucrat Bureaucrat::operator--(int) { Bureaucrat Bureaucrat::operator--(int) {
Bureaucrat old = *this; Bureaucrat old = *this;
_grade++; _grade++;
@ -55,3 +90,12 @@ std::ostream &operator<<(std::ostream &os, Bureaucrat &val) {
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade(); os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
return os; 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");
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 13:59:43 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 <exception> #include <exception>
#include <fstream> #include <fstream>
#include <iostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
typedef unsigned char uint8_t; 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 MAXGRADE 1
#define MINGRADE 150 #define MINGRADE 150
void _log(std::string emoji, std::string what, std::string who,
std::string str);
class Bureaucrat { class Bureaucrat {
public: public:
Bureaucrat(void) { Bureaucrat(void);
_log("", "Bureaucrat", "", "default constructor called"); Bureaucrat(const Bureaucrat &cpy);
} Bureaucrat(std::string name, uint8_t grade);
Bureaucrat(const Bureaucrat &cpy) { ~Bureaucrat(void);
_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"); }
const std::string &getName(void) { return _name; } const std::string &getName(void);
uint8_t getGrade(void) { return _grade; } uint8_t getGrade(void);
class GradeTooHighException : public std::exception { class GradeTooHighException : public std::exception {
public: public:
virtual const char *what() const throw() { virtual const char *what() const throw();
return ("Grade is too high");
}
}; };
class GradeTooLowException : public std::exception { class GradeTooLowException : public std::exception {
public: public:
virtual const char *what() const throw() { virtual const char *what() const throw();
return ("Grade is too low");
}
}; };
// Copy assignement operator // Copy assignement operator

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 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 #
# # # #
# **************************************************************************** # # **************************************************************************** #

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 14:01:11 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */