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");
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
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

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */