summaryrefslogtreecommitdiffhomepage
path: root/migration/migration.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'migration/migration.hpp')
-rw-r--r--migration/migration.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/migration/migration.hpp b/migration/migration.hpp
new file mode 100644
index 00000000..b9c20f15
--- /dev/null
+++ b/migration/migration.hpp
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <QString>
+#include <vector>
+
+#include "export.hpp"
+
+namespace migrations {
+
+class migration;
+class registrator;
+
+namespace detail {
+ class migrator final
+ {
+ using mm = migration*;
+ template<typename t> using vec_ = std::vector<t>;
+ using vstr = vec_<QString>;
+ using vec = vec_<mm>;
+ static vec& migrations();
+ static QString last_migration_time();
+ static QString time_after_migrations();
+ static void set_last_migration_time(const QString& val);
+ migrator() = delete;
+ static vec sorted_migrations();
+ public:
+ static vstr run();
+ static void register_migration(migration* m);
+ static void mark_config_as_not_needing_migration();
+ };
+
+ template<typename t>
+ struct registrator final
+ {
+ registrator()
+ {
+ static t m;
+ migrator::register_migration(static_cast<migration*>(&m));
+ }
+ };
+}
+
+#ifndef __COUNTER__
+# error "oops, need __COUNTER__ extension for preprocessor"
+#endif
+
+#define OPENTRACK_MIGRATION(type) static ::migrations::detail::registrator<type> opentrack_migration_registrator__ ## __COUNTER__ ## _gensym;
+
+#ifdef Q_CREATOR_RUN
+# pragma clang diagnostic ignored "-Wweak-vtables"
+#endif
+
+class migration
+{
+ migration& operator=(const migration&) = delete;
+ migration(const migration&) = delete;
+ migration& operator=(migration&&) = delete;
+ migration(migration&&) = delete;
+
+public:
+ migration();
+ virtual ~migration();
+ virtual QString unique_date() const = 0;
+ virtual QString name() const = 0;
+ virtual bool should_run() const = 0;
+ virtual void run() = 0;
+};
+
+}
+
+OPENTRACK_MIGRATION_EXPORT std::vector<QString> run_migrations();
+OPENTRACK_MIGRATION_EXPORT void mark_config_as_not_needing_migration();