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(std::string target);
|
||||||
PresidentialPardonForm(const PresidentialPardonForm &other);
|
PresidentialPardonForm(const PresidentialPardonForm &other);
|
||||||
~PresidentialPardonForm();
|
~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;
|
const std::string getTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class RobotomyRequestForm : public AForm
|
|||||||
~RobotomyRequestForm();
|
~RobotomyRequestForm();
|
||||||
RobotomyRequestForm &operator=(const RobotomyRequestForm &other) = delete;
|
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;
|
const std::string getTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,9 +15,10 @@ class ShrubberyCreationForm : public AForm
|
|||||||
ShrubberyCreationForm(std::string target);
|
ShrubberyCreationForm(std::string target);
|
||||||
ShrubberyCreationForm(const ShrubberyCreationForm &other);
|
ShrubberyCreationForm(const ShrubberyCreationForm &other);
|
||||||
~ShrubberyCreationForm();
|
~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;
|
const std::string getTarget() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#define BUREAUCRAT BOLD BACKGROUND4 " Bureaucrat: " RESET " "
|
#define BUREAUCRAT BOLD BACKGROUND4 " Bureaucrat: " RESET " "
|
||||||
#define AFORM BOLD BACKGROUND5 " AForm: " RESET " "
|
#define AFORM BOLD BACKGROUND5 " AForm: " RESET " "
|
||||||
#define SHRUBBERY_CREATION_FORM BOLD BACKGROUND6 " ShrubberyCreationForm: " RESET " "
|
#define SHRUBBERY_CREATION_FORM BOLD BACKGROUND10 " ShrubberyCreationForm: " RESET " "
|
||||||
#define ROBOTOMY_REQUEST_FORM BOLD BACKGROUND7 " RobotomyRequestForm: " RESET " "
|
#define ROBOTOMY_REQUEST_FORM BOLD BACKGROUND11 " RobotomyRequestForm: " RESET " "
|
||||||
#define PRESIDENTIAL_PARDON_FORM BOLD BACKGROUND8 " PresidentialPardonForm: " RESET " "
|
#define PRESIDENTIAL_PARDON_FORM BOLD BACKGROUND9 " PresidentialPardonForm: " RESET " "
|
||||||
|
|
||||||
#define CONSTRUCTOR "Constructor called"
|
#define CONSTRUCTOR "Constructor called"
|
||||||
#define PARAMETERIZED_CONSTRUCTOR "Parameterized constructor called"
|
#define PARAMETERIZED_CONSTRUCTOR "Parameterized constructor called"
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
|
#include "PresidentialPardonForm.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "AForm.hpp"
|
#include "AForm.hpp"
|
||||||
#include "PresidentialPardonForm.hpp"
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
|
||||||
PresidentialPardonForm::PresidentialPardonForm(std::string target)
|
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;
|
std::cout << PRESIDENTIAL_PARDON_FORM << *this << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +20,8 @@ PresidentialPardonForm::~PresidentialPardonForm()
|
|||||||
std::cout << PRESIDENTIAL_PARDON_FORM DESTRUCTOR << std::endl;
|
std::cout << PRESIDENTIAL_PARDON_FORM DESTRUCTOR << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &other)
|
PresidentialPardonForm::PresidentialPardonForm(
|
||||||
|
const PresidentialPardonForm &other)
|
||||||
: AForm(other), _target(other._target)
|
: AForm(other), _target(other._target)
|
||||||
{
|
{
|
||||||
std::cout << PRESIDENTIAL_PARDON_FORM COPY_CONSTRUCTOR << std::endl;
|
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)
|
std::ostream &operator<<(std::ostream &os, const PresidentialPardonForm &form)
|
||||||
{
|
{
|
||||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
os << form.getName()
|
||||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||||
|
<< ", Sign Grade: " << form.getSignGrade()
|
||||||
|
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||||
<< ", Target: " << form.getTarget();
|
<< ", Target: " << form.getTarget();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -39,7 +45,8 @@ void PresidentialPardonForm::execute(const Bureaucrat &executor) const
|
|||||||
if (executor.getGrade() > getExecuteGrade())
|
if (executor.getGrade() > getExecuteGrade())
|
||||||
throw AForm::GradeTooLowException();
|
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
|
const std::string PresidentialPardonForm::getTarget() const
|
||||||
|
|||||||
@ -1,16 +1,20 @@
|
|||||||
#include "RobotomyRequestForm.hpp"
|
#include "RobotomyRequestForm.hpp"
|
||||||
#include "colors.h"
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#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;
|
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;
|
std::cout << ROBOTOMY_REQUEST_FORM COPY_CONSTRUCTOR << std::endl;
|
||||||
}
|
}
|
||||||
@ -27,12 +31,16 @@ void RobotomyRequestForm::execute(const Bureaucrat &executor) const
|
|||||||
if (executor.getGrade() > getExecuteGrade())
|
if (executor.getGrade() > getExecuteGrade())
|
||||||
throw AForm::GradeTooLowException();
|
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)));
|
std::srand(static_cast<unsigned int>(std::time(0)));
|
||||||
if (std::rand() % 2)
|
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
|
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
|
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)
|
std::ostream &operator<<(std::ostream &os, const RobotomyRequestForm &form)
|
||||||
{
|
{
|
||||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
os << form.getName()
|
||||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||||
|
<< ", Sign Grade: " << form.getSignGrade()
|
||||||
|
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||||
<< ", Target: " << form.getTarget();
|
<< ", Target: " << form.getTarget();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
#include "AForm.hpp"
|
#include "ShrubberyCreationForm.hpp"
|
||||||
#include "Bureaucrat.hpp"
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "ShrubberyCreationForm.hpp"
|
#include "AForm.hpp"
|
||||||
|
#include "Bureaucrat.hpp"
|
||||||
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
|
|
||||||
ShrubberyCreationForm::ShrubberyCreationForm(std::string target)
|
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 PARAMETERIZED_CONSTRUCTOR << std::endl;
|
||||||
std::cout << SHRUBBERY_CREATION_FORM << *this << std::endl;
|
std::cout << SHRUBBERY_CREATION_FORM << *this << std::endl;
|
||||||
@ -23,7 +25,7 @@ ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &other)
|
|||||||
ShrubberyCreationForm::~ShrubberyCreationForm()
|
ShrubberyCreationForm::~ShrubberyCreationForm()
|
||||||
{
|
{
|
||||||
std::cout << SHRUBBERY_CREATION_FORM DESTRUCTOR << std::endl;
|
std::cout << SHRUBBERY_CREATION_FORM DESTRUCTOR << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShrubberyCreationForm::execute(const Bureaucrat &executor) const
|
void ShrubberyCreationForm::execute(const Bureaucrat &executor) const
|
||||||
{
|
{
|
||||||
@ -35,27 +37,29 @@ void ShrubberyCreationForm::execute(const Bureaucrat &executor) const
|
|||||||
std::ofstream ofs(_target + "_shrubbery");
|
std::ofstream ofs(_target + "_shrubbery");
|
||||||
if (!ofs)
|
if (!ofs)
|
||||||
{
|
{
|
||||||
std::cerr << "Error creating file: " << _target << "_shrubbery" << std::endl;
|
std::cerr << "Error creating file: " << _target << "_shrubbery"
|
||||||
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofs << " # #### ####\n"
|
ofs << " # #### ####\n"
|
||||||
<< " ### \\/#|### |/####\n"
|
<< " ### \\/#|### |/####\n"
|
||||||
<< " ##\\/#/ \\||/##/_/##/_#\n"
|
<< " ##\\/#/ \\||/##/_/##/_#\n"
|
||||||
<< " ### \\/###|/ \\/ # ###\n"
|
<< " ### \\/###|/ \\/ # ###\n"
|
||||||
<< " ##_\\_#\\_\\## | #/###_/_####\n"
|
<< " ##_\\_#\\_\\## | #/###_/_####\n"
|
||||||
<< " ## #### # \\ #| / #### ##/##\n"
|
<< " ## #### # \\ #| / #### ##/##\n"
|
||||||
<< " __#_--###` |{,###---###-~\n"
|
<< " __#_--###` |{,###---###-~\n"
|
||||||
<< " \\ }{\n"
|
<< " \\ }{\n"
|
||||||
<< " }}{\n"
|
<< " }}{\n"
|
||||||
<< " }}{\n"
|
<< " }}{\n"
|
||||||
<< " ejm {{}\n"
|
<< " {{}\n"
|
||||||
<< " , -=-~{ .-^- _\n"
|
<< " , -=-~{ .-^- _\n"
|
||||||
<< " `}\n"
|
<< " `}\n"
|
||||||
<< " {\n";
|
<< " {\n";
|
||||||
|
|
||||||
ofs.close();
|
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
|
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)
|
std::ostream &operator<<(std::ostream &os, const ShrubberyCreationForm &form)
|
||||||
{
|
{
|
||||||
os << form.getName() << " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
os << form.getName()
|
||||||
<< ", Sign Grade: " << form.getSignGrade() << ", Execute Grade: " << form.getExecuteGrade()
|
<< " Form: " << (form.getIsSigned() ? "Signed" : "Not Signed")
|
||||||
|
<< ", Sign Grade: " << form.getSignGrade()
|
||||||
|
<< ", Execute Grade: " << form.getExecuteGrade()
|
||||||
<< ", Target: " << form.getTarget();
|
<< ", Target: " << form.getTarget();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user