86 lines
2.6 KiB
C++
86 lines
2.6 KiB
C++
|
/* ************************************************************************** */
|
|||
|
/* */
|
|||
|
/* ::: :::::::: */
|
|||
|
/* Bureaucrat.hpp :+: :+: :+: */
|
|||
|
/* +:+ +:+ +:+ */
|
|||
|
/* 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 */
|
|||
|
/* */
|
|||
|
/* ************************************************************************** */
|
|||
|
|
|||
|
#pragma once
|
|||
|
|
|||
|
#include <exception>
|
|||
|
#include <fstream>
|
|||
|
#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
|
|||
|
|
|||
|
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"); }
|
|||
|
|
|||
|
const std::string &getName(void) { return _name; }
|
|||
|
uint8_t getGrade(void) { return _grade; }
|
|||
|
|
|||
|
class GradeTooHighException : public std::exception {
|
|||
|
public:
|
|||
|
virtual const char *what() const throw() {
|
|||
|
return ("Grade is too high");
|
|||
|
}
|
|||
|
};
|
|||
|
class GradeTooLowException : public std::exception {
|
|||
|
public:
|
|||
|
virtual const char *what() const throw() {
|
|||
|
return ("Grade is too low");
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
// Copy assignement operator
|
|||
|
Bureaucrat &operator=(Bureaucrat const &);
|
|||
|
|
|||
|
// Preincrement operator
|
|||
|
Bureaucrat &operator++(void);
|
|||
|
Bureaucrat &operator--(void);
|
|||
|
|
|||
|
// Post increment operator
|
|||
|
Bureaucrat operator++(int);
|
|||
|
Bureaucrat operator--(int);
|
|||
|
|
|||
|
private:
|
|||
|
const std::string _name;
|
|||
|
uint8_t _grade;
|
|||
|
};
|
|||
|
|
|||
|
std::ostream &operator<<(std::ostream &, Bureaucrat &);
|