-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
163 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* ------------------------------------------------------------------------- | ||
* A Modular Optimization framework for Localization and mApping (MOLA) | ||
* Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria | ||
* See LICENSE for license information. | ||
* ------------------------------------------------------------------------- */ | ||
/** | ||
* @file MinimalModuleContainer.h | ||
* @brief A simple module container for use without mola_launcher | ||
* @author Jose Luis Blanco Claraco | ||
* @date Dec 26, 2024 | ||
*/ | ||
#pragma once | ||
|
||
#include <mola_kernel/interfaces/ExecutableBase.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace mola | ||
{ | ||
/** \addtogroup mola_kernel_grp | ||
* @{ */ | ||
|
||
/** | ||
* A minimal MOLA application container, for use programatically when it is | ||
* not advisable to use the mola-cli application. | ||
* | ||
* This implements basic discoverability and visibility between modules. | ||
*/ | ||
class MinimalModuleContainer | ||
{ | ||
public: | ||
MinimalModuleContainer() = default; | ||
~MinimalModuleContainer(); | ||
|
||
explicit MinimalModuleContainer( | ||
const std::vector<mola::ExecutableBase::Ptr>& mods) | ||
: modules_(mods) | ||
{ | ||
for (auto& m : modules_) | ||
{ | ||
ASSERT_(m); | ||
installNameServer(*m); | ||
} | ||
} | ||
|
||
void add(const mola::ExecutableBase::Ptr& m) | ||
{ | ||
ASSERT_(m); | ||
modules_.push_back(m); | ||
installNameServer(*m); | ||
} | ||
|
||
const auto& modules() const { return modules_; } | ||
|
||
private: | ||
std::vector<mola::ExecutableBase::Ptr> modules_; | ||
|
||
void installNameServer(mola::ExecutableBase& m); | ||
|
||
ExecutableBase::Ptr nameServerImpl(const std::string& name); | ||
}; | ||
|
||
/** @} */ | ||
|
||
} // namespace mola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* ------------------------------------------------------------------------- | ||
* A Modular Optimization framework for Localization and mApping (MOLA) | ||
* Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria | ||
* See LICENSE for license information. | ||
* ------------------------------------------------------------------------- */ | ||
/** | ||
* @file MinimalModuleContainer.cpp | ||
* @brief A simple module container for use without mola_launcher | ||
* @author Jose Luis Blanco Claraco | ||
* @date Dec 26, 2024 | ||
*/ | ||
|
||
#include <mola_kernel/MinimalModuleContainer.h> | ||
|
||
namespace mola | ||
{ | ||
MinimalModuleContainer::~MinimalModuleContainer() = default; | ||
|
||
void MinimalModuleContainer::installNameServer(ExecutableBase& m) | ||
{ | ||
m.nameServer_ = std::bind( | ||
&MinimalModuleContainer::nameServerImpl, this, std::placeholders::_1); | ||
} | ||
|
||
ExecutableBase::Ptr MinimalModuleContainer::nameServerImpl( | ||
const std::string& name) | ||
{ | ||
// Special syntax to sequentially access all existing modules: | ||
// If the requested name has the format: "[" + <i>, return the i-th | ||
// module, or nullptr if out of range. | ||
// This is used by ExecutableBase::findService() | ||
if (name.size() >= 2 && name[0] == '[') | ||
{ | ||
const auto idx = std::stoul(name.substr(1)); | ||
if (idx >= modules_.size()) { return ExecutableBase::Ptr(); } | ||
else | ||
{ | ||
auto it = modules_.begin(); | ||
std::advance(it, idx); | ||
return *it; | ||
} | ||
} | ||
// non numeric search not implemented in this minimal container | ||
return ExecutableBase::Ptr(); | ||
} | ||
|
||
} // namespace mola |