logic: source groups for project settings
* project can not have multiple source groups with different types * language of a project is now inferred from source groups * setting global NameHierarchy delimiter of first sourceGroup in project * added project settings migrations for source groups * Add Settings Migration classes (MoveKey, DeleteKey, Lambda) * Update sample projects with migrations * added method to config to retrieve sublevel key names * implemented recursive removing of keys in settings * moved project files out of top level * removed solution parsing code as it is not used anymore fortune cookie message = The secret of getting ahead is getting started.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#include "settings/migration/Migration.h"
|
||||
|
||||
#include "settings/Settings.h"
|
||||
|
||||
Migration::~Migration()
|
||||
{
|
||||
}
|
||||
|
||||
bool Migration::isValueDefinedInSettings(const Settings* settings, const std::string& key) const
|
||||
{
|
||||
return settings->isValueDefined(key);
|
||||
}
|
||||
|
||||
void Migration::removeValuesInSettings(Settings* settings, const std::string& key) const
|
||||
{
|
||||
settings->removeValues(key);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef MIGRATION_H
|
||||
#define MIGRATION_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "settings/Settings.h"
|
||||
|
||||
class Migration
|
||||
{
|
||||
public:
|
||||
virtual ~Migration();
|
||||
virtual void apply(Settings* settings) const = 0;
|
||||
|
||||
bool isValueDefinedInSettings(const Settings* settings, const std::string& key) const;
|
||||
|
||||
template <typename T>
|
||||
T getValueFromSettings(Settings* settings, const std::string& key, T defaultValue) const;
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> getValuesFromSettings(Settings* settings, const std::string& key, std::vector<T> defaultValues) const;
|
||||
|
||||
template<typename T>
|
||||
bool setValueInSettings(Settings* settings, const std::string& key, T value) const;
|
||||
|
||||
template<typename T>
|
||||
bool setValuesInSettings(Settings* settings, const std::string& key, std::vector<T> values) const;
|
||||
|
||||
void removeValuesInSettings(Settings* settings, const std::string& key) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T Migration::getValueFromSettings(Settings* settings, const std::string& key, T defaultValue) const
|
||||
{
|
||||
return settings->getValue(key, defaultValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> Migration::getValuesFromSettings(Settings* settings, const std::string& key, std::vector<T> defaultValues) const
|
||||
{
|
||||
return settings->getValues(key, defaultValues);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Migration::setValueInSettings(Settings* settings, const std::string& key, T value) const
|
||||
{
|
||||
return settings->setValue(key, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Migration::setValuesInSettings(Settings* settings, const std::string& key, std::vector<T> values) const
|
||||
{
|
||||
return settings->setValues(key, values);
|
||||
}
|
||||
|
||||
#endif // MIGRATION_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "settings/migration/MigrationDeleteKey.h"
|
||||
|
||||
MigrationDeleteKey::MigrationDeleteKey(const std::string& key)
|
||||
: m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
void MigrationDeleteKey::apply(Settings* settings) const
|
||||
{
|
||||
removeValuesInSettings(settings, m_key);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef MIGRATION_DELETE_KEY_H
|
||||
#define MIGRATION_DELETE_KEY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "settings/migration/Migration.h"
|
||||
|
||||
class MigrationDeleteKey: public Migration
|
||||
{
|
||||
public:
|
||||
MigrationDeleteKey(const std::string& key);
|
||||
virtual void apply(Settings* settings) const;
|
||||
|
||||
private:
|
||||
const std::string m_key;
|
||||
};
|
||||
|
||||
#endif // MIGRATION_DELETE_KEY_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "settings/migration/MigrationLambda.h"
|
||||
|
||||
MigrationLambda::MigrationLambda(std::function<void(const Migration*, Settings*)> m_lambda)
|
||||
: m_lambda(m_lambda)
|
||||
{
|
||||
}
|
||||
|
||||
void MigrationLambda::apply(Settings* settings) const
|
||||
{
|
||||
m_lambda(this, settings);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef MIGRATION_LAMBDA_H
|
||||
#define MIGRATION_LAMBDA_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "settings/migration/Migration.h"
|
||||
|
||||
class MigrationLambda: public Migration
|
||||
{
|
||||
public:
|
||||
MigrationLambda(std::function<void(const Migration*, Settings*)> m_lambda);
|
||||
virtual void apply(Settings* settings) const;
|
||||
|
||||
private:
|
||||
std::function<void(const Migration*, Settings*)> m_lambda;
|
||||
};
|
||||
|
||||
#endif // MIGRATION_LAMBDA_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "settings/migration/MigrationMoveKey.h"
|
||||
|
||||
MigrationMoveKey::MigrationMoveKey(const std::string& oldKey, const std::string& newKey)
|
||||
: m_oldKey(oldKey)
|
||||
, m_newKey(newKey)
|
||||
{
|
||||
}
|
||||
|
||||
void MigrationMoveKey::apply(Settings* settings) const
|
||||
{
|
||||
if (!isValueDefinedInSettings(settings, m_newKey))
|
||||
{
|
||||
setValuesInSettings<std::string>(
|
||||
settings,
|
||||
m_newKey,
|
||||
getValuesFromSettings<std::string>(settings, m_oldKey, std::vector<std::string>())
|
||||
);
|
||||
removeValuesInSettings(settings, m_oldKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef MIGRATION_MOVE_KEY_H
|
||||
#define MIGRATION_MOVE_KEY_H
|
||||
|
||||
#include "settings/migration/Migration.h"
|
||||
|
||||
class MigrationMoveKey: public Migration
|
||||
{
|
||||
public:
|
||||
MigrationMoveKey(const std::string& oldKey, const std::string& newKey);
|
||||
virtual void apply(Settings* settings) const;
|
||||
|
||||
private:
|
||||
const std::string m_oldKey;
|
||||
const std::string m_newKey;
|
||||
};
|
||||
|
||||
#endif // MIGRATION_MOVE_KEY_H
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "settings/migration/SettingsMigrator.h"
|
||||
|
||||
#include "settings/Settings.h"
|
||||
|
||||
SettingsMigrator::SettingsMigrator()
|
||||
{
|
||||
}
|
||||
|
||||
SettingsMigrator::~SettingsMigrator()
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsMigrator::addMigration(size_t targetVersion, std::shared_ptr<Migration> migration)
|
||||
{
|
||||
if (migration)
|
||||
{
|
||||
m_migrations.emplace(targetVersion, migration);
|
||||
}
|
||||
}
|
||||
|
||||
bool SettingsMigrator::willMigrate(const Settings* settings, size_t targetVersion) const
|
||||
{
|
||||
size_t originVersion = settings->getVersion();
|
||||
|
||||
if (originVersion < targetVersion)
|
||||
{
|
||||
for (; originVersion <= targetVersion; originVersion++)
|
||||
{
|
||||
std::pair<std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator, std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator> ret;
|
||||
ret = m_migrations.equal_range(originVersion);
|
||||
|
||||
for (std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator it = ret.first; it != ret.second; it++)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SettingsMigrator::migrate(Settings* settings, size_t targetVersion) const
|
||||
{
|
||||
size_t originVersion = settings->getVersion();
|
||||
|
||||
if (originVersion < targetVersion)
|
||||
{
|
||||
for (; originVersion <= targetVersion; originVersion++)
|
||||
{
|
||||
std::pair<std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator, std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator> ret;
|
||||
ret = m_migrations.equal_range(originVersion);
|
||||
|
||||
for (std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator it = ret.first; it != ret.second; it++)
|
||||
{
|
||||
it->second->apply(settings);
|
||||
}
|
||||
}
|
||||
|
||||
settings->setVersion(targetVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef SETTNGS_MIGRATOR_H
|
||||
#define SETTNGS_MIGRATOR_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Migration;
|
||||
class Settings;
|
||||
|
||||
class SettingsMigrator
|
||||
{
|
||||
public:
|
||||
static SettingsMigrator createApplicationSettingsMigrator();
|
||||
|
||||
SettingsMigrator();
|
||||
virtual ~SettingsMigrator();
|
||||
|
||||
void addMigration(size_t targetVersion, std::shared_ptr<Migration> migration);
|
||||
|
||||
bool willMigrate(const Settings* settings, size_t targetVersion) const;
|
||||
bool migrate(Settings* settings, size_t targetVersion) const;
|
||||
|
||||
private:
|
||||
std::multimap<size_t, std::shared_ptr<Migration>> m_migrations;
|
||||
};
|
||||
|
||||
#endif // SETTINGS_MIGRATOR_H
|
||||
Reference in New Issue
Block a user