From 8a2526894f17be3f183282c22d9c20d32a959630 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Fri, 17 Jul 2015 07:05:53 +0300 Subject: [PATCH] Move Options::setDescription() elsewhere Pass the help text for programs using other means, clarifying responsibilities in the code. Now Options is closer to being just a container of options. Further refactoring to follow. Change-Id: I398ebef7884d88111ab1bddcd9397882835b39b4 --- share/template/template.cpp | 2 +- src/gromacs/commandline/cmdlinehelpmodule.cpp | 10 +- src/gromacs/commandline/cmdlinehelpwriter.cpp | 92 ++++--------------- src/gromacs/commandline/cmdlinehelpwriter.h | 25 +++-- .../commandline/cmdlineoptionsmodule.cpp | 38 +++++++- .../commandline/cmdlineoptionsmodule.h | 45 ++++++++- src/gromacs/commandline/pargs.cpp | 3 +- .../commandline/tests/cmdlinehelpmodule.cpp | 9 +- .../commandline/tests/cmdlinehelpwriter.cpp | 35 +++---- .../tests/cmdlinemodulemanagertest.h | 2 +- ...mandLineHelpWriterTest_HandlesHelpText.xml | 21 +++++ ...HelpWriterTest_HandlesMultipleSections.xml | 31 ------- .../gmxpreprocess/insert-molecules.cpp | 8 +- src/gromacs/options/options-impl.h | 6 +- src/gromacs/options/options.cpp | 23 +---- src/gromacs/options/options.h | 39 -------- .../analysissettings-impl.h | 7 +- .../trajectoryanalysis/analysissettings.cpp | 16 +++- .../trajectoryanalysis/analysissettings.h | 11 ++- .../trajectoryanalysis/cmdlinerunner.cpp | 2 +- .../trajectoryanalysis/modules/angle.cpp | 4 +- .../trajectoryanalysis/modules/distance.cpp | 4 +- .../trajectoryanalysis/modules/freevolume.cpp | 3 +- .../trajectoryanalysis/modules/pairdist.cpp | 6 +- .../trajectoryanalysis/modules/rdf.cpp | 6 +- .../trajectoryanalysis/modules/sasa.cpp | 2 +- .../trajectoryanalysis/modules/select.cpp | 6 +- .../tests/test_selection.cpp | 8 +- 28 files changed, 221 insertions(+), 243 deletions(-) create mode 100644 src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml delete mode 100644 src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml diff --git a/share/template/template.cpp b/share/template/template.cpp index 6ef9e466b5..3cb55d5e89 100644 --- a/share/template/template.cpp +++ b/share/template/template.cpp @@ -101,7 +101,7 @@ AnalysisTemplate::initOptions(Options *options, "analysis groups." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("o") .filetype(eftPlot).outputFile() diff --git a/src/gromacs/commandline/cmdlinehelpmodule.cpp b/src/gromacs/commandline/cmdlinehelpmodule.cpp index 11237e21ff..cabe8f1b7a 100644 --- a/src/gromacs/commandline/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/cmdlinehelpmodule.cpp @@ -289,11 +289,15 @@ void RootHelpTopic::writeHelp(const HelpWriterContext &context) const } cmdlineContext->setModuleDisplayName(helpModule_.binaryName_); optionsHolder.initOptions(); - Options &options = *optionsHolder.options(); - options.setDescription(RootHelpText::text); + Options &options = *optionsHolder.options(); + ConstArrayRef helpText; + if (context.outputFormat() != eHelpOutputFormat_Console) + { + helpText = RootHelpText::text; + } // TODO: Add [] into the synopsis. CommandLineHelpWriter(options) - .setShowDescriptions(context.outputFormat() != eHelpOutputFormat_Console) + .setHelpText(helpText) .writeHelp(*cmdlineContext); } if (context.outputFormat() == eHelpOutputFormat_Console) diff --git a/src/gromacs/commandline/cmdlinehelpwriter.cpp b/src/gromacs/commandline/cmdlinehelpwriter.cpp index 69448c4bd7..4cda572678 100644 --- a/src/gromacs/commandline/cmdlinehelpwriter.cpp +++ b/src/gromacs/commandline/cmdlinehelpwriter.cpp @@ -73,69 +73,6 @@ namespace //! \addtogroup module_commandline //! \{ -/******************************************************************** - * DescriptionsFormatter - */ - -class DescriptionsFormatter : public OptionsVisitor -{ - public: - /*! \brief - * Creates a new description formatter. - * - * \param[in] context Help context to use to write the help. - */ - explicit DescriptionsFormatter(const HelpWriterContext &context) - : context_(context), title_(NULL), bDidOutput_(false) - { - } - - //! Formats all section descriptions from a given options. - void format(const Options &options, const char *title) - { - title_ = title; - bDidOutput_ = false; - visitSubSection(options); - if (bDidOutput_) - { - context_.outputFile().writeLine(); - } - } - - //! Formats the description for a single subsection and handles recursion. - virtual void visitSubSection(const Options §ion); - // This method is not used and never called. - virtual void visitOption(const OptionInfo & /*option*/) {} - - private: - const HelpWriterContext &context_; - const char *title_; - bool bDidOutput_; - - GMX_DISALLOW_COPY_AND_ASSIGN(DescriptionsFormatter); -}; - -void DescriptionsFormatter::visitSubSection(const Options §ion) -{ - if (!section.description().empty()) - { - if (bDidOutput_) - { - context_.outputFile().writeLine(); - } - else if (title_ != NULL) - { - context_.writeTitle(title_); - } - // TODO: Print title for the section? - context_.writeTextBlock(section.description()); - bDidOutput_ = true; - } - - OptionsIterator iterator(section); - iterator.acceptSubSections(this); -} - /******************************************************************** * IOptionsFormatter */ @@ -578,17 +515,16 @@ class CommandLineHelpWriter::Impl //! Options object to use for generating help. const Options &options_; + //! Help text. + std::string helpText_; //! List of bugs/knows issues. ConstArrayRef bugs_; //! Time unit to show in descriptions. std::string timeUnit_; - //! Whether to write descriptions to output. - bool bShowDescriptions_; }; CommandLineHelpWriter::Impl::Impl(const Options &options) - : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString()), - bShowDescriptions_(false) + : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString()) { } @@ -622,16 +558,23 @@ CommandLineHelpWriter::~CommandLineHelpWriter() } CommandLineHelpWriter & -CommandLineHelpWriter::setShowDescriptions(bool bSet) +CommandLineHelpWriter::setTimeUnitString(const char *timeUnit) { - impl_->bShowDescriptions_ = bSet; + impl_->timeUnit_ = timeUnit; return *this; } CommandLineHelpWriter & -CommandLineHelpWriter::setTimeUnitString(const char *timeUnit) +CommandLineHelpWriter::setHelpText(const std::string &help) { - impl_->timeUnit_ = timeUnit; + impl_->helpText_ = help; + return *this; +} + +CommandLineHelpWriter & +CommandLineHelpWriter::setHelpText(const ConstArrayRef &help) +{ + impl_->helpText_ = joinStrings(help, "\n"); return *this; } @@ -669,10 +612,11 @@ void CommandLineHelpWriter::writeHelp(const CommandLineHelpContext &context) synopsisFormatter.finish(); } - if (impl_->bShowDescriptions_) + if (!impl_->helpText_.empty()) { - DescriptionsFormatter descriptionFormatter(writerContext); - descriptionFormatter.format(impl_->options_, "Description"); + writerContext.writeTitle("Description"); + writerContext.writeTextBlock(impl_->helpText_); + writerContext.outputFile().writeLine(); } CommonFormatterData common(impl_->timeUnit_.c_str()); OptionsListFormatter formatter(writerContext, common, "Options"); diff --git a/src/gromacs/commandline/cmdlinehelpwriter.h b/src/gromacs/commandline/cmdlinehelpwriter.h index 04fff38c9c..93725fa3c8 100644 --- a/src/gromacs/commandline/cmdlinehelpwriter.h +++ b/src/gromacs/commandline/cmdlinehelpwriter.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,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. @@ -43,6 +43,8 @@ #ifndef GMX_COMMANDLINE_CMDLINEHELPWRITER_H #define GMX_COMMANDLINE_CMDLINEHELPWRITER_H +#include + #include "gromacs/utility/classhelpers.h" namespace gmx @@ -54,7 +56,7 @@ class Options; template class ConstArrayRef; /*! \brief - * Writes help information for Options in ascii format. + * Writes help information for Options. * * \inpublicapi * \ingroup module_commandline @@ -70,10 +72,6 @@ class CommandLineHelpWriter explicit CommandLineHelpWriter(const Options &options); ~CommandLineHelpWriter(); - /*! \brief - * Sets whether long descriptions for sections are shown in the help. - */ - CommandLineHelpWriter &setShowDescriptions(bool bShow); /*! \brief * Sets time unit to show in descriptions. * @@ -85,7 +83,20 @@ class CommandLineHelpWriter * If not called, uses a default "ps". */ CommandLineHelpWriter &setTimeUnitString(const char *timeUnit); - + /*! \brief + * Sets the help text to print as description. + * + * \param[in] help Help text to show. + * \throws std::bad_alloc if out of memory. + * + * If `help` is empty, or this method is not called, only a list of + * options is printed. + * Formatting for the help text is described on \ref page_onlinehelp. + */ + CommandLineHelpWriter &setHelpText(const std::string &help); + //! \copydoc setHelpText(const std::string &) + CommandLineHelpWriter & + setHelpText(const ConstArrayRef &help); /*! \brief * Sets the list of known bugs/limitations. * diff --git a/src/gromacs/commandline/cmdlineoptionsmodule.cpp b/src/gromacs/commandline/cmdlineoptionsmodule.cpp index 2b560f161c..e8249492e8 100644 --- a/src/gromacs/commandline/cmdlineoptionsmodule.cpp +++ b/src/gromacs/commandline/cmdlineoptionsmodule.cpp @@ -50,7 +50,9 @@ #include "gromacs/commandline/cmdlineparser.h" #include "gromacs/options/filenameoptionmanager.h" #include "gromacs/options/options.h" +#include "gromacs/utility/arrayref.h" #include "gromacs/utility/gmxassert.h" +#include "gromacs/utility/stringutil.h" namespace gmx { @@ -58,6 +60,24 @@ namespace gmx namespace { +/******************************************************************** + * CommandLineOptionsModuleSettings + */ + +class CommandLineOptionsModuleSettings : public ICommandLineOptionsModuleSettings +{ + public: + const std::string &helpText() const { return helpText_; } + + virtual void setHelpText(const ConstArrayRef &help) + { + helpText_ = joinStrings(help, "\n"); + } + + private: + std::string helpText_; +}; + /******************************************************************** * CommandLineOptionsModule */ @@ -122,10 +142,11 @@ void CommandLineOptionsModule::writeHelp(const CommandLineHelpContext &context) moduleGuard.reset(factory_()); module = moduleGuard.get(); } - Options options(name(), shortDescription()); - module->initOptions(&options); + Options options(name(), shortDescription()); + CommandLineOptionsModuleSettings settings; + module->initOptions(&options, &settings); CommandLineHelpWriter(options) - .setShowDescriptions(true) + .setHelpText(settings.helpText()) .writeHelp(context); } @@ -136,7 +157,8 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[]) options.addManager(&fileoptManager); - module_->initOptions(&options); + CommandLineOptionsModuleSettings settings; + module_->initOptions(&options, &settings); { CommandLineParser parser(&options); parser.parse(&argc, argv); @@ -147,6 +169,14 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[]) } // namespace +/******************************************************************** + * ICommandLineOptionsModuleSettings + */ + +ICommandLineOptionsModuleSettings::~ICommandLineOptionsModuleSettings() +{ +} + /******************************************************************** * ICommandLineOptionsModule */ diff --git a/src/gromacs/commandline/cmdlineoptionsmodule.h b/src/gromacs/commandline/cmdlineoptionsmodule.h index f5a9056373..ae7c004d01 100644 --- a/src/gromacs/commandline/cmdlineoptionsmodule.h +++ b/src/gromacs/commandline/cmdlineoptionsmodule.h @@ -48,10 +48,48 @@ namespace gmx { +template class ConstArrayRef; + class CommandLineModuleManager; class ICommandLineModule; class Options; +/*! \brief + * Settings to pass information between a CommandLineOptionsModule and generic + * code that runs it. + * + * \inpublicapi + * \ingroup module_commandline + */ +class ICommandLineOptionsModuleSettings +{ + public: + /*! \brief + * Sets the help text for the module from string array. + * + * \param[in] help String array to set as the description. + * \throws std::bad_alloc if out of memory. + * + * Formatting for the help text is described on \ref page_onlinehelp. + * + * Example usage: + * \code + const char *const desc[] = { + "This is the description", + "for the options" + }; + + settings->setHelpText(desc); + \endcode + */ + virtual void setHelpText(const ConstArrayRef &help) = 0; + + protected: + // Disallow deletion through the interface. + // (no need for the virtual, but some compilers warn otherwise) + virtual ~ICommandLineOptionsModuleSettings(); +}; + /*! \brief * Module that can be run from a command line and uses gmx::Options for * argument processing. @@ -182,6 +220,8 @@ class ICommandLineOptionsModule * Initializes command-line arguments understood by the module. * * \param[in,out] options Options object to add the options to. + * \param[in,out] settings Settings to communicate information + * to/from generic code running the module. * * When running the module, this method is called after init(). * When printing help, there is no call to init(), and this is the only @@ -190,7 +230,8 @@ class ICommandLineOptionsModule * the module to \p options. Output values from options should be * stored in member variables. */ - virtual void initOptions(Options *options) = 0; + virtual void initOptions(Options *options, + ICommandLineOptionsModuleSettings *settings) = 0; /*! \brief * Called after all option values have been set. * @@ -203,7 +244,7 @@ class ICommandLineOptionsModule * If the module needs to call, e.g., Options::isSet(), this is the * place to do that. */ - virtual void optionsFinished(Options *options) = 0; + virtual void optionsFinished(Options *options) = 0; /*! \brief * Runs the module. diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 95af8735b7..6daf7d554b 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -498,7 +498,6 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags, fileOptManager.disableInputOptionChecking( FF(PCA_NOT_READ_NODE) || FF(PCA_DISABLE_INPUT_FILE_CHECKING)); options.addManager(&fileOptManager); - options.setDescription(gmx::constArrayRefFromArray(desc, ndesc)); if (FF(PCA_CAN_SET_DEFFNM)) { @@ -567,7 +566,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags, "Help output should be handled higher up and " "only get called only on the master rank"); gmx::CommandLineHelpWriter(options) - .setShowDescriptions(true) + .setHelpText(gmx::constArrayRefFromArray(desc, ndesc)) .setTimeUnitString(timeUnitManager.timeUnitAsString()) .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs)) .writeHelp(*context); diff --git a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp index 5fada52c35..ba62e55e03 100644 --- a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp @@ -107,13 +107,14 @@ TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic) * * \ingroup module_commandline */ -void initOptionsBasic(gmx::Options *options) +void initOptionsBasic(gmx::Options *options, + gmx::ICommandLineOptionsModuleSettings *settings) { const char *const desc[] = { "Sample description", "for testing [THISMODULE]." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(gmx::IntegerOption("int")); } @@ -143,8 +144,8 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp) MockHelpTopic &topic2 = addHelpTopic("topic2", "Another topic"); using ::testing::_; using ::testing::Invoke; - EXPECT_CALL(mod1, initOptions(_)).WillOnce(Invoke(&initOptionsBasic)); - EXPECT_CALL(mod2, initOptions(_)); + EXPECT_CALL(mod1, initOptions(_, _)).WillOnce(Invoke(&initOptionsBasic)); + EXPECT_CALL(mod2, initOptions(_, _)); EXPECT_CALL(topic1, writeHelp(_)); EXPECT_CALL(sub1, writeHelp(_)); EXPECT_CALL(sub2, writeHelp(_)); diff --git a/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp b/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp index 7d3a282e2e..886b0b0d18 100644 --- a/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp +++ b/src/gromacs/commandline/tests/cmdlinehelpwriter.cpp @@ -56,6 +56,7 @@ #include "gromacs/options/basicoptions.h" #include "gromacs/options/filenameoption.h" #include "gromacs/options/options.h" +#include "gromacs/utility/arrayref.h" #include "gromacs/utility/stringstream.h" #include "testutils/stringtest.h" @@ -246,32 +247,22 @@ TEST_F(CommandLineHelpWriterTest, HandlesSelectionOptions) #endif /* - * Tests help printing for multiple sections. + * Tests help output using a help text. */ -TEST_F(CommandLineHelpWriterTest, HandlesMultipleSections) +TEST_F(CommandLineHelpWriterTest, HandlesHelpText) { - using namespace gmx; + const char *const help[] = { + "Help text", + "for testing." + }; + using gmx::IntegerOption; - Options options("test", "Main Title"); - Options subSect1("subsect1", "Subsection 1 Title"); - Options subSect2("subsect2", "Subsection 2 Title"); - Options subSect3("subsect3", NULL); - options.addSubSection(&subSect1); - options.addSubSection(&subSect2); - options.addSubSection(&subSect3); - options.setDescription("Description for main section."); - subSect1.setDescription("Description for subsection 1."); - subSect2.setDescription("Description for subsection 2."); - subSect3.setDescription("Description for subsection 3."); - options.addOption(IntegerOption("main") - .description("Option in main section")); - subSect1.addOption(IntegerOption("sub1") - .description("Option in subsection 1")); - subSect2.addOption(IntegerOption("sub2") - .description("Option in subsection 2")); + gmx::Options options(NULL, NULL); + options.addOption(IntegerOption("int").description("Integer option") + .defaultValue(2)); - CommandLineHelpWriter writer(options); - writer.setShowDescriptions(true); + gmx::CommandLineHelpWriter writer(options); + writer.setHelpText(help); checkHelp(&writer); } diff --git a/src/gromacs/commandline/tests/cmdlinemodulemanagertest.h b/src/gromacs/commandline/tests/cmdlinemodulemanagertest.h index c41cc55bcc..deb27ddb3a 100644 --- a/src/gromacs/commandline/tests/cmdlinemodulemanagertest.h +++ b/src/gromacs/commandline/tests/cmdlinemodulemanagertest.h @@ -108,7 +108,7 @@ class MockOptionsModule : public gmx::ICommandLineOptionsModule ~MockOptionsModule(); MOCK_METHOD1(init, void(gmx::CommandLineModuleSettings *settings)); - MOCK_METHOD1(initOptions, void(gmx::Options *options)); + MOCK_METHOD2(initOptions, void(gmx::Options *options, gmx::ICommandLineOptionsModuleSettings *settings)); MOCK_METHOD1(optionsFinished, void(gmx::Options *options)); MOCK_METHOD0(run, int()); }; diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml new file mode 100644 index 0000000000..5ecad2b947 --- /dev/null +++ b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml @@ -0,0 +1,21 @@ + + + + ] + +DESCRIPTION + +Help text for testing. + +OPTIONS + +Other options: + + -int (2) + Integer option + +]]> + diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml deleted file mode 100644 index baa4db0047..0000000000 --- a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - ] [-sub2 ] [-main ] - -DESCRIPTION - -Description for main section. - -Description for subsection 1. - -Description for subsection 2. - -Description for subsection 3. - -OPTIONS - -Other options: - - -sub1 - Option in subsection 1 - -sub2 - Option in subsection 2 - -main - Option in main section - -]]> - diff --git a/src/gromacs/gmxpreprocess/insert-molecules.cpp b/src/gromacs/gmxpreprocess/insert-molecules.cpp index 34421a3c10..b4f77af2b3 100644 --- a/src/gromacs/gmxpreprocess/insert-molecules.cpp +++ b/src/gromacs/gmxpreprocess/insert-molecules.cpp @@ -318,7 +318,8 @@ class InsertMolecules : public ICommandLineOptionsModule { } - virtual void initOptions(Options *options); + virtual void initOptions(Options *options, + ICommandLineOptionsModuleSettings *settings); virtual void optionsFinished(Options *options); virtual int run(); @@ -339,7 +340,8 @@ class InsertMolecules : public ICommandLineOptionsModule int enumRot_; }; -void InsertMolecules::initOptions(Options *options) +void InsertMolecules::initOptions(Options *options, + ICommandLineOptionsModuleSettings *settings) { const char *const desc[] = { "[THISMODULE] inserts [TT]-nmol[tt] copies of the system specified in", @@ -376,7 +378,7 @@ void InsertMolecules::initOptions(Options *options) "[TT]-try[tt] and [TT]-rot[tt] work as in the default mode (see above)." }; - options->setDescription(desc); + settings->setHelpText(desc); // TODO: Replace use of legacyType. options->addOption(FileNameOption("f") diff --git a/src/gromacs/options/options-impl.h b/src/gromacs/options/options-impl.h index 3fba6da02a..a5294c0420 100644 --- a/src/gromacs/options/options-impl.h +++ b/src/gromacs/options/options-impl.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,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. @@ -108,10 +108,6 @@ class Options::Impl //! Name for the Options object. std::string name_; - //! Description title for the Options object. - std::string title_; - //! Full description for the Options object. - std::string description_; /*! \brief * Option managers set for this collection. * diff --git a/src/gromacs/options/options.cpp b/src/gromacs/options/options.cpp index 4048addbf3..c0cff70203 100644 --- a/src/gromacs/options/options.cpp +++ b/src/gromacs/options/options.cpp @@ -67,8 +67,8 @@ IOptionManager::~IOptionManager() * Options::Impl */ -Options::Impl::Impl(const char *name, const char *title) - : name_(name != NULL ? name : ""), title_(title != NULL ? title : ""), +Options::Impl::Impl(const char *name, const char * /*title*/) + : name_(name != NULL ? name : ""), parent_(NULL) { } @@ -137,25 +137,6 @@ const std::string &Options::name() const return impl_->name_; } -const std::string &Options::title() const -{ - return impl_->title_; -} - -const std::string &Options::description() const -{ - return impl_->description_; -} - -void Options::setDescription(const std::string &desc) -{ - impl_->description_ = desc; -} - -void Options::setDescription(const ConstArrayRef &descArray) -{ - impl_->description_ = joinStrings(descArray, "\n"); -} void Options::addManager(IOptionManager *manager) { diff --git a/src/gromacs/options/options.h b/src/gromacs/options/options.h index 452f96c6de..d62319b0a0 100644 --- a/src/gromacs/options/options.h +++ b/src/gromacs/options/options.h @@ -55,8 +55,6 @@ namespace gmx { -template class ConstArrayRef; - class AbstractOption; class OptionsAssigner; class OptionsIterator; @@ -134,43 +132,6 @@ class Options //! Returns the short name of the option collection. const std::string &name() const; - //! Returns the title of the option collection. - const std::string &title() const; - //! Returns the full description of the option collection. - const std::string &description() const; - - /*! \brief - * Sets the full description of the option collection. - * - * \param[in] desc String to set as the description. - * - * This overload is mainly useful if the description is very short. - * Currently this is mostly the case in unit testing. - */ - void setDescription(const std::string &desc); - /*! \brief - * Sets the full description of the option collection from string array. - * - * \param[in] descArray String array to set as the description. - * - * All strings in `descArray` are concatenated to form the description. - * Spaces are inserted between strings if they are missing. - * - * Example usage: - * \code - const char *const desc[] = { - "This is the description", - "for the options" - }; - - gmx::Options options(NULL, NULL); - options.setDescription(desc); - \endcode - * - * To use this overload, you must also include - * `gromacs/utility/arrayref.h`. - */ - void setDescription(const ConstArrayRef &descArray); /*! \brief * Adds an option manager. diff --git a/src/gromacs/trajectoryanalysis/analysissettings-impl.h b/src/gromacs/trajectoryanalysis/analysissettings-impl.h index b42defaaa6..0939204c8f 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings-impl.h +++ b/src/gromacs/trajectoryanalysis/analysissettings-impl.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,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. @@ -42,6 +42,8 @@ #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H +#include + #include "gromacs/analysisdata/modules/plot.h" #include "gromacs/options/timeunitmanager.h" #include "gromacs/trajectoryanalysis/analysissettings.h" @@ -73,6 +75,9 @@ class TrajectoryAnalysisSettings::Impl bool bRmPBC; //! Whether to pass PBC information to the analysis module. bool bPBC; + + //! Help text for the module. + std::string helpText_; }; } // namespace gmx diff --git a/src/gromacs/trajectoryanalysis/analysissettings.cpp b/src/gromacs/trajectoryanalysis/analysissettings.cpp index da9031abb8..03689a8fca 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.cpp +++ b/src/gromacs/trajectoryanalysis/analysissettings.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,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. @@ -46,8 +46,10 @@ #include "gromacs/fileio/trxio.h" #include "gromacs/math/vec.h" #include "gromacs/topology/topology.h" +#include "gromacs/utility/arrayref.h" #include "gromacs/utility/exceptions.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/stringutil.h" #include "analysissettings-impl.h" @@ -161,6 +163,18 @@ TrajectoryAnalysisSettings::setFrameFlags(int frflags) impl_->frflags = frflags; } +const std::string & +TrajectoryAnalysisSettings::helpText() const +{ + return impl_->helpText_; +} + +void +TrajectoryAnalysisSettings::setHelpText(const ConstArrayRef &help) +{ + impl_->helpText_ = joinStrings(help, "\n"); +} + /******************************************************************** * TopologyInformation diff --git a/src/gromacs/trajectoryanalysis/analysissettings.h b/src/gromacs/trajectoryanalysis/analysissettings.h index 20383df9cd..ba2b6a1225 100644 --- a/src/gromacs/trajectoryanalysis/analysissettings.h +++ b/src/gromacs/trajectoryanalysis/analysissettings.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,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. @@ -43,6 +43,8 @@ #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H +#include + #include "gromacs/math/vectypes.h" #include "gromacs/options/timeunitmanager.h" #include "gromacs/utility/classhelpers.h" @@ -52,6 +54,8 @@ struct t_topology; namespace gmx { +template class ConstArrayRef; + class AnalysisDataPlotSettings; class Options; class TrajectoryAnalysisRunnerCommon; @@ -218,6 +222,11 @@ class TrajectoryAnalysisSettings */ void setFrameFlags(int frflags); + //! Returns the help text. + const std::string &helpText() const; + //! \copydoc ICommandLineOptionsModuleSettings::setHelpText(const std::string &) + void setHelpText(const ConstArrayRef &help); + private: class Impl; diff --git a/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp b/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp index 339c0c7fc8..5ac15b6281 100644 --- a/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp +++ b/src/gromacs/trajectoryanalysis/cmdlinerunner.cpp @@ -273,7 +273,7 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &con selections.initOptions(&selectionOptions); CommandLineHelpWriter(options) - .setShowDescriptions(true) + .setHelpText(settings.helpText()) .setTimeUnitString(settings.timeUnitManager().timeUnitAsString()) .writeHelp(context); } diff --git a/src/gromacs/trajectoryanalysis/modules/angle.cpp b/src/gromacs/trajectoryanalysis/modules/angle.cpp index a8a4e0a358..8968c49690 100644 --- a/src/gromacs/trajectoryanalysis/modules/angle.cpp +++ b/src/gromacs/trajectoryanalysis/modules/angle.cpp @@ -304,7 +304,7 @@ Angle::Angle() void -Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) +Angle::initOptions(Options *options, TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "[THISMODULE] computes different types of angles between vectors.", @@ -359,7 +359,7 @@ Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) static const char *const cGroup2TypeEnum[] = { "none", "vector", "plane", "t0", "z", "sphnorm" }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile() .store(&fnAverage_).defaultBasename("angaver") diff --git a/src/gromacs/trajectoryanalysis/modules/distance.cpp b/src/gromacs/trajectoryanalysis/modules/distance.cpp index 4b07d1483a..bc9fb9687e 100644 --- a/src/gromacs/trajectoryanalysis/modules/distance.cpp +++ b/src/gromacs/trajectoryanalysis/modules/distance.cpp @@ -132,7 +132,7 @@ Distance::Distance() void -Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) +Distance::initOptions(Options *options, TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "[THISMODULE] calculates distances between pairs of positions", @@ -156,7 +156,7 @@ Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings* "distances, use [gmx-pairdist]." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile() .store(&fnAverage_).defaultBasename("distave") diff --git a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp index b489c2a933..a99215cffd 100644 --- a/src/gromacs/trajectoryanalysis/modules/freevolume.cpp +++ b/src/gromacs/trajectoryanalysis/modules/freevolume.cpp @@ -196,8 +196,7 @@ FreeVolume::initOptions(Options *options, "the terminal." }; - // Add the descriptive text (program help text) to the options - options->setDescription(desc); + settings->setHelpText(desc); // Add option for optional output file options->addOption(FileNameOption("o").filetype(eftPlot).outputFile() diff --git a/src/gromacs/trajectoryanalysis/modules/pairdist.cpp b/src/gromacs/trajectoryanalysis/modules/pairdist.cpp index 37b2bbbef5..0d365ffa34 100644 --- a/src/gromacs/trajectoryanalysis/modules/pairdist.cpp +++ b/src/gromacs/trajectoryanalysis/modules/pairdist.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -177,7 +177,7 @@ PairDistance::PairDistance() void -PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) +PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "[THISMODULE] calculates pairwise distances between one reference", @@ -214,7 +214,7 @@ PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*setti "[gmx-distance] may be a more suitable tool." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required() .store(&fnDist_).defaultBasename("dist") diff --git a/src/gromacs/trajectoryanalysis/modules/rdf.cpp b/src/gromacs/trajectoryanalysis/modules/rdf.cpp index 468b729873..448095bdf3 100644 --- a/src/gromacs/trajectoryanalysis/modules/rdf.cpp +++ b/src/gromacs/trajectoryanalysis/modules/rdf.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,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. @@ -200,7 +200,7 @@ Rdf::Rdf() } void -Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) +Rdf::initOptions(Options *options, TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "[THISMODULE] calculates radial distribution functions from one", @@ -240,7 +240,7 @@ Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) "i.e. the average number of particles within a distance r.[PAR]" }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required() .store(&fnRdf_).defaultBasename("rdf") diff --git a/src/gromacs/trajectoryanalysis/modules/sasa.cpp b/src/gromacs/trajectoryanalysis/modules/sasa.cpp index 674a5fa265..9649102069 100644 --- a/src/gromacs/trajectoryanalysis/modules/sasa.cpp +++ b/src/gromacs/trajectoryanalysis/modules/sasa.cpp @@ -445,7 +445,7 @@ Sasa::initOptions(Options *options, TrajectoryAnalysisSettings *settings) "that are both too high." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required() .store(&fnArea_).defaultBasename("area") diff --git a/src/gromacs/trajectoryanalysis/modules/select.cpp b/src/gromacs/trajectoryanalysis/modules/select.cpp index 443c4a129c..0239d18860 100644 --- a/src/gromacs/trajectoryanalysis/modules/select.cpp +++ b/src/gromacs/trajectoryanalysis/modules/select.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2009,2010,2011,2012,2013,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. @@ -327,7 +327,7 @@ Select::Select() void -Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) +Select::initOptions(Options *options, TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "[THISMODULE] writes out basic data about dynamic selections.", @@ -391,7 +391,7 @@ Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/) "dynamic selections." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(FileNameOption("os").filetype(eftPlot).outputFile() .store(&fnSize_).defaultBasename("size") diff --git a/src/gromacs/trajectoryanalysis/tests/test_selection.cpp b/src/gromacs/trajectoryanalysis/tests/test_selection.cpp index e8153b6e2e..c0868646e6 100644 --- a/src/gromacs/trajectoryanalysis/tests/test_selection.cpp +++ b/src/gromacs/trajectoryanalysis/tests/test_selection.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2011,2012,2013,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. @@ -99,14 +99,14 @@ SelectionTester::printSelections() } void -SelectionTester::initOptions(Options *options, - TrajectoryAnalysisSettings * /*settings*/) +SelectionTester::initOptions(Options *options, + TrajectoryAnalysisSettings *settings) { static const char *const desc[] = { "This is a test program for selections." }; - options->setDescription(desc); + settings->setHelpText(desc); options->addOption(SelectionOption("select").storeVector(&selections_) .required().multiValue() -- 2.22.0