aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/module.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:07:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:07:09 +0200
commit2169f0e960c6e2b94518c03e6eb0406908b96e65 (patch)
tree73cfda5d0c7aa38c74104cca89931045db37892e /libbuild2/module.hxx
parent1abc10223b37d9ead3454a06e176b4b65370a2be (diff)
Improve module loading API
Diffstat (limited to 'libbuild2/module.hxx')
-rw-r--r--libbuild2/module.hxx43
1 files changed, 30 insertions, 13 deletions
diff --git a/libbuild2/module.hxx b/libbuild2/module.hxx
index 34c7245..729cc2e 100644
--- a/libbuild2/module.hxx
+++ b/libbuild2/module.hxx
@@ -96,7 +96,7 @@ namespace build2
{
template <typename T>
T*
- lookup (const string& name) const
+ find_module (const string& name) const
{
auto i (find (name));
return i != end ()
@@ -111,9 +111,10 @@ namespace build2
boot_module (scope& root, const string& name, const location&);
// Init the specified module loading its library if necessary. Used by the
- // parser but also by some modules to init prerequisite modules. Return true
- // if the module was both successfully loaded and configured (false can only
- // be returned if optional is true).
+ // parser but also by some modules to init prerequisite modules. Return a
+ // pointer to the corresponding module state if the module was both
+ // successfully loaded and configured and NULL otherwise (which can only
+ // happen if optional is true). Note that the return can be used as a bool.
//
// The config_hints variable map can be used to pass configuration hints
// from one module to another. For example, the cxx modude may pass the
@@ -121,7 +122,7 @@ namespace build2
// module (which may not always be able to extract the same information from
// its tools).
//
- LIBBUILD2_SYMEXPORT bool
+ LIBBUILD2_SYMEXPORT module_state*
init_module (scope& root,
scope& base,
const string& name,
@@ -129,21 +130,37 @@ namespace build2
bool optional = false,
const variable_map& config_hints = empty_variable_map);
- // An alias to use from other modules (we could also distinguish between
- // boot and init).
+ // A wrapper over init_module() to use from other modules that incorporates
+ // the <name>.loaded variable check (use init_module() directly to sidestep
+ // this check).
//
- // @@ TODO: maybe incorporate the .loaded variable check we have all over
- // (it's not clear if init_module() already has this semantics)?
+ bool
+ load_module (scope& root,
+ scope& base,
+ const string& name,
+ const location&,
+ bool optional,
+ const variable_map& config_hints = empty_variable_map);
+
+ // As above but always load and return a reference to the module instance
+ // pointer (so it can be moved).
//
- inline bool
+ unique_ptr<module_base>&
load_module (scope& root,
scope& base,
const string& name,
- const location& loc,
- bool optional = false,
+ const location&,
+ const variable_map& config_hints = empty_variable_map);
+
+ template <typename T>
+ inline T&
+ load_module (scope& root,
+ scope& base,
+ const string& name,
+ const location& l,
const variable_map& config_hints = empty_variable_map)
{
- return init_module (root, base, name, loc, optional, config_hints);
+ return static_cast<T&> (*load_module (root, base, name, l, config_hints));
}
// Loaded modules (as in libraries).