diff --git a/include/imodule.h b/include/imodule.h index 91d9f16258..9b54f3badd 100644 --- a/include/imodule.h +++ b/include/imodule.h @@ -31,7 +31,7 @@ * As long as no external module/plugin files are removed this number is safe to stay * as it is. Keep this number compatible to std::size_t, i.e. unsigned. */ -#define MODULE_COMPATIBILITY_LEVEL 20201026 +#define MODULE_COMPATIBILITY_LEVEL 20210717 // A function taking an error title and an error message string, invoked in debug builds // for things like ASSERT_MESSAGE and ERROR_MESSAGE diff --git a/include/iversioncontrol.h b/include/iversioncontrol.h new file mode 100644 index 0000000000..5b9c09c826 --- /dev/null +++ b/include/iversioncontrol.h @@ -0,0 +1,60 @@ +#pragma once + +#include "imodule.h" + +namespace vcs +{ + +/** + * Common interface of a version control module offering + * methods to access its history. + * + * Each module needs to define a unique prefix which are used + * when resolving item URIs. + */ +class IVersionControlModule +{ +public: + virtual ~IVersionControlModule() {} + + using Ptr = std::shared_ptr; + + // Returns the prefix which is used to construct URIs + // that refer to a specific point in the VCS history + virtual std::string getUriPrefix() = 0; +}; + + +/** + * Interface which keeps track of the active version control + * modules of this app. + * + * Version Control modules need to register themselves here + * to be accessible by the core modules. + */ +class IVersionControlManager : + public RegisterableModule +{ +public: + virtual ~IVersionControlManager() {} + + // Register the given module. If a module with the same prefix has already been registered, + // a std::runtime_error exception will be thrown. + virtual void registerModule(const IVersionControlModule::Ptr& vcsModule) = 0; + + virtual void unregisterModule(const IVersionControlModule::Ptr& vcsModule) = 0; + + // Return the source control module for the given prefix, or an empty reference if nothing found + virtual IVersionControlModule::Ptr getModuleForPrefix(const std::string& prefix) = 0; +}; + +constexpr const char* const MODULE_VERSION_CONTROL_MANAGER = "VersionControlManager"; + +} + +// The accessor for the clipper module +inline vcs::IVersionControlManager& GlobalVersionControlManager() +{ + static module::InstanceReference _reference(vcs::MODULE_VERSION_CONTROL_MANAGER); + return _reference; +} diff --git a/radiantcore/CMakeLists.txt b/radiantcore/CMakeLists.txt index d80d40a030..9dcf49d070 100644 --- a/radiantcore/CMakeLists.txt +++ b/radiantcore/CMakeLists.txt @@ -277,6 +277,7 @@ add_library(radiantcore MODULE shaders/textures/TextureManipulator.cpp skins/Doom3SkinCache.cpp undo/UndoSystem.cpp + versioncontrol/VersionControlManager.cpp vfs/DeflatedInputStream.cpp vfs/DirectoryArchive.cpp vfs/Doom3FileSystem.cpp diff --git a/radiantcore/versioncontrol/VersionControlManager.cpp b/radiantcore/versioncontrol/VersionControlManager.cpp new file mode 100644 index 0000000000..dab4d6374a --- /dev/null +++ b/radiantcore/versioncontrol/VersionControlManager.cpp @@ -0,0 +1,50 @@ +#include "VersionControlManager.h" + +#include "itextstream.h" +#include "module/StaticModule.h" + +namespace vcs +{ + +void VersionControlManager::registerModule(const IVersionControlModule::Ptr& vcsModule) +{ + auto result = _registeredModules.emplace(vcsModule->getUriPrefix(), vcsModule); + + if (!result.second) + { + throw std::runtime_error("A VCS module with prefix " + vcsModule->getUriPrefix() + " has already been registered."); + } +} + +void VersionControlManager::unregisterModule(const IVersionControlModule::Ptr& vcsModule) +{ + _registeredModules.erase(vcsModule->getUriPrefix()); +} + +IVersionControlModule::Ptr VersionControlManager::getModuleForPrefix(const std::string& prefix) +{ + auto existing = _registeredModules.find(prefix); + + return existing != _registeredModules.end() ? existing->second : IVersionControlModule::Ptr(); +} + +const std::string& VersionControlManager::getName() const +{ + static std::string _name(vcs::MODULE_VERSION_CONTROL_MANAGER); + return _name; +} + +const StringSet& VersionControlManager::getDependencies() const +{ + static StringSet _dependencies; + return _dependencies; +} + +void VersionControlManager::initialiseModule(const IApplicationContext& ctx) +{ + rMessage() << getName() << "::initialiseModule called." << std::endl; +} + +module::StaticModule versionControlManagerModule; + +} diff --git a/radiantcore/versioncontrol/VersionControlManager.h b/radiantcore/versioncontrol/VersionControlManager.h new file mode 100644 index 0000000000..5bf09b3b26 --- /dev/null +++ b/radiantcore/versioncontrol/VersionControlManager.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "iversioncontrol.h" + +namespace vcs +{ + +class VersionControlManager final : + public IVersionControlManager +{ +private: + std::map _registeredModules; + +public: + void registerModule(const IVersionControlModule::Ptr& vcsModule) override; + void unregisterModule(const IVersionControlModule::Ptr& vcsModule) override; + IVersionControlModule::Ptr getModuleForPrefix(const std::string& prefix) override; + + // RegisterableModule implementation + const std::string& getName() const override; + const StringSet& getDependencies() const override; + void initialiseModule(const IApplicationContext& ctx) override; +}; + +} diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index f4afbc703b..e93059f8fc 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -673,6 +673,7 @@ + @@ -1028,6 +1029,7 @@ + diff --git a/tools/msvc/DarkRadiantCore.vcxproj.filters b/tools/msvc/DarkRadiantCore.vcxproj.filters index 77f0ffb56f..fcd6c79d29 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj.filters +++ b/tools/msvc/DarkRadiantCore.vcxproj.filters @@ -200,6 +200,9 @@ {a98a0273-a99f-4a0d-b181-14479a01cecd} + + {6e21fce5-68dc-4b21-8856-b219352b5f02} + @@ -1048,6 +1051,9 @@ src\log + + src\versioncontrol + @@ -2139,5 +2145,8 @@ src\log + + src\versioncontrol + \ No newline at end of file diff --git a/tools/msvc/include.vcxproj b/tools/msvc/include.vcxproj index 3d56c6b46b..0c8f741376 100644 --- a/tools/msvc/include.vcxproj +++ b/tools/msvc/include.vcxproj @@ -202,6 +202,7 @@ +