41 lines
963 B
C++
41 lines
963 B
C++
#include "singleton_manager.h"
|
|
|
|
#include "singleton.h"
|
|
|
|
bool singleton_initliazer::has_init(singleton* s) {
|
|
return std::ranges::find(singletons_, s) != singletons_.end();
|
|
}
|
|
|
|
void singleton_initliazer::init_singleton(singleton* s) {
|
|
if (!has_init(s)) {
|
|
singletons_.push_back(s);
|
|
s->init(*this);
|
|
}
|
|
}
|
|
|
|
void singleton_manager::add(singleton* s) {
|
|
singletons_.push_back(s);
|
|
}
|
|
|
|
void singleton_manager::init() {
|
|
singleton_initliazer initliazer;
|
|
for (const auto s : singletons_) {
|
|
initliazer.init_singleton(s);
|
|
}
|
|
for (const auto s : singletons_) {
|
|
s->post_init();
|
|
}
|
|
singletons_ = initliazer.singletons_;
|
|
}
|
|
|
|
void singleton_manager::release() const {
|
|
for (int32_t j = singletons_.size() - 1; j >= 0; --j) {
|
|
auto s = singletons_[j];
|
|
s->begin_release();
|
|
}
|
|
for (int32_t j = singletons_.size() - 1; j >= 0; --j) {
|
|
auto s = singletons_[j];
|
|
s->release();
|
|
}
|
|
}
|