Пример #1
0
void	OfficeBlock::doBureaucracy(const std::string& form_name, const std::string& target) const
{
	if (this->_intern && this->_b_sign && this->_b_exec)
	{
		Form 	*f = this->_intern->makeForm(form_name, target);
		if (f)
		{
			std::cout << "Intern make a form of type \"" << form_name << "\": " << *f;
			f->beSigned(*this->_b_sign);
			std::cout << "Bureaucrat " << this->_b_sign->getName() << " signed the form " << f->getName() << std::endl;
			f->execute(*this->_b_exec);
			std::cout << "Bureaucrat " << this->_b_exec->getName() << " execute the form " << f->getName() << std::endl;
			delete f;
		} else {
			std::cerr << "Intern can't make a Form of type \"" << form_name << "\"" << std::endl;
		}
	} else {
		if (!this->_intern)
			std::cerr << "An Intern is required in OfficeBlock" << std::endl;
		if (!this->_b_sign)
			std::cerr << "An Bureaucrat is required in OfficeBlock to sign the form" << std::endl;
		if (!this->_b_exec)
			std::cerr << "An Bureaucrat is required in OfficeBlock to execute the form" << std::endl;
	}
}
Пример #2
0
void Bureaucrat::executeForm(Form const & form)
{
	try {
		form.execute(*this);
		std::cout << this->_name << " executes " << form.getName() << std::endl;
	} catch (std::exception & e) {
		std::cout << this->_name << " can't execute " << form.getName() << " : " << e.what() << std::endl;
	}
}
Пример #3
0
void Bureaucrat::signForm(Form & form)
{
	try {
		form.beSigned(*this);
		std::cout << this->_name << " signs " << form.getName() << std::endl;
	} catch (std::exception &e) {
		std::cout << this->_name << " cannot sign " << form.getName() << " because " << e.what() << std::endl;
	}
}
Пример #4
0
void				Bureaucrat::executeForm(Form & form) const {
	try {
		form.execute(*this);
		std::cout << _name << " executes " << form.getName() << std::endl;
	} catch (std::exception & e) {
		std::cout << _name << " cannot execute " << form.getName();
		std::cout << " because " << e.what() << std::endl;
	}
}
Пример #5
0
void				Bureaucrat::signForm( Form & form ) const {
	try {
		form.beSigned(*this);
		std::cout << _name << "signs form [" << form.getName() << "]" << std::endl;
	} catch (Form::GradeTooLowException & e) {
		std::cout << _name << " cannot sign form [" << form.getName() << "] because";
		std::cout << " " << e.what() << std::endl;
	}
}
Пример #6
0
void Bureaucrat::signForm(Form &src) {

    src.beSigned(*this);
    if (src.getGradeSign() >= this->getGrade()) {
        std::cout << "<" << this->name << "> signs " << src.getName() << std::endl;
    }
    else {
        std::cout << "<" << this->name << "> cannot signs " << src.getName() << " because " << "the form grade is too low" << std::endl;
    }
}
Пример #7
0
void	Bureaucrat::signForm(Form &form)
{
	try 
	{
		form.beSigned(this);
		std::cout << this->_name << " signs " << form.getName() << std::endl;
	}
	catch (std::exception &e)
	{
		std::cout << this->_name << " cannot sign " << form.getName() << " because his grade isn't high enough" << std::endl;
	}
}
Пример #8
0
void				Bureaucrat::signForm(Form & f) {
	try
	{
		f.beSigned(*this);
		std::cout << this->_name << " signs " << f.getName() << std::endl;

	}
	catch (Form::GradeTooLowException & e)
	{
		std::cout << this->_name << " cannot sign " << f.getName() << " because He's low grade" << std::endl;
	}

}
Пример #9
0
void		Bureaucrat::signForm(Form &form)
{
	try
	{
		if (form.beSigned(*this))
			std::cout << this->_name << " signs " << form.getName() << std::endl;
	}
	catch (std::exception const &err)
	{
		std::cout << this->_name << " cannot sign " << form.getName();
		std::cout << " because " << err.what() << std::endl;
    }
	return ;
}
Пример #10
0
void				Bureaucrat::executeForm(Form const & form) {
	try
	{
		form.execute(*this);
		std::cout << this->_name << " executes " << form.getName() << std::endl;
	}
    catch (Form::GradeTooLowException & e)
    {
        std::cout << e.errorGrade() << " for " << form.getName() << std::endl;
    }
    catch (Form::AlreadySignedException & e)
    {
        std::cout << e.errorSigned() << " for " << form.getName() << std::endl;
    }
}
Пример #11
0
void		Bureaucrat::executeForm( Form const & form ) const
{
	try
	{
		form.execute(*this);
		std::cout << this->getName() << " executes " << form.getName() << std::endl;
	}
	catch (Form::GradeTooLowException & e)
	{
		std::cout << this->getName() << " can't executes " << form.getName() << "cause his grade is " << this->getGrade() << " and need to be " << form.getExecGrade() << std::endl;
	}
	catch (Form::NotSignedException & e)
	{
		std::cout << this->getName() << " can't executes " << form.getName() << " cause the form " << form.getName() << " is not signed !" << std::endl;
	}
}
Пример #12
0
void		Bureaucrat::signForm(Form & con)
{
	if (con.beSigned(*this))
	{
		std::cout << this->_name << " signs " << con.getName() << "." << std::endl;
	}
	else if (!con.getSigned())
	{
		std::cout << this->_name << " cannot sign " << con.getName() << " because his level is too low." << std::endl;
	}
	else
	{
		std::cout << this->_name << " cannot sign " << con.getName() << " because the form is already signed." << std::endl;
	}

}
Пример #13
0
void Bureaucrat::executeForm(Form const &form) {
    try {
        form.execute(*this);
        std::cout << "<bureaucrat> executes <" << form.getName() << ">" << std::endl;

    }
    catch (std::exception &e) {
        std::cout << e.what() << std::endl;
    }
}
Пример #14
0
bool Bureaucrat::executeForm(Form const & form)
{
	try {
		form.execute(*this);
		return true;
	} catch (std::exception & e) {
		std::cout << this->_name << " can't execute " << form.getName() << " : " << e.what() << std::endl;
	}
	return false;
}
Пример #15
0
void					test1(Bureaucrat &b, Form &f)
{
	std::cout << "\033[35mtest1: \033[0m" << std::endl;
	
	std::cout << b.getName() << "(" << b.getGrade() <<
		") trying to sign " << f.getName() << "(" << f.getSGrade() <<
		")" << std::endl;
	b.signForm(f);
	std::cout << std::endl;
	return ;
}
Пример #16
0
void				Bureaucrat::signForm( Form & form ) const {
	try {
		bool	wasSigned = form.getWasSigned();

		form.beSigned(*this);
		std::cout << "Bureaucrat " << name << " (Grade " << grade << ") signs a " << form.getName()
		<< " (s.grade " << form.getRequirementSign() << ", ex.grade " << form.getRequirementExec()
		<< ")";
		if (wasSigned)
			std::cout << " (Signed)." << std::endl;
		else
			std::cout << " (Unsigned)." << std::endl;
		
	} catch (Form::GradeTooLowException) {
		std::cout << "Bureaucrat " << name << " cannot sign " << form.getName() << " because his grade is too low (His grade is "
			<< grade << " but should be at least " << form.getRequirementSign() << ")." << std::endl;
	} catch (std::exception) {
		std::cout << "Bureaucrat " << name << " cannot sign " << form.getName() << " because of an unknown reason." << std::endl;
	}
}
Пример #17
0
void
Bureaucrat::executeForm(Form const & f) {
	try {
		f.execute(*this);
		std::cout << this->_name << " executes " << f.getName() << "." << std::endl;
	}
	catch (std::exception & e) {
		std::cout << e.what() << std::endl;
	}
	return ;
}
Пример #18
0
void
Bureaucrat::signForm(Form & f) {
	if (this->_grade > f.getSignGrade()) {
		std::cout << this->_name << " cannot sign because "; 
		throw Bureaucrat::GradeTooLowException();
	}
	else {
		f.beSigned(*this);
		std::cout << this->_name << " signs " << f.getName() << std::endl;
	}
	return;
}
Пример #19
0
Form*		Intern::makeForm( std::string name, std::string target )
{
	Form* form = NULL;
	if (name == "robotomy request")
		form = new RobotomyRequestForm(target);
	else if (name == "presidential pardon")
		form = new PresidentialPardonForm(target);
	else if (name == "shrubbery creation")
		form = new ShrubberyCreationForm(target);
	else
	{
		std::cout << name << " form doesn't exist" << std::endl;
		return form;
	}
	std::cout << "Intern creates " << form->getName() << std::endl;
	return form;
}
Пример #20
0
/*
** public
*/
Form					*Intern::makeForm(std::string const &name, std::string const &target)
{
	Form *form;

	if (name == "robotomy request")
		form = new RobotomyRequestForm(target);
	else if (name == "presidential pardon")
		form = new PresidentialPardonForm(target);
	else if (name == "shrubbery creation")
		form = new ShrubberyCreationForm(target);
	else
		form = NULL;

	if (form)
		std::cout << "Intern creates " << form->getName() << "." << std::endl;
	else
		std::cout << "Intern creatation failed." << std::endl;

	return form;
}
Пример #21
0
Form::Form( Form const & src ) : _name(src.getName()), _sign_grade(src.getSignGrade()),
 _exec_grade(src.getExecGrade()), _status( src.getStatus() )
{
	*this = src;
	return ;
}
Пример #22
0
Form::Form( Form const & src ) :
    _name(src.getName()), _signed(src.getSigned()), _signGrade(src.getSignGrade()),
    _executeGrade(src.getExecuteGrade())
{
}
Пример #23
0
Form::Form(Form const & src): m_name(src.getName()), m_sgrade(src.getSGrade()), m_xgrade(src.getXGrade())
{
	*this = src;
	return;
}