Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes on how Singleton destroyed #25

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Personal.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,13 @@ class PersonalFactory {
_prototypes.push_back(std::make_shared<PersonalSpecific>());
_prototypes.push_back(std::make_shared<PersonalExcept>());
}
public:

/**
* Destructor
*
*/
~PersonalFactory() {
delete _instance;
// Do nothing.
}

public:
Expand All @@ -360,14 +364,23 @@ class PersonalFactory {
*
* @return PersonalFactory*
*/
static PersonalFactory* instance() {
static PersonalFactory* getInstance() {
if (_instance == NULL) {
_instance = new PersonalFactory();
}

return _instance;
}

/**
* Destroy current instance.
*
*/
static void resetInstance() {
delete _instance;
_instance = NULL;
}

/**
* Return total items inside _prototypes.
*
Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ int main(int argc, char* argv[]) {

// Create a new IPersonal instance.
try {
std::shared_ptr<IPersonal> chumeochuixoong = PersonalFactory::instance()->create(argc, argv);
std::shared_ptr<IPersonal> chumeochuixoong = PersonalFactory::getInstance()->create(argc, argv);

// Print the textart.
OutputHelper::printTextart();

// Print the stats.
std::cout << "Total passed classes: " << chumeochuixoong->getTotalClassesPassed()
<< " (" << Utility::percent(chumeochuixoong->getTotalClassesPassed(), chumeochuixoong->getTotalClasses())
<< " (" << Utility::percent(chumeochuixoong->getTotalClassesPassed(),
chumeochuixoong->getTotalClasses())
<< "%)" << '\n';

// Print passed table
Expand All @@ -29,11 +30,15 @@ int main(int argc, char* argv[]) {

// Print failed stats.
std::cout << "Total failed classes: " << chumeochuixoong->getTotalClassesFailed()
<< " (" << Utility::percent(chumeochuixoong->getTotalClassesFailed(), chumeochuixoong->getTotalClasses())
<< " (" << Utility::percent(chumeochuixoong->getTotalClassesFailed(),
chumeochuixoong->getTotalClasses())
<< "%)" << '\n';

// Print failed table.
OutputHelper::printTable(chumeochuixoong->toFailedVector(), false);

// Release created PersonalFactory
PersonalFactory::resetInstance();
}

// And catch exceptions
Expand Down