| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
#include "iarchive.h" |
| 5 |
|
| 6 |
namespace vcs |
| 7 |
{ |
| 8 |
|
| 9 |
/** |
| 10 |
* Common interface of a version control module offering |
| 11 |
* methods to access its history. |
| 12 |
* |
| 13 |
* Each module needs to define a unique prefix which are used |
| 14 |
* when resolving item URIs. |
| 15 |
*/ |
| 16 |
class IVersionControlModule |
| 17 |
{ |
| 18 |
public: |
| 19 |
virtual ~IVersionControlModule() {} |
| 20 |
|
| 21 |
using Ptr = std::shared_ptr<IVersionControlModule>; |
| 22 |
|
| 23 |
// Returns the prefix which is used to construct URIs |
| 24 |
// that refer to a specific point in the VCS history |
| 25 |
virtual std::string getUriPrefix() = 0; |
| 26 |
|
| 27 |
// Attempts to open the given resource (in text mode) |
| 28 |
virtual ArchiveTextFilePtr openTextFile(const std::string& vcsUri) = 0; |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* Interface which keeps track of the active version control |
| 34 |
* modules of this app. |
| 35 |
* |
| 36 |
* Version Control modules need to register themselves here |
| 37 |
* to be accessible by the core modules. |
| 38 |
*/ |
| 39 |
class IVersionControlManager : |
| 40 |
public RegisterableModule |
| 41 |
{ |
| 42 |
public: |
| 43 |
virtual ~IVersionControlManager() {} |
| 44 |
|
| 45 |
// Register the given module. If a module with the same prefix has already been registered, |
| 46 |
// a std::runtime_error exception will be thrown. |
| 47 |
virtual void registerModule(const IVersionControlModule::Ptr& vcsModule) = 0; |
| 48 |
|
| 49 |
virtual void unregisterModule(const IVersionControlModule::Ptr& vcsModule) = 0; |
| 50 |
|
| 51 |
// Return the source control module for the given prefix, or an empty reference if nothing found |
| 52 |
virtual IVersionControlModule::Ptr getModuleForPrefix(const std::string& prefix) = 0; |
| 53 |
}; |
| 54 |
|
| 55 |
constexpr const char* const MODULE_VERSION_CONTROL_MANAGER = "VersionControlManager"; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
// The accessor for the clipper module |
| 60 |
inline vcs::IVersionControlManager& GlobalVersionControlManager() |
| 61 |
{ |
| 62 |
static module::InstanceReference<vcs::IVersionControlManager> _reference(vcs::MODULE_VERSION_CONTROL_MANAGER); |
| 63 |
return _reference; |
| 64 |
} |