summaryrefslogtreecommitdiffhomepage
path: root/migration
diff options
context:
space:
mode:
Diffstat (limited to 'migration')
-rw-r--r--migration/migration.cpp31
-rw-r--r--migration/migration.hpp3
2 files changed, 24 insertions, 10 deletions
diff --git a/migration/migration.cpp b/migration/migration.cpp
index 4ddb2c8c..f4b1739b 100644
--- a/migration/migration.cpp
+++ b/migration/migration.cpp
@@ -26,14 +26,25 @@ using namespace options::globals;
namespace migrations::detail {
-static std::vector<mptr> migration_list;
-static std::vector<mfun> migration_thunks;
+
+std::vector<mptr>& migrator::migration_list()
+{
+ static std::vector<mptr> v;
+ return v;
+}
+
+std::vector<mfun>& migrator::migration_thunks()
+{
+ static std::vector<mfun> v;
+ return v;
+}
+
void migrator::register_migration(mptr const& m)
{
const QString date = m->unique_date();
- for (mptr const& m2 : migration_list)
+ for (mptr const& m2 : migration_list())
if (m2->unique_date() == date)
std::abort();
@@ -65,35 +76,35 @@ void migrator::register_migration(mptr const& m)
if (day_ < 1 || day_ > 31)
abort();
- migration_list.push_back(m);
+ migration_list().push_back(m);
}
void migrator::eval_thunks()
{
- for (auto& fun : migration_thunks)
+ for (auto& fun : migration_thunks())
{
mptr m = fun();
register_migration(m);
}
- if (!migration_thunks.empty())
+ if (!migration_thunks().empty())
sort_migrations();
- migration_thunks.clear();
+ migration_thunks().clear();
}
void migrator::add_migration_thunk(mfun& thunk)
{
- migration_thunks.push_back(thunk);
+ migration_thunks().push_back(thunk);
}
std::vector<mptr>& migrator::migrations()
{
eval_thunks();
- return migration_list;
+ return migration_list();
}
void migrator::sort_migrations()
{
- std::sort(migration_list.begin(), migration_list.end(),
+ std::sort(migration_list().begin(), migration_list().end(),
[](const mptr x, const mptr y) {
return x->unique_date() < y->unique_date();
});
diff --git a/migration/migration.hpp b/migration/migration.hpp
index a3035247..7fc18c97 100644
--- a/migration/migration.hpp
+++ b/migration/migration.hpp
@@ -43,6 +43,9 @@ namespace detail {
static void set_last_migration_time(const QString& val);
static int to_int(const QString& str, bool& ok);
+
+ static std::vector<mptr>& migration_list();
+ static std::vector<mfun>& migration_thunks();
};
template<typename t>