From 526304a41970c1ad890cf81d92bb4b123e8608e7 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 28 Apr 2018 17:19:27 +0200 Subject: migration: use thunks Otherwise we get QCoreApplication used before QApplication instance is created. Requesting the sorted migration data will force the thunks. --- migration/migration.hpp | 60 +++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'migration/migration.hpp') diff --git a/migration/migration.hpp b/migration/migration.hpp index 5f99de7a..e81e0ae5 100644 --- a/migration/migration.hpp +++ b/migration/migration.hpp @@ -13,25 +13,36 @@ #include "export.hpp" +#include + namespace migrations { -class migration; +struct migration; class registrator; namespace detail { - class migrator final + using mptr = std::shared_ptr; + using mfun = std::function; + + struct migrator { - static std::vector& migrations(); + static std::vector run(); + static void add_migration_thunk(std::function& thunk); + static void mark_config_as_not_needing_migration(); + + private: + static void sort_migrations(); + + static void register_migration(mptr m); + static std::vector& 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 sorted_migrations(); static int to_int(const QString& str, bool& ok); - public: - static std::vector run(); - static void register_migration(migration* m); - static void mark_config_as_not_needing_migration(); }; template @@ -39,8 +50,9 @@ namespace detail { { registrator() { - static t m; - migrator::register_migration(static_cast(&m)); + mfun f { []() { return std::shared_ptr(new t); } }; + + migrator::add_migration_thunk(f); } }; } @@ -49,29 +61,33 @@ namespace detail { # error "oops, need __COUNTER__ extension for preprocessor" #endif -#define OPENTRACK_MIGRATION(type) static ::migrations::detail::registrator opentrack_migration_registrator__ ## __COUNTER__ ## _gensym +#define MIGRATE_EXPAND2(x) x +#define MIGRATE_EXPAND1(x) MIGRATE_EXPAND2(x) +#define MIGRATE_EXPANDED2(type, ctr) \ + static ::migrations::detail::registrator opentrack_migration_registrator_ ## ctr +#define MIGRATE_EXPANDED1(type, ctr) \ + MIGRATE_EXPANDED2(type, ctr) + +#define OPENTRACK_MIGRATION(type) \ + MIGRATE_EXPANDED1(type, MIGRATE_EXPAND1(__COUNTER__)) #ifdef Q_CREATOR_RUN # pragma clang diagnostic ignored "-Wweak-vtables" #endif -class migration +struct migration { - migration& operator=(const migration&) = delete; - migration(const migration&) = delete; - migration& operator=(migration&&) = delete; - migration(migration&&) = delete; - -public: - migration(); - virtual ~migration(); + migration() = default; + inline virtual ~migration(); virtual QString unique_date() const = 0; virtual QString name() const = 0; virtual bool should_run() const = 0; virtual void run() = 0; }; -} +inline migration::~migration() {} + +} // ns migrations OTR_MIGRATION_EXPORT std::vector run_migrations(); OTR_MIGRATION_EXPORT void mark_config_as_not_needing_migration(); -- cgit v1.2.3