ref: format
This commit is contained in:
@@ -8,33 +8,40 @@
|
||||
|
||||
uint16_t MscEngine::REV = 0;
|
||||
|
||||
MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules) {
|
||||
MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules)
|
||||
{
|
||||
std::unordered_map<std::string, uint16_t> registry;
|
||||
for (const auto &module : modules) {
|
||||
for (const auto &module : modules)
|
||||
{
|
||||
if (!module)
|
||||
continue;
|
||||
|
||||
auto [it, inserted] =
|
||||
registry.try_emplace(module->getName(), module->getRev());
|
||||
if (!inserted) {
|
||||
if (!inserted)
|
||||
{
|
||||
throw std::runtime_error("Duplicate module detected: " +
|
||||
module->getName());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &module : modules) {
|
||||
for (const auto &module : modules)
|
||||
{
|
||||
if (!module)
|
||||
continue;
|
||||
|
||||
for (const auto &[dep_name, range] : module->getDependencies()) {
|
||||
for (const auto &[dep_name, range] : module->getDependencies())
|
||||
{
|
||||
auto it = registry.find(dep_name);
|
||||
if (it == registry.end()) {
|
||||
if (it == registry.end())
|
||||
{
|
||||
throw std::runtime_error("Module " + module->getName() +
|
||||
" requires missing module: " + dep_name);
|
||||
}
|
||||
|
||||
int current_rev = it->second;
|
||||
if (!range.isSatisfied(current_rev)) {
|
||||
if (!range.isSatisfied(current_rev))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Module " + module->getName() + " requires " + dep_name +
|
||||
" in range [" + std::to_string(range.minRevision) + " <-> " +
|
||||
@@ -49,6 +56,7 @@ MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules) {
|
||||
|
||||
UNIMPL MscEngine::getBus() const { throw std::runtime_error("Unimplemented"); }
|
||||
|
||||
UNIMPL MscEngine::getLoadedModules() const {
|
||||
UNIMPL MscEngine::getLoadedModules() const
|
||||
{
|
||||
throw std::runtime_error("Unimplemented");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "engine/modules/test1/test1.hpp"
|
||||
#include "engine/core/engine_module_api.hpp"
|
||||
#include "engine/utils/rev_range.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -9,9 +10,13 @@ std::string Test1Module::getName() const { return "test1"; }
|
||||
uint16_t Test1Module::getRev() const { return 1; }
|
||||
|
||||
const std::unordered_map<std::string, MscRevisionRange> &
|
||||
Test1Module::getDependencies() const {
|
||||
Test1Module::getDependencies() const
|
||||
{
|
||||
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
||||
return deps;
|
||||
}
|
||||
|
||||
void Test1Module::onInitialize() {}
|
||||
void Test1Module::onInitialize(IMscEngineModuleAPI &engine)
|
||||
{
|
||||
(void)(engine);
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
auto engine =
|
||||
std::make_unique<MscEngine>(std::vector<std::shared_ptr<MscEngineModule>>{
|
||||
std::make_shared<Test1Module>()});
|
||||
|
||||
Reference in New Issue
Block a user