Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
    }
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}

}
Ejemplo n.º 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 ;
}
Ejemplo n.º 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;
    }
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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;
	}

}
Ejemplo n.º 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;
    }
}
Ejemplo n.º 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;
}
Ejemplo n.º 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 ;
}
Ejemplo n.º 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;
	}
}
Ejemplo n.º 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 ;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 21
0
Form::Form( Form const & src ) : _name(src.getName()), _sign_grade(src.getSignGrade()),
 _exec_grade(src.getExecGrade()), _status( src.getStatus() )
{
	*this = src;
	return ;
}
Ejemplo n.º 22
0
Archivo: Form.cpp Proyecto: Hadopire/42
Form::Form( Form const & src ) :
    _name(src.getName()), _signed(src.getSigned()), _signGrade(src.getSignGrade()),
    _executeGrade(src.getExecuteGrade())
{
}
Ejemplo n.º 23
0
Form::Form(Form const & src): m_name(src.getName()), m_sgrade(src.getSGrade()), m_xgrade(src.getXGrade())
{
	*this = src;
	return;
}