#include "settings/ProjectSettings.h" #include "utility/utility.h" std::vector ProjectSettings::getDefaultSourceExtensions() { std::vector defaultValues; defaultValues.push_back(".c"); defaultValues.push_back(".cpp"); defaultValues.push_back(".cxx"); defaultValues.push_back(".cc"); return defaultValues; } std::shared_ptr ProjectSettings::s_instance; std::shared_ptr ProjectSettings::getInstance() { if (!s_instance) { s_instance = std::shared_ptr(new ProjectSettings()); } return s_instance; } ProjectSettings::ProjectSettings() { } ProjectSettings::~ProjectSettings() { } bool ProjectSettings::operator==(const ProjectSettings& other) const { return getFilePath() == other.getFilePath() && getLanguage() == other.getLanguage() && getStandard() == other.getStandard() && getVisualStudioSolutionPath() == other.getVisualStudioSolutionPath() && getCompilationDatabasePath() == other.getCompilationDatabasePath() && getUseSourcePathsForHeaderSearch() == other.getUseSourcePathsForHeaderSearch() && utility::isPermutation(getSourcePaths(), other.getSourcePaths()) && utility::isPermutation(getHeaderSearchPaths(), other.getHeaderSearchPaths()) && utility::isPermutation(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) && utility::isPermutation(getCompilerFlags(), other.getCompilerFlags()) && utility::isPermutation(getSourceExtensions(), other.getSourceExtensions()); } bool ProjectSettings::operator!=(const ProjectSettings& other) const { return !(*this == other); } void ProjectSettings::save(const FilePath& filePath) { m_projectName = ""; m_projectFileLocation = ""; Settings::save(filePath); } std::string ProjectSettings::getLanguage() const { return getValue("language_settings/language", "C++"); } bool ProjectSettings::setLanguage(const std::string& language) { return setValue("language_settings/language", language); } std::string ProjectSettings::getStandard() const { return getValue("language_settings/standard", "1z"); } bool ProjectSettings::setStandard(const std::string& standard) { return setValue("language_settings/standard", standard); } std::vector ProjectSettings::getSourcePaths() const { return getPathValues("source/source_paths/source_path"); } std::vector ProjectSettings::getAbsoluteSourcePaths() const { std::vector paths = getSourcePaths(); expandPaths(paths); makePathsAbsolute(paths); return paths; } bool ProjectSettings::setSourcePaths(const std::vector& sourcePaths) { return setPathValues("source/source_paths/source_path", sourcePaths); } std::vector ProjectSettings::getHeaderSearchPaths() const { return getPathValues("source/header_search_paths/header_search_path"); } std::vector ProjectSettings::getAbsoluteHeaderSearchPaths() const { std::vector paths = getHeaderSearchPaths(); expandPaths(paths); makePathsAbsolute(paths); return paths; } bool ProjectSettings::setHeaderSearchPaths(const std::vector& headerSearchPaths) { return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths); } std::vector ProjectSettings::getFrameworkSearchPaths() const { return getPathValues("source/framework_search_paths/framework_search_path"); } std::vector ProjectSettings::getAbsoluteFrameworkSearchPaths() const { std::vector paths = getFrameworkSearchPaths(); expandPaths(paths); makePathsAbsolute(paths); return paths; } bool ProjectSettings::setFrameworkSearchPaths(const std::vector& frameworkSearchPaths) { return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths); } std::vector ProjectSettings::getCompilerFlags() const { std::vector defaultValues; return getValues("source/compiler_flags/compiler_flag", defaultValues); } bool ProjectSettings::setCompilerFlags(const std::vector& compilerFlags) { return setValues("source/compiler_flags/compiler_flag", compilerFlags); } std::vector ProjectSettings::getSourceExtensions() const { return getValues("source/extensions/source_extensions", getDefaultSourceExtensions()); } bool ProjectSettings::setSourceExtensions(const std::vector &sourceExtensions) { return setValues("source/extensions/source_extensions", sourceExtensions); } bool ProjectSettings::isUseSourcePathsForHeaderSearchDefined() const { return isValueDefined("source/use_source_paths_for_header_search"); } bool ProjectSettings::getUseSourcePathsForHeaderSearch() const { return getValue("source/use_source_paths_for_header_search", false); } bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch) { return setValue("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch); } FilePath ProjectSettings::getVisualStudioSolutionPath() const { return FilePath(getValue("source/build_file_path/vs_solution_path", "")); } bool ProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath) { return setValue("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str()); } FilePath ProjectSettings::getCompilationDatabasePath() const { return FilePath(getValue("source/build_file_path/compilation_db_path", "")); } bool ProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath) { return setValue("source/build_file_path/compilation_db_path", compilationDatabasePath.str()); } std::string ProjectSettings::getDescription() const { return getValue("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; } void ProjectSettings::makePathsAbsolute(std::vector& paths) const { FilePath basePath = getProjectFileLocation(); for (size_t i = 0; i < paths.size(); i++) { if (!paths[i].isAbsolute()) { paths[i] = basePath.concat(paths[i]).canonical(); } } }