Initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include <cstdint>
|
||||
#include <engine/core/engine.hpp>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
uint16_t MscEngine::REV = 0;
|
||||
|
||||
MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules) {
|
||||
std::unordered_map<std::string, uint16_t> registry;
|
||||
for (const auto &module : modules) {
|
||||
if (!module)
|
||||
continue;
|
||||
|
||||
auto [it, inserted] =
|
||||
registry.try_emplace(module->getName(), module->getRev());
|
||||
if (!inserted) {
|
||||
throw std::runtime_error("Duplicate module detected: " +
|
||||
module->getName());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &module : modules) {
|
||||
if (!module)
|
||||
continue;
|
||||
|
||||
for (const auto &[dep_name, range] : module->getDependencies()) {
|
||||
auto it = registry.find(dep_name);
|
||||
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)) {
|
||||
throw std::runtime_error(
|
||||
"Module " + module->getName() + " requires " + dep_name +
|
||||
" in range [" + std::to_string(range.minRevision) + " <-> " +
|
||||
std::to_string(range.maxRevision) + "], but got rev" +
|
||||
std::to_string(current_rev));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_modules = std::move(modules);
|
||||
}
|
||||
|
||||
UNIMPL MscEngine::getBus() const { throw std::runtime_error("Unimplemented"); }
|
||||
|
||||
UNIMPL MscEngine::getLoadedModules() const {
|
||||
throw std::runtime_error("Unimplemented");
|
||||
}
|
||||
Reference in New Issue
Block a user