/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
: name_(name), description_(description), factory_(factory)
{
}
+ CommandLineOptionsModule(const char *name, const char *description,
+ CommandLineOptionsModuleInterface *module)
+ : name_(name), description_(description), factory_(NULL),
+ module_(module)
+ {
+ }
virtual const char *name() const { return name_; }
virtual const char *shortDescription() const { return description_; }
void CommandLineOptionsModule::init(CommandLineModuleSettings *settings)
{
- module_.reset(factory_());
+ if (!module_)
+ {
+ GMX_RELEASE_ASSERT(factory_ != NULL, "Neither factory nor module provided");
+ module_.reset(factory_());
+ }
module_->init(settings);
}
void CommandLineOptionsModule::writeHelp(const CommandLineHelpContext &context) const
{
- boost::scoped_ptr<CommandLineOptionsModuleInterface> module(factory_());
+ boost::scoped_ptr<CommandLineOptionsModuleInterface> moduleGuard;
+ CommandLineOptionsModuleInterface *module = module_.get();
+ if (!module)
+ {
+ GMX_RELEASE_ASSERT(factory_ != NULL, "Neither factory nor module provided");
+ moduleGuard.reset(factory_());
+ module = moduleGuard.get();
+ }
Options options(name(), shortDescription());
module->initOptions(&options);
CommandLineHelpWriter(options)
manager->addModule(move(module));
}
+// static
+void CommandLineOptionsModuleInterface::registerModule(
+ CommandLineModuleManager *manager, const char *name,
+ const char *description, CommandLineOptionsModuleInterface *module)
+{
+ CommandLineModulePointer wrapperModule(
+ new CommandLineOptionsModule(name, description, module));
+ manager->addModule(move(wrapperModule));
+}
+
} // namespace gmx