1
0
CPP_Module_05/ex00/Bureaucrat.hpp
2025-03-08 20:04:33 +01:00

86 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 &);