{
}
-AForm::AForm(const std::string &name, int signatory_grade, int executor_grade)
+AForm::AForm(const std::string &name, int signatory_grade, int executor_grade, std::string target)
: m_name(name)
, m_is_signed(0)
, m_signatory_grade(signatory_grade)
, m_executor_grade(executor_grade)
+ , m_target(target)
{
if (signatory_grade < Bureaucrat::HIGHEST_GRADE || executor_grade < Bureaucrat::HIGHEST_GRADE)
throw (Bureaucrat::GradeTooHighException());
void AForm::checkExecutorGrade(const Bureaucrat &bureaucrat) const
{
+ if (!m_is_signed)
+ throw (AForm::FormNotSignedException());
if (bureaucrat.getGrade() > m_executor_grade)
throw (Bureaucrat::GradeTooLowException());
}
ostream << "\t\t\t\tSignature\n";
return (ostream);
}
+
+AForm::FormNotSignedException::FormNotSignedException()
+ : std::runtime_error::runtime_error("The form is not signed")
+{
+}
+
+AForm::FormNotSignedException::FormNotSignedException(const AForm::FormNotSignedException &other)
+ : std::runtime_error::runtime_error(other.what())
+{
+}
+
+AForm::FormNotSignedException::~FormNotSignedException() throw()
+{
+}
+
+AForm::FormNotSignedException &AForm::FormNotSignedException::operator=(const AForm::FormNotSignedException &other)
+{
+ std::runtime_error::operator = (other);
+ return (*this);
+}
bool m_is_signed;
const int m_signatory_grade;
const int m_executor_grade;
+ const std::string m_target;
+ // These are protected only so that inheriting classes can use them
+ // in their "non implementations" of there functions
+ protected:
AForm();
AForm &operator=(const AForm &other);
public:
- AForm(const std::string &name, int signatory_grade, int executor_grade);
+ AForm(const std::string &name, int signatory_grade, int executor_grade, std::string target);
AForm(const AForm &other);
virtual ~AForm();
void beSigned(const Bureaucrat &bureaucrat);
void checkExecutorGrade(const Bureaucrat &bureaucrat) const;
void virtual execute(const Bureaucrat &bureaucrat) const = 0;
+
+ class FormNotSignedException;
};
std::ostream &operator<<(std::ostream &ostream, const AForm &form);
+class AForm::FormNotSignedException : public std::runtime_error
+{
+ public:
+ FormNotSignedException();
+ FormNotSignedException(const FormNotSignedException &other);
+ ~FormNotSignedException() throw();
+
+ FormNotSignedException &operator=(const FormNotSignedException &other);
+};
+
#endif // AFORM_H
<< " because his grade " << m_grade << " is lower than the necessary "
<< form.getSignatoryGrade() << '\n';
}
+ catch (const AForm::FormNotSignedException &exception)
+ {
+ std::cout << m_name << " couldn't execute the form " << form.getName()
+ << " because the norm has not yet been signed.\n";
+ }
}
std::ostream &operator<<(std::ostream &ostream, const Bureaucrat &bureaucrat)
SRCDIR := .
-SOURCES := main.cpp \
- Bureaucrat.cpp \
- AForm.cpp \
+SOURCES := main.cpp \
+ Bureaucrat.cpp \
+ AForm.cpp \
+ ShrubberyCreationForm.cpp \
+ RobotomyRequestForm.cpp \
+ PresidentialPardonForm.cpp \
SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
--- /dev/null
+#include "PresidentialPardonForm.h"
+
+PresidentialPardonForm::PresidentialPardonForm()
+ : AForm()
+{
+}
+
+PresidentialPardonForm::PresidentialPardonForm(const std::string &target)
+ : AForm("Presidential Pardon Form", 25, 5, target)
+{
+}
+
+PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &other)
+ : AForm(other)
+{
+}
+
+PresidentialPardonForm::~PresidentialPardonForm()
+{
+}
+
+void PresidentialPardonForm::execute(Bureaucrat const &executor) const
+{
+ checkExecutorGrade(executor);
+}
--- /dev/null
+#ifndef PRESIDENTIALPARDONFORM_H
+# define PRESIDENTIALPARDONFORM_H
+
+#include "AForm.h"
+#include <string>
+
+class PresidentialPardonForm : public AForm
+{
+ // These are protected only so that inheriting classes can use them
+ // in their "non implementations" of there functions
+ protected:
+ PresidentialPardonForm();
+
+ using AForm::operator=;
+
+ public:
+ PresidentialPardonForm(const std::string &target);
+ PresidentialPardonForm(const PresidentialPardonForm &other);
+ ~PresidentialPardonForm();
+
+ void execute(Bureaucrat const &executor) const;
+};
+
+#endif // PRESIDENTIALPARDONFORM_H
--- /dev/null
+#include "RobotomyRequestForm.h"
+
+RobotomyRequestForm::RobotomyRequestForm()
+ : AForm()
+{
+}
+
+RobotomyRequestForm::RobotomyRequestForm(const std::string &target)
+ : AForm("Robotomy Request Form", 72, 45, target)
+{
+}
+
+RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &other)
+ : AForm(other)
+{
+}
+
+RobotomyRequestForm::~RobotomyRequestForm()
+{
+}
+
+void RobotomyRequestForm::execute(Bureaucrat const &executor) const
+{
+ checkExecutorGrade(executor);
+}
--- /dev/null
+#ifndef ROBOTOMYREQUESTFORM_H
+# define ROBOTOMYREQUESTFORM_H
+
+#include "AForm.h"
+#include <string>
+
+class RobotomyRequestForm : public AForm
+{
+ // These are protected only so that inheriting classes can use them
+ // in their "non implementations" of there functions
+ protected:
+ RobotomyRequestForm();
+
+ using AForm::operator=;
+
+ public:
+ RobotomyRequestForm(const std::string &target);
+ RobotomyRequestForm(const RobotomyRequestForm &other);
+ ~RobotomyRequestForm();
+
+ void execute(Bureaucrat const &executor) const;
+};
+
+#endif // ROBOTOMYREQUESTFORM_H
--- /dev/null
+#include "ShrubberyCreationForm.h"
+
+ShrubberyCreationForm::ShrubberyCreationForm()
+ : AForm()
+{
+}
+
+ShrubberyCreationForm::ShrubberyCreationForm(const std::string &target)
+ : AForm("Shrubbery Creation Form", 145, 137, target)
+{
+}
+
+ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &other)
+ : AForm(other)
+{
+}
+
+ShrubberyCreationForm::~ShrubberyCreationForm()
+{
+}
+
+void ShrubberyCreationForm::execute(Bureaucrat const &executor) const
+{
+ checkExecutorGrade(executor);
+}
--- /dev/null
+#ifndef SHRUBBERYCREATIONFORM_H
+# define SHRUBBERYCREATIONFORM_H
+
+#include "AForm.h"
+#include <string>
+
+class ShrubberyCreationForm : public AForm
+{
+ // These are protected only so that inheriting classes can use them
+ // in their "non implementations" of there functions
+ protected:
+ ShrubberyCreationForm();
+
+ using AForm::operator=;
+
+ public:
+ ShrubberyCreationForm(const std::string &target);
+ ShrubberyCreationForm(const ShrubberyCreationForm &other);
+ ~ShrubberyCreationForm();
+
+ void execute(Bureaucrat const &executor) const;
+};
+
+#endif // SHRUBBERYCREATIONFORM_H
+++ /dev/null
-#ifndef SHRUBERRYCREATIONFORM_H
-# define SHRUBERRYCREATIONFORM_H
-
-class ShruberryCreationForm
-{
- private:
-
- public:
- using l
- ShruberryCreationForm(const ShruberryCreationForm &other);
- ~ShruberryCreationForm();
-
- ShruberryCreationForm &operator=(const ShruberryCreationForm &other);
-};
-
-ShruberryCreationForm::ShruberryCreationForm(const std::string &target)
- : AForm("Shruberry Creation Form", 145, 137, target)
-{
-}
-
-ShruberryCreationForm::~ShruberryCreationForm()
-{
-}
-
-#endif // SHRUBERRYCREATIONFORM_H
#include "Bureaucrat.h"
#include "AForm.h"
+#include "ShrubberyCreationForm.h"
+#include "RobotomyRequestForm.h"
+#include "PresidentialPardonForm.h"
#include <iostream>
int main(void)
{
- Bureaucrat boss("Boss", 1);
- Bureaucrat employee("Employee", 110);
+ Bureaucrat employee0("Employee0", 1);
+ Bureaucrat employee1("Employee1", 20);
+ Bureaucrat employee2("Employee2", 50);
+ Bureaucrat employee3("Employee3", 140);
+ Bureaucrat employee4("Employee4", 150);
+ ShrubberyCreationForm shrub("test_sh");
+ RobotomyRequestForm robot("test_rob");
+ PresidentialPardonForm pres("test_pres");
+ employee4.signForm(shrub);
+ employee3.signForm(robot);
+ employee2.signForm(pres);
+ std::cout << '\n';
+ employee3.executeForm(shrub);
+ employee2.executeForm(robot);
+ employee1.executeForm(pres);
+ std::cout << '\n';
+ employee2.executeForm(shrub);
+ employee1.executeForm(robot);
+ employee0.executeForm(pres);
+ std::cout << '\n';
+ employee3.signForm(shrub);
+ employee2.signForm(robot);
+ employee1.signForm(pres);
+ std::cout << '\n';
+ employee3.executeForm(shrub);
+ employee2.executeForm(robot);
+ employee1.executeForm(pres);
+ std::cout << '\n';
+ employee2.executeForm(shrub);
+ employee1.executeForm(robot);
+ employee0.executeForm(pres);
return (0);
}