logic: add name delimiter to NameHierarchy

* NameHierarchy now looks like this: <delimiter>\tm<all the rest>
* made new baseclasses for SettingsMigration and SettingsMigrator
* Use the migration system for SqliteBookmarkStorage as well
This commit is contained in:
malte_langkabel
2017-05-16 13:08:12 +02:00
parent 6d0f633d24
commit c551c9a1dd
71 changed files with 692 additions and 523 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ ValType Cache<KeyType, ValType, Hasher>::getValue(KeyType key)
}
++m_missCount;
ValType val = m_calculator(key);
m_map[key] = val;
m_map.insert(std::pair<KeyType, ValType>(key, val));
return val;
}
@@ -10,6 +10,10 @@ class MessageActivateNodes
public:
struct ActiveNode
{
ActiveNode()
: nodeId(0)
, nameHierarchy(NAME_DELIMITER_UNKNOWN)
{ }
Id nodeId;
NameHierarchy nameHierarchy;
};
@@ -36,7 +36,7 @@ public:
{
if (!m_matches[i].subtext.empty())
{
ss << m_matches[i].subtext << NameHierarchy::getDelimiter();
ss << m_matches[i].subtext << m_matches[i].delimiter;
}
ss << m_matches[i].name;
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef MIGRATION_H
#define MIGRATION_H
template <typename MigratableType>
class Migration
{
public:
virtual ~Migration();
virtual void apply(MigratableType* migratable) const = 0;
};
template <typename MigratableType>
Migration<MigratableType>::~Migration()
{
}
#endif // MIGRATION_H
+87
View File
@@ -0,0 +1,87 @@
#ifndef MIGRATOR_H
#define MIGRATOR_H
#include <map>
#include <memory>
#include "utility/migration/Migration.h"
template <typename MigratableType>
class Migrator
{
public:
virtual ~Migrator();
void addMigration(size_t targetVersion, std::shared_ptr<Migration<MigratableType>> migration);
bool willMigrate(const MigratableType* migratable, size_t targetVersion) const;
bool migrate(MigratableType* migratable, size_t targetVersion) const;
private:
typedef std::multimap<size_t, std::shared_ptr<Migration<MigratableType>>> MigrationMap;
MigrationMap m_migrations;
};
template <typename MigratableType>
Migrator<MigratableType>::~Migrator()
{
}
template <typename MigratableType>
void Migrator<MigratableType>::addMigration(size_t targetVersion, std::shared_ptr<Migration<MigratableType>> migration)
{
if (migration)
{
m_migrations.emplace(targetVersion, migration);
}
}
template <typename MigratableType>
bool Migrator<MigratableType>::willMigrate(const MigratableType* migratable, size_t targetVersion) const
{
size_t sourceVersion = migratable->getVersion();
if (sourceVersion < targetVersion)
{
for (; sourceVersion <= targetVersion; sourceVersion++)
{
std::pair<MigrationMap::const_iterator, MigrationMap::const_iterator> ret;
ret = m_migrations.equal_range(sourceVersion);
for (MigrationMap::const_iterator it = ret.first; it != ret.second; it++)
{
return true;
}
}
}
return false;
}
template <typename MigratableType>
bool Migrator<MigratableType>::migrate(MigratableType* migratable, size_t targetVersion) const
{
size_t sourceVersion = migratable->getVersion();
if (sourceVersion < targetVersion)
{
for (; sourceVersion <= targetVersion; sourceVersion++)
{
std::pair<MigrationMap::const_iterator, MigrationMap::const_iterator> ret;
ret = m_migrations.equal_range(sourceVersion);
for (MigrationMap::const_iterator it = ret.first; it != ret.second; it++)
{
it->second->apply(migratable);
}
}
migratable->setVersion(targetVersion);
return true;
}
return false;
}
#endif // MIGRATOR_H