/* Copyright (c) 2016, Stanislaw Halik * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, * provided that the above copyright notice and this permission * notice appear in all copies. */ #pragma once #include #include #include "export.hpp" #include namespace migrations { struct migration; class registrator; namespace detail { using mptr = std::shared_ptr; using mfun = std::function; struct migrator { 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); static int to_int(const QString& str, bool& ok); }; template struct registrator final { registrator() { mfun f { []() { return std::shared_ptr(new t); } }; migrator::add_migration_thunk(f); } }; } #ifndef __COUNTER__ # error "oops, need __COUNTER__ extension for preprocessor" #endif #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 struct 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();