#include #include #include #include #include #include #include #include int main() { { Bureaucrat franck; std::cout << franck << std::endl; franck.incrementGrade(); std::cout << franck << std::endl; Bureaucrat alain("Alain"); std::cout << alain << std::endl; alain.incrementGrade(); std::cout << alain << std::endl; Bureaucrat james("James", 1); std::cout << james << std::endl; james.decrementGrade(); std::cout << james << std::endl; } std::cout << "================ Exceptions ================" << std::endl; { std::cout << "=== Decrement too low ===" << std::endl; try { Bureaucrat franckAlainJamesLeboeuf; std::cout << franckAlainJamesLeboeuf << std::endl; franckAlainJamesLeboeuf.decrementGrade(); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } std::cout << "=== Increment too high ===" << std::endl; try { Bureaucrat franckAlainJamesLeboeuf("Franck Alain James Leboeuf", 1); std::cout << franckAlainJamesLeboeuf << std::endl; franckAlainJamesLeboeuf.incrementGrade(); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } std::cout << "=== Construct too low ===" << std::endl; try { Bureaucrat franckAlainJamesLeboeuf("Franck Alain James Leboeuf", 151); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } std::cout << "=== Construct too high ===" << std::endl; try { Bureaucrat franckAlainJamesLeboeuf("Franck Alain James Leboeuf", 0); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } } // std::cout << "================================ Forms ================================" << std::endl; // { // Bureaucrat franck; // Form vente; // std::cout << vente << std::endl; // vente.beSigned(franck); // std::cout << vente << std::endl; // Form vente2; // std::cout << vente2 << std::endl; // franck.signForm(vente2); // std::cout << vente2 << std::endl; // Bureaucrat alain("Alain"); // Form contrat("Contrat"); // std::cout << contrat << std::endl; // contrat.beSigned(alain); // std::cout << contrat << std::endl; // Form contrat2("Contrat2"); // std::cout << contrat2 << std::endl; // alain.signForm(contrat2); // std::cout << contrat2 << std::endl; // Bureaucrat james("James", 1); // Form achat("Achat", 1, 1); // std::cout << achat << std::endl; // achat.beSigned(james); // std::cout << achat << std::endl; // Form achat2("Achat2", 1, 1); // std::cout << achat2 << std::endl; // james.signForm(achat2); // std::cout << achat2 << std::endl; // Bureaucrat franckAlainJamesLeboeuf("Franck Alain James Leboeuf", 1); // Form contratAlternance("Contrat Alternance", 1, 1); // std::cout << contratAlternance << std::endl; // contratAlternance.beSigned(franckAlainJamesLeboeuf); // std::cout << contratAlternance << std::endl; // contratAlternance.beSigned(franckAlainJamesLeboeuf); // std::cout << contratAlternance << std::endl; // Form contractAlternance2("Contrat Alternance 2", 1, 1); // franckAlainJamesLeboeuf.signForm(contractAlternance2); // std::cout << contractAlternance2 << std::endl; // franckAlainJamesLeboeuf.signForm(contractAlternance2); // std::cout << contractAlternance2 << std::endl; // } // std::cout << "================ Exceptions ================" << std::endl; // { // std::cout << "=== Construct both grade too low ===" << std::endl; // try { // Form vente("Vente", 151, 151); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Construct both grade too high ===" << std::endl; // try { // Form vente("Vente", 0, 0); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Construct to sign grade too low ===" << std::endl; // try { // Form vente("Vente", 151, 150); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Construct to sign grade too high ===" << std::endl; // try { // Form vente("Vente", 0, 0); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Construct to execute grade too low ===" << std::endl; // try { // Form vente("Vente", 150, 151); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Construct to execute grade too high ===" << std::endl; // try { // Form vente("Vente", 150, 0); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Grade to be signed too low ===" << std::endl; // try { // Bureaucrat franck; // Form vente("Vente", 1, 1); // vente.beSigned(franck); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // std::cout << "=== Grade to sign form too low ===" << std::endl; // try { // Bureaucrat franck; // Form vente("Vente", 1, 1); // franck.signForm(vente); // } catch (const std::exception& exception) { // std::cout << exception.what() << std::endl; // } // } std::cout << "================================ Concrete forms ================================" << std::endl; { std::cout << "=== Shrubbery creation ===" << std::endl; Bureaucrat james("James", 1); ShrubberyCreationForm jardin("Jardin"); std::cout << jardin << std::endl; james.signForm(jardin); std::cout << jardin << std::endl; james.executeForm(jardin); std::cout << "=== Robotomy request ===" << std::endl; RobotomyRequestForm marvin("Marvin"); std::cout << marvin << std::endl; james.signForm(marvin); std::cout << marvin << std::endl; james.executeForm(marvin); james.executeForm(marvin); james.executeForm(marvin); james.executeForm(marvin); std::cout << "=== Presidential pardon ===" << std::endl; PresidentialPardonForm arthur("Arthur Dent"); std::cout << arthur << std::endl; james.signForm(arthur); std::cout << arthur << std::endl; james.executeForm(arthur); std::cout << "=== Execute through base reference ===" << std::endl; PresidentialPardonForm ford("Ford Prefect"); AForm& form = ford; james.signForm(form); james.executeForm(form); } std::cout << "================ Exceptions ================" << std::endl; { std::cout << "=== Execute form not signed ===" << std::endl; Bureaucrat james("James", 1); PresidentialPardonForm arthur("Arthur Dent"); james.executeForm(arthur); std::cout << "=== Sign grade too low ===" << std::endl; Bureaucrat franck; ShrubberyCreationForm jardin("Jardin"); franck.signForm(jardin); std::cout << jardin << std::endl; std::cout << "=== Execute grade too low ===" << std::endl; Bureaucrat alain("Alain", 140); ShrubberyCreationForm maison("Maison"); alain.signForm(maison); std::cout << maison << std::endl; alain.executeForm(maison); james.executeForm(maison); std::cout << "=== Execute grade boundaries ===" << std::endl; Bureaucrat zaphod("Zaphod", 45); RobotomyRequestForm trillian("Trillian"); zaphod.signForm(trillian); zaphod.executeForm(trillian); zaphod.decrementGrade(); std::cout << zaphod << std::endl; zaphod.executeForm(trillian); std::cout << "=== Execute not signed then grade too low (direct) ===" << std::endl; try { Bureaucrat leboeuf; PresidentialPardonForm pardon("Franck Leboeuf"); pardon.execute(leboeuf); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } std::cout << "=== Execute grade too low (direct) ===" << std::endl; try { Bureaucrat leboeuf; Bureaucrat president("President", 1); PresidentialPardonForm pardon("Franck Leboeuf"); pardon.beSigned(president); pardon.execute(leboeuf); } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } } std::cout << "================================ Intern ================================" << std::endl; { Intern someRandomIntern; Bureaucrat james("James", 1); std::cout << "=== Robotomy request ===" << std::endl; AForm* rrf; rrf = someRandomIntern.makeForm("robotomy request", "Bender"); std::cout << *rrf << std::endl; james.signForm(*rrf); james.executeForm(*rrf); delete rrf; std::cout << "=== Shrubbery creation ===" << std::endl; AForm* scf; scf = someRandomIntern.makeForm("shrubbery creation", "Bureau"); std::cout << *scf << std::endl; james.signForm(*scf); james.executeForm(*scf); delete scf; std::cout << "=== Presidential pardon ===" << std::endl; AForm* ppf; ppf = someRandomIntern.makeForm("presidential pardon", "Ford Prefect"); std::cout << *ppf << std::endl; james.signForm(*ppf); james.executeForm(*ppf); delete ppf; } std::cout << "================ Exceptions ================" << std::endl; { std::cout << "=== Unknown form name ===" << std::endl; try { Intern someRandomIntern; AForm* form = someRandomIntern.makeForm("coffee request", "Bureau"); delete form; } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } std::cout << "=== Empty form name ===" << std::endl; try { Intern someRandomIntern; AForm* form = someRandomIntern.makeForm("", "Bureau"); delete form; } catch (const std::exception& exception) { std::cout << exception.what() << std::endl; } } }