GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cpp_modules/cpp05/ex02/src/Bureaucrat.cpp at master · Thopterek/cpp_modules Expand file tree/ Copy pathBureaucrat.cppMore file actions 136 lines (118 loc) · 4.38 KB / Copy pathBureaucrat.cppFile metadata and controls136 lines (118 loc) · 4.38 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 /* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Bureaucrat.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ndziadzi <[email protected]. +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/17 15:38:58 by ndziadzi #+# #+# */ /* Updated: 2025/04/22 14:59:06 by ndziadzi ### ########.fr */ /* */ /* ************************************************************************** */ #include "../inc/Bureaucrat.hpp" #include "../inc/AForm.hpp" Bureaucrat::Bureaucrat() : name("Default_name"), grade(75) { std::cout << "BURE: Default constructor with grade in the middle" << std::endl; } Bureaucrat::Bureaucrat(std::string name, int grade) : name(name) { if (grade < 1) throw GradeTooHighException(); else if (grade > 150) throw GradeTooLowException(); std::cout << "BURE: " << getName() << " succesfully constructed" << std::endl; this->grade = grade; } Bureaucrat::~Bureaucrat() { std::cout << "BURE: " << getName() << " destructor called" << std::endl; } Bureaucrat::Bureaucrat(const Bureaucrat &other) : name(other.name), grade(other.grade) { std::cout << "BURE: Copy constructor called" << std::endl; } Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other) { std::cout << "BURE: Copy assingment, but name is unchanged" << std::endl; if (this != &other) { grade = other.grade; } return (*this); } std::string const &Bureaucrat::getName() const { return (name); } int const &Bureaucrat::getGrade() const { return (grade); } void Bureaucrat::setOneHigher() { if (grade - 1 < 1) throw GradeTooHighException(); std::cout << getName() << ", grade change went okay (higher)" << std::endl; this->grade -= 1; } void Bureaucrat::setOneLower() { if (grade + 1 > 150) throw GradeTooLowException(); std::cout << getName() << ", grade change went okay (lower is +)" << std::endl; this->grade += 1; } const char *Bureaucrat::GradeTooHighException::what() const throw() { return ("BURE : GradeTooHigh : less than 1, exception called"); } const char *Bureaucrat::GradeTooLowException::what() const throw() { return ("BURE : GradeTooLow : more than 150 exception called"); } Bureaucrat *Bureaucrat::tryNewBureaucrat(std::string name, int grade) { Bureaucrat *bure = 0; try { bure = new Bureaucrat(name, grade); } catch (const Bureaucrat::GradeTooHighException &e) { std::cerr << "Caught exception for init: " << e.what() << std::endl; } catch (const Bureaucrat::GradeTooLowException &e) { std::cerr << "Caught exception for init: " << e.what() << std::endl; } return (bure); } void Bureaucrat::tryHigherGrade() { try { this->setOneHigher(); } catch (const Bureaucrat::GradeTooHighException &e) { std::cerr << "Caught exception when changing grade (-)" << std::endl; } } void Bureaucrat::tryLowerGrade() { try { this->setOneLower(); } catch (const Bureaucrat::GradeTooHighException &e) { std::cerr << "Caught exception when changing grade (+)" << std::endl; } } void Bureaucrat::signForm(AForm &form) { try { form.beSigned(*this); std::cout << getName() << " signed " << form.getName() << std::endl; } catch (std::exception &e) { std::cerr << getName() << " couldn't sign " << std::flush; std::cerr << form.getName() << ", because " << std::flush; std::cerr << "his grade is " << getGrade() << std::flush; std::cerr << " and form grade is " << form.getReqToSign() << std::endl; } } void Bureaucrat::executeForm(AForm const &form) { try { form.execute(*this); std::cout << getName() << " executed " << form.getName() << std::endl; } catch (std::exception &e) { std::cerr << getName() << " couldn't execute " << std::flush; std::cerr << form.getName() << ", because " << std::flush; std::cerr << "form grade is: " << form.getReqToExec() << std::flush; std::cerr << " and Bureaucrat grade is: " << getGrade() << std::endl; } } std::ostream &operator<<(std::ostream &os, const Bureaucrat &bure) { os << bure.getName() << ", bureaucrat grade " << bure.getGrade() << "."; return (os); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |