summaryrefslogtreecommitdiffhomepage
path: root/migration/migration.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'migration/migration.hpp')
-rw-r--r--migration/migration.hpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/migration/migration.hpp b/migration/migration.hpp
index 5f99de7a..7fc18c97 100644
--- a/migration/migration.hpp
+++ b/migration/migration.hpp
@@ -9,29 +9,43 @@
#pragma once
#include <QString>
-#include <vector>
-
#include "export.hpp"
+#include <memory>
+#include <vector>
+#include <functional>
+
namespace migrations {
-class migration;
+struct migration;
class registrator;
namespace detail {
- class migrator final
+ using mptr = std::shared_ptr<migration>;
+ using mfun = std::function<mptr ()>;
+
+ struct migrator
{
- static std::vector<migration*>& migrations();
+ static std::vector<QString> run();
+ static void add_migration_thunk(std::function<mptr()>& thunk);
+ static void mark_profile_as_not_needing_migration();
+
+ private:
+ static void sort_migrations();
+
+ static void register_migration(const mptr& m);
+ static std::vector<mptr>& migrations();
+
+ static void eval_thunks();
+
static QString last_migration_time();
static QString time_after_migrations();
+
static void set_last_migration_time(const QString& val);
- migrator() = delete;
- static std::vector<migration*> sorted_migrations();
static int to_int(const QString& str, bool& ok);
- public:
- static std::vector<QString> run();
- static void register_migration(migration* m);
- static void mark_config_as_not_needing_migration();
+
+ static std::vector<mptr>& migration_list();
+ static std::vector<mfun>& migration_thunks();
};
template<typename t>
@@ -39,31 +53,28 @@ namespace detail {
{
registrator()
{
- static t m;
- migrator::register_migration(static_cast<migration*>(&m));
+ mfun f { [] { return std::shared_ptr<migration>(new t); } };
+
+ migrator::add_migration_thunk(f);
}
};
}
-#ifndef __COUNTER__
-# error "oops, need __COUNTER__ extension for preprocessor"
-#endif
+#define OPENTRACK_MIGRATION3(type, ctr) \
+ static const char init_##ctr = (::migrations::detail::registrator<type>{}, 0);
-#define OPENTRACK_MIGRATION(type) static ::migrations::detail::registrator<type> opentrack_migration_registrator__ ## __COUNTER__ ## _gensym
+#define OPENTRACK_MIGRATION2(type, ctr) \
+ OPENTRACK_MIGRATION3(type, ctr)
-#ifdef Q_CREATOR_RUN
-# pragma clang diagnostic ignored "-Wweak-vtables"
-#endif
+#define OPENTRACK_MIGRATION(type) \
+ OPENTRACK_MIGRATION2(type, __COUNTER__)
-class migration
+struct migration
{
- migration& operator=(const migration&) = delete;
+ migration();
migration(const migration&) = delete;
- migration& operator=(migration&&) = delete;
- migration(migration&&) = delete;
+ migration& operator=(const migration&) = delete;
-public:
- migration();
virtual ~migration();
virtual QString unique_date() const = 0;
virtual QString name() const = 0;
@@ -71,7 +82,7 @@ public:
virtual void run() = 0;
};
-}
+} // ns migrations
OTR_MIGRATION_EXPORT std::vector<QString> run_migrations();
-OTR_MIGRATION_EXPORT void mark_config_as_not_needing_migration();
+OTR_MIGRATION_EXPORT void mark_profile_as_not_needing_migration();