From 0119f5e579bc57a1f9c01f14637bdf93994110ca Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Tue, 19 May 2015 18:06:07 +0300 Subject: [PATCH] Allow any order for sections in 'gmx help -export' Make the selection help appear in a more logical order in the user guide by writing out the subtopics in the order in which they were added, and ordering the topics like they were in 4.5 and 4.6. Part of #679. Change-Id: I0adf875fc36d32d79e1e066c0ee8025a6277c0df --- .../commandline/tests/cmdlinehelpmodule.cpp | 2 + .../CommandLineHelpModuleTest_ExportsHelp.xml | 4 ++ src/gromacs/onlinehelp/helptopic.cpp | 42 ++++++++++++------- src/gromacs/selection/selhelp.cpp | 10 ++--- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp index e5b9a13962..b8cb8eae28 100644 --- a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp @@ -142,6 +142,7 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp) MockHelpTopic &topic1 = addHelpTopic("topic1", "Test topic"); MockHelpTopic &sub1 = topic1.addSubTopic("sub1", "Subtopic 1", "Sub text"); MockHelpTopic &sub2 = topic1.addSubTopic("sub2", "Subtopic 2", "Sub text"); + MockHelpTopic &sub3 = topic1.addSubTopic("other", "Out-of-order subtopic", "Sub text"); MockHelpTopic &topic2 = addHelpTopic("topic2", "Another topic"); using ::testing::_; using ::testing::Invoke; @@ -150,6 +151,7 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp) EXPECT_CALL(topic1, writeHelp(_)); EXPECT_CALL(sub1, writeHelp(_)); EXPECT_CALL(sub2, writeHelp(_)); + EXPECT_CALL(sub3, writeHelp(_)); EXPECT_CALL(topic2, writeHelp(_)); int rc = 0; ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv())); diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml index 02a51bb3da..7ad92f536e 100644 --- a/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml +++ b/src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml @@ -119,6 +119,10 @@ Sub text Subtopic 2 ---------- Sub text + +Out-of-order subtopic +--------------------- +Sub text ]]> SubTopicList; //! Container for mapping subtopic names to help topic objects. - typedef std::map SubTopicMap; + typedef std::map SubTopicMap; /*! \brief - * Maps subtopic names to help topic objects. + * Subtopics in the order they were added. * * Owns the contained subtopics. */ - SubTopicMap subtopics_; + SubTopicList subTopics_; + /*! \brief + * Maps subtopic names to help topic objects. + * + * Points to objects in the \a subTopics_ map. + */ + SubTopicMap subTopicMap_; }; /******************************************************************** @@ -114,18 +122,18 @@ AbstractCompositeHelpTopic::~AbstractCompositeHelpTopic() bool AbstractCompositeHelpTopic::hasSubTopics() const { - return !impl_->subtopics_.empty(); + return !impl_->subTopics_.empty(); } const HelpTopicInterface * AbstractCompositeHelpTopic::findSubTopic(const char *name) const { - Impl::SubTopicMap::const_iterator topic = impl_->subtopics_.find(name); - if (topic == impl_->subtopics_.end()) + Impl::SubTopicMap::const_iterator topic = impl_->subTopicMap_.find(name); + if (topic == impl_->subTopicMap_.end()) { return NULL; } - return topic->second.get(); + return topic->second; } void AbstractCompositeHelpTopic::writeHelp(const HelpWriterContext &context) const @@ -140,23 +148,23 @@ AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context, { if (context.outputFormat() != eHelpOutputFormat_Console) { - Impl::SubTopicMap::const_iterator topic; - for (topic = impl_->subtopics_.begin(); topic != impl_->subtopics_.end(); ++topic) + Impl::SubTopicList::const_iterator topic; + for (topic = impl_->subTopics_.begin(); topic != impl_->subTopics_.end(); ++topic) { - const char *const title = topic->second->title(); + const char *const title = (*topic)->title(); if (!isNullOrEmpty(title)) { context.outputFile().writeLine(); HelpWriterContext subContext(context); subContext.enterSubSection(title); - topic->second->writeHelp(subContext); + (*topic)->writeHelp(subContext); } } return true; } int maxNameLength = 0; Impl::SubTopicMap::const_iterator topic; - for (topic = impl_->subtopics_.begin(); topic != impl_->subtopics_.end(); ++topic) + for (topic = impl_->subTopicMap_.begin(); topic != impl_->subTopicMap_.end(); ++topic) { const char *const title = topic->second->title(); if (!isNullOrEmpty(title)) @@ -178,7 +186,7 @@ AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context, formatter.addColumn(NULL, 72 - maxNameLength, true); formatter.setFirstColumnIndent(4); file.writeLine(title); - for (topic = impl_->subtopics_.begin(); topic != impl_->subtopics_.end(); ++topic) + for (topic = impl_->subTopicMap_.begin(); topic != impl_->subTopicMap_.end(); ++topic) { const char *const name = topic->first.c_str(); const char *const title = topic->second->title(); @@ -195,10 +203,12 @@ AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context, void AbstractCompositeHelpTopic::addSubTopic(HelpTopicPointer topic) { - GMX_ASSERT(impl_->subtopics_.find(topic->name()) == impl_->subtopics_.end(), + GMX_ASSERT(impl_->subTopicMap_.find(topic->name()) == impl_->subTopicMap_.end(), "Attempted to register a duplicate help topic name"); - impl_->subtopics_.insert(std::make_pair(std::string(topic->name()), - move(topic))); + const HelpTopicInterface *topicPtr = topic.get(); + impl_->subTopics_.reserve(impl_->subTopics_.size() + 1); + impl_->subTopicMap_.insert(std::make_pair(std::string(topicPtr->name()), topicPtr)); + impl_->subTopics_.push_back(move(topic)); } } // namespace gmx diff --git a/src/gromacs/selection/selhelp.cpp b/src/gromacs/selection/selhelp.cpp index 02cdfcb45a..f51c0b5ff8 100644 --- a/src/gromacs/selection/selhelp.cpp +++ b/src/gromacs/selection/selhelp.cpp @@ -683,14 +683,14 @@ void KeywordsHelpTopic::printKeywordList(const HelpWriterContext &context, HelpTopicPointer createSelectionHelpTopic() { CompositeHelpTopicPointer root(new CompositeHelpTopic); - root->registerSubTopic >(); root->registerSubTopic >(); - root->registerSubTopic >(); - root->registerSubTopic >(); + root->registerSubTopic >(); + root->registerSubTopic >(); + root->registerSubTopic >(); root->registerSubTopic(); + root->registerSubTopic >(); root->registerSubTopic >(); - root->registerSubTopic >(); - root->registerSubTopic >(); + root->registerSubTopic >(); return move(root); } //! \endcond -- 2.22.0