src: Project Refactoring

* Added language specific Project and ProjectSettings
* moved project specific code from Application to Project
* made Application a singleton
* added handleDialog method to Application which displays a dialog window and waits for user input
* Added ScopedFunctor that executes a function when deleted
This commit is contained in:
malte_langkabel
2016-08-11 12:17:13 +02:00
parent 6b51c7cfe4
commit c847fba568
63 changed files with 1375 additions and 874 deletions
+57 -169
View File
@@ -1,75 +1,83 @@
#include "settings/ProjectSettings.h"
#include "settings/CxxProjectSettings.h"
#include "settings/JavaProjectSettings.h"
#include "utility/utility.h"
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions()
LanguageType ProjectSettings::getLanguageOfProject(FilePath projectFilePath)
{
std::vector<std::string> defaultValues;
defaultValues.push_back(".c");
defaultValues.push_back(".cpp");
defaultValues.push_back(".cxx");
defaultValues.push_back(".cc");
return defaultValues;
}
std::shared_ptr<ProjectSettings> ProjectSettings::s_instance;
std::shared_ptr<ProjectSettings> ProjectSettings::getInstance()
{
if (!s_instance)
{
s_instance = std::shared_ptr<ProjectSettings>(new ProjectSettings());
}
return s_instance;
ProjectSettings tempSettings(projectFilePath);
tempSettings.load();
return tempSettings.getLanguage();
}
ProjectSettings::ProjectSettings()
{
}
ProjectSettings::ProjectSettings(const FilePath& projectFilePath)
{
setFilePath(projectFilePath);
}
ProjectSettings::ProjectSettings(std::string projectName, const FilePath& projectFileLocation)
{
setFilePath(FilePath(projectFileLocation.str() + "/" + projectName + ".coatiproject"));
}
ProjectSettings::~ProjectSettings()
{
}
bool ProjectSettings::operator==(const ProjectSettings& other) const
bool ProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const
{
return
getFilePath() == other.getFilePath() &&
return (
getLanguage() == other.getLanguage() &&
getStandard() == other.getStandard() &&
getVisualStudioSolutionPath() == other.getVisualStudioSolutionPath() &&
getCompilationDatabasePath() == other.getCompilationDatabasePath() &&
getUseSourcePathsForHeaderSearch() == other.getUseSourcePathsForHeaderSearch() &&
utility::isPermutation<FilePath>(getSourcePaths(), other.getSourcePaths()) &&
utility::isPermutation<FilePath>(getHeaderSearchPaths(), other.getHeaderSearchPaths()) &&
utility::isPermutation<FilePath>(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) &&
utility::isPermutation<FilePath>(getExcludePaths(), other.getExcludePaths()) &&
utility::isPermutation<std::string>(getCompilerFlags(), other.getCompilerFlags()) &&
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions());
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions())
);
}
bool ProjectSettings::operator!=(const ProjectSettings& other) const
bool ProjectSettings::load()
{
return !(*this == other);
return Settings::load(getFilePath());
}
void ProjectSettings::save(const FilePath& filePath)
std::string ProjectSettings::getProjectName() const
{
m_projectName = "";
m_projectFileLocation = "";
Settings::save(filePath);
return getFilePath().withoutExtension().fileName();
}
std::string ProjectSettings::getLanguage() const
void ProjectSettings::setProjectName(const std::string& name)
{
return getValue<std::string>("language_settings/language", "C++");
setFilePath(FilePath(getProjectFileLocation().str() + "/" + name + ".coatiproject"));
}
bool ProjectSettings::setLanguage(const std::string& language)
FilePath ProjectSettings::getProjectFileLocation() const
{
return setValue<std::string>("language_settings/language", language);
return getFilePath().parentDirectory();
}
void ProjectSettings::setProjectFileLocation(const FilePath& location)
{
setFilePath(FilePath(location.str() + "/" + getProjectName() + ".coatiproject"));
}
std::string ProjectSettings::getDescription() const
{
return getValue<std::string>("info/description", "");
}
LanguageType ProjectSettings::getLanguage() const
{
return stringToLanguageType(getValue<std::string>("language_settings/language", languageTypeToString(LANGUAGE_UNKNOWN)));
}
bool ProjectSettings::setLanguage(LanguageType language)
{
return setValue<std::string>("language_settings/language", languageTypeToString(language));
}
std::string ProjectSettings::getStandard() const
@@ -82,19 +90,6 @@ bool ProjectSettings::setStandard(const std::string& standard)
return setValue<std::string>("language_settings/standard", standard);
}
std::vector<FilePath> ProjectSettings::getJavaClasspaths() const
{
return getPathValues("source/class_paths/class_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteJavaClasspaths() const
{
std::vector<FilePath> paths = getJavaClasspaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
std::vector<FilePath> ProjectSettings::getSourcePaths() const
{
return getPathValues("source/source_paths/source_path");
@@ -113,73 +108,6 @@ bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
return setPathValues("source/source_paths/source_path", sourcePaths);
}
std::vector<FilePath> ProjectSettings::getHeaderSearchPaths() const
{
return getPathValues("source/header_search_paths/header_search_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteHeaderSearchPaths() const
{
std::vector<FilePath> paths = getHeaderSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool ProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
{
return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths);
}
std::vector<FilePath> ProjectSettings::getFrameworkSearchPaths() const
{
return getPathValues("source/framework_search_paths/framework_search_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteFrameworkSearchPaths() const
{
std::vector<FilePath> paths = getFrameworkSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool ProjectSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
{
return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths);
}
std::vector<std::string> ProjectSettings::getCompilerFlags() const
{
std::vector<std::string> defaultValues;
return getValues("source/compiler_flags/compiler_flag", defaultValues);
}
bool ProjectSettings::setCompilerFlags(const std::vector<std::string>& compilerFlags)
{
return setValues("source/compiler_flags/compiler_flag", compilerFlags);
}
std::vector<std::string> ProjectSettings::getSourceExtensions() const
{
return getValues("source/extensions/source_extensions", getDefaultSourceExtensions());
}
bool ProjectSettings::setSourceExtensions(const std::vector<std::string> &sourceExtensions)
{
return setValues("source/extensions/source_extensions", sourceExtensions);
}
bool ProjectSettings::getUseSourcePathsForHeaderSearch() const
{
return getValue<bool>("source/use_source_paths_for_header_search", false);
}
bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch)
{
return setValue<bool>("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch);
}
std::vector<FilePath> ProjectSettings::getExcludePaths() const
{
return getPathValues("source/exclude_paths/exclude_path");
@@ -198,59 +126,14 @@ bool ProjectSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
return setPathValues("source/exclude_paths/exclude_path", excludePaths);
}
FilePath ProjectSettings::getVisualStudioSolutionPath() const
std::vector<std::string> ProjectSettings::getSourceExtensions() const
{
return FilePath(getValue<std::string>("source/build_file_path/vs_solution_path", ""));
return getValues("source/extensions/source_extensions", getDefaultSourceExtensions());
}
bool ProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath)
bool ProjectSettings::setSourceExtensions(const std::vector<std::string> &sourceExtensions)
{
return setValue<std::string>("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str());
}
FilePath ProjectSettings::getCompilationDatabasePath() const
{
return FilePath(getValue<std::string>("source/build_file_path/compilation_db_path", ""));
}
bool ProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath)
{
return setValue<std::string>("source/build_file_path/compilation_db_path", compilationDatabasePath.str());
}
std::string ProjectSettings::getDescription() const
{
return getValue<std::string>("info/description", "");
}
std::string ProjectSettings::getProjectName() const
{
if (m_projectName.size())
{
return m_projectName;
}
return getFilePath().withoutExtension().fileName();
}
void ProjectSettings::setProjectName(const std::string& name)
{
m_projectName = name;
}
FilePath ProjectSettings::getProjectFileLocation() const
{
if (!m_projectFileLocation.empty())
{
return m_projectFileLocation;
}
return getFilePath().parentDirectory();
}
void ProjectSettings::setProjectFileLocation(const FilePath& location)
{
m_projectFileLocation = location;
return setValues("source/extensions/source_extensions", sourceExtensions);
}
void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
@@ -264,3 +147,8 @@ void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
}
}
}
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions() const
{
return std::vector<std::string>();
}