Refactor form classes and improve formatting for consistency
This commit is contained in:
parent
c392424d91
commit
e631a84565
93
.clang-format
Normal file
93
.clang-format
Normal file
@ -0,0 +1,93 @@
|
||||
# .clang-format
|
||||
---
|
||||
# Base style to inherit from (llvm, google, chromium, microsoft, mozilla, webkit)
|
||||
BasedOnStyle: microsoft
|
||||
|
||||
# Indentation
|
||||
IndentWidth: 4 # Number of spaces per indent level
|
||||
TabWidth: 4 # Number of spaces per tab
|
||||
UseTab: Never # Options: Never, ForIndentation, Always
|
||||
|
||||
# Braces
|
||||
BreakBeforeBraces: Allman # Options: Attach, Linux, Stroustrup, Allman, GNU, WebKit, Custom
|
||||
BraceWrapping:
|
||||
AfterClass: true # Put brace on new line after class
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
|
||||
# Spaces
|
||||
SpaceBeforeParens: ControlStatements # Options: Never, ControlStatements, Always
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpacesInAngles: false
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
|
||||
# Alignment
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
|
||||
# Column limit
|
||||
ColumnLimit: 80 # Max line length before wrapping
|
||||
|
||||
# Pointer/reference alignment
|
||||
PointerAlignment: Right # Options: Left, Right, Middle
|
||||
|
||||
# Includes
|
||||
IncludeBlocks: Regroup # Options: Preserve, Merge, Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^<.*>'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^".*\.hpp"'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^".*\.h"'
|
||||
Priority: 4
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
SortIncludes: true
|
||||
|
||||
# Function declaration/definition formatting
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
BinPackParameters: true
|
||||
BinPackArguments: true
|
||||
|
||||
# Namespace indentation
|
||||
NamespaceIndentation: None # Options: None, Inner, All
|
||||
|
||||
# Constructor initializer formatting
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
|
||||
# Access modifier indentation
|
||||
AccessModifierOffset: -2
|
||||
|
||||
# Trailing commas
|
||||
Cpp11BracedListStyle: true
|
||||
|
||||
# Comment formatting
|
||||
ReflowComments: true
|
||||
SpacesBeforeTrailingComments: 1
|
||||
|
||||
# Misc
|
||||
IndentCaseLabels: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MaxEmptyLinesToKeep: 1
|
||||
@ -15,9 +15,10 @@ class PresidentialPardonForm : public AForm
|
||||
PresidentialPardonForm(std::string target);
|
||||
PresidentialPardonForm(const PresidentialPardonForm &other);
|
||||
~PresidentialPardonForm();
|
||||
PresidentialPardonForm &operator=(const PresidentialPardonForm &other) = delete;
|
||||
PresidentialPardonForm &operator=(const PresidentialPardonForm &other) =
|
||||
delete;
|
||||
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
const std::string getTarget() const;
|
||||
};
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class RobotomyRequestForm : public AForm
|
||||
~RobotomyRequestForm();
|
||||
RobotomyRequestForm &operator=(const RobotomyRequestForm &other) = delete;
|
||||
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
const std::string getTarget() const;
|
||||
};
|
||||
|
||||
|
||||
@ -15,9 +15,10 @@ class ShrubberyCreationForm : public AForm
|
||||
ShrubberyCreationForm(std::string target);
|
||||
ShrubberyCreationForm(const ShrubberyCreationForm &other);
|
||||
~ShrubberyCreationForm();
|
||||
ShrubberyCreationForm &operator=(const ShrubberyCreationForm &other) = delete;
|
||||
ShrubberyCreationForm &operator=(const ShrubberyCreationForm &other) =
|
||||
delete;
|
||||
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
void execute(const Bureaucrat &executor) const override;
|
||||
const std::string getTarget() const;
|
||||
};
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
|
||||
#define BUREAUCRAT BOLD BACKGROUND4 " Bureaucrat: " RESET " "
|
||||
#define AFORM BOLD BACKGROUND5 " AForm: " RESET " "
|
||||
#define SHRUBBERY_CREATION_FORM BOLD BACKGROUND6 " ShrubberyCreationForm: " RESET " "
|
||||
#define ROBOTOMY_REQUEST_FORM BOLD BACKGROUND7 " RobotomyRequestForm: " RESET " "
|
||||
#define PRESIDENTIAL_PARDON_FORM BOLD BACKGROUND8 " PresidentialPardonForm: " RESET " "
|
||||
#define SHRUBBERY_CREATION_FORM BOLD BACKGROUND10 " ShrubberyCreationForm: " RESET " "
|
||||
#define ROBOTOMY_REQUEST_FORM BOLD BACKGROUND11 " RobotomyRequestForm: " RESET " "
|
||||
#define PRESIDENTIAL_PARDON_FORM BOLD BACKGROUND9 " PresidentialPardonForm: " RESET " "
|
||||
|
||||
#define CONSTRUCTOR "Constructor called"
|
||||
#define PARAMETERIZED_CONSTRUCTOR "Parameterized constructor called"
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
#include "PresidentialPardonForm.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "AForm.hpp"
|
||||
#include "PresidentialPardonForm.hpp"
|
||||
|
||||
#include "colors.h"
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm(std::string target)
|
||||
: AForm("PresidaentialPardonForm", 1, 1), _target(target)
|
||||
: AForm("Presidential Pardon", 25, 5), _target(target)
|
||||
{
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM PARAMETERIZED_CONSTRUCTOR << std::endl;
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM PARAMETERIZED_CONSTRUCTOR
|
||||
<< std::endl;
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM << *this << std::endl;
|
||||
}
|
||||
|
||||
@ -17,7 +20,8 @@ PresidentialPardonForm::~PresidentialPardonForm()
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM DESTRUCTOR << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &other)
|
||||
PresidentialPardonForm::PresidentialPardonForm(
|
||||
const PresidentialPardonForm &other)
|
||||
: AForm(other), _target(other._target)
|
||||
{
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM COPY_CONSTRUCTOR << std::endl;
|
||||
@ -26,8 +30,10 @@ PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &oth
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const PresidentialPardonForm &form)
|
||||
{
|
||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
||||
os << form.getName()
|
||||
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade()
|
||||
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||
<< ", Target: " << form.getTarget();
|
||||
return os;
|
||||
}
|
||||
@ -39,7 +45,8 @@ void PresidentialPardonForm::execute(const Bureaucrat &executor) const
|
||||
if (executor.getGrade() > getExecuteGrade())
|
||||
throw AForm::GradeTooLowException();
|
||||
|
||||
std::cout << "Presidential pardon granted to " << _target << " by " << executor.getName() << "." << std::endl;
|
||||
std::cout << PRESIDENTIAL_PARDON_FORM<< executor.getName() << " made shure Zaphod Beeblebrox pardoned "
|
||||
<< _target << "." << std::endl;
|
||||
}
|
||||
|
||||
const std::string PresidentialPardonForm::getTarget() const
|
||||
|
||||
@ -1,16 +1,20 @@
|
||||
#include "RobotomyRequestForm.hpp"
|
||||
#include "colors.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(std::string target) : AForm("RobotomyRequestForm", 72, 45), _target(target)
|
||||
#include "colors.h"
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(std::string target)
|
||||
: AForm("Robotomy Request", 72, 45), _target(target)
|
||||
{
|
||||
std::cout << ROBOTOMY_REQUEST_FORM PARAMETERIZED_CONSTRUCTOR << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &other) : AForm(other), _target(other._target)
|
||||
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &other)
|
||||
: AForm(other), _target(other._target)
|
||||
{
|
||||
std::cout << ROBOTOMY_REQUEST_FORM COPY_CONSTRUCTOR << std::endl;
|
||||
}
|
||||
@ -27,12 +31,16 @@ void RobotomyRequestForm::execute(const Bureaucrat &executor) const
|
||||
if (executor.getGrade() > getExecuteGrade())
|
||||
throw AForm::GradeTooLowException();
|
||||
|
||||
std::cout << "Drilling noises... ";
|
||||
std::cout << ROBOTOMY_REQUEST_FORM DESTRUCTOR
|
||||
<< "Drrr, Drrr. Drilling noises... " << std::endl;
|
||||
std::srand(static_cast<unsigned int>(std::time(0)));
|
||||
if (std::rand() % 2)
|
||||
std::cout << _target << " has been robotomized successfully!" << std::endl;
|
||||
std::cout << ROBOTOMY_REQUEST_FORM DESTRUCTOR << _target
|
||||
<< " has been robotomized!" << std::endl;
|
||||
else
|
||||
std::cout << "Robotomy failed for " << _target << "." << std::endl;
|
||||
std::cout << ROBOTOMY_REQUEST_FORM DESTRUCTOR << _target
|
||||
<< "'s robotomy failed. " << _target
|
||||
<< " is not the same anymore..." << std::endl;
|
||||
}
|
||||
|
||||
const std::string RobotomyRequestForm::getTarget() const
|
||||
@ -42,8 +50,10 @@ const std::string RobotomyRequestForm::getTarget() const
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const RobotomyRequestForm &form)
|
||||
{
|
||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
||||
os << form.getName()
|
||||
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade()
|
||||
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||
<< ", Target: " << form.getTarget();
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
#include "AForm.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
#include "ShrubberyCreationForm.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "ShrubberyCreationForm.hpp"
|
||||
#include "AForm.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
#include "colors.h"
|
||||
|
||||
ShrubberyCreationForm::ShrubberyCreationForm(std::string target)
|
||||
: AForm("ShrubberyCreationForm", 145, 137), _target(target)
|
||||
: AForm("Shrubbery Creation", 145, 137), _target(target)
|
||||
{
|
||||
std::cout << SHRUBBERY_CREATION_FORM PARAMETERIZED_CONSTRUCTOR << std::endl;
|
||||
std::cout << SHRUBBERY_CREATION_FORM << *this << std::endl;
|
||||
@ -35,27 +37,29 @@ void ShrubberyCreationForm::execute(const Bureaucrat &executor) const
|
||||
std::ofstream ofs(_target + "_shrubbery");
|
||||
if (!ofs)
|
||||
{
|
||||
std::cerr << "Error creating file: " << _target << "_shrubbery" << std::endl;
|
||||
std::cerr << "Error creating file: " << _target << "_shrubbery"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
ofs << " # #### ####\n"
|
||||
<< " ### \\/#|### |/####\n"
|
||||
<< " ##\\/#/ \\||/##/_/##/_#\n"
|
||||
<< " ### \\/###|/ \\/ # ###\n"
|
||||
<< " ##_\\_#\\_\\## | #/###_/_####\n"
|
||||
<< " ## #### # \\ #| / #### ##/##\n"
|
||||
<< " __#_--###` |{,###---###-~\n"
|
||||
<< " \\ }{\n"
|
||||
<< " }}{\n"
|
||||
<< " }}{\n"
|
||||
<< " ejm {{}\n"
|
||||
<< " , -=-~{ .-^- _\n"
|
||||
<< " `}\n"
|
||||
<< " {\n";
|
||||
ofs << " # #### ####\n"
|
||||
<< " ### \\/#|### |/####\n"
|
||||
<< " ##\\/#/ \\||/##/_/##/_#\n"
|
||||
<< " ### \\/###|/ \\/ # ###\n"
|
||||
<< " ##_\\_#\\_\\## | #/###_/_####\n"
|
||||
<< " ## #### # \\ #| / #### ##/##\n"
|
||||
<< " __#_--###` |{,###---###-~\n"
|
||||
<< " \\ }{\n"
|
||||
<< " }}{\n"
|
||||
<< " }}{\n"
|
||||
<< " {{}\n"
|
||||
<< " , -=-~{ .-^- _\n"
|
||||
<< " `}\n"
|
||||
<< " {\n";
|
||||
|
||||
ofs.close();
|
||||
std::cout << "Shrubbery created in file: " << _target << "_shrubbery" << std::endl;
|
||||
std::cout << SHRUBBERY_CREATION_FORM << "Shrubbery created in file: " << _target << "_shrubbery"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
const std::string ShrubberyCreationForm::getTarget() const
|
||||
@ -65,9 +69,10 @@ const std::string ShrubberyCreationForm::getTarget() const
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const ShrubberyCreationForm &form)
|
||||
{
|
||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
||||
os << form.getName()
|
||||
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||
<< ", Sign Grade: " << form.getSignGrade()
|
||||
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||
<< ", Target: " << form.getTarget();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user