Allow any order for sections in 'gmx help -export'
authorTeemu Murtola <teemu.murtola@gmail.com>
Tue, 19 May 2015 15:06:07 +0000 (18:06 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Fri, 22 May 2015 14:53:39 +0000 (16:53 +0200)
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

src/gromacs/commandline/tests/cmdlinehelpmodule.cpp
src/gromacs/commandline/tests/refdata/CommandLineHelpModuleTest_ExportsHelp.xml
src/gromacs/onlinehelp/helptopic.cpp
src/gromacs/selection/selhelp.cpp

index e5b9a139622863d985579b37ff9269a2504e1e06..b8cb8eae28e2bc4e658bebe3925ffdc61571a8e6 100644 (file)
@@ -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()));
index 02a51bb3da9d414aeae202e7581e6cfb581d2083..7ad92f536e7b2f713d29282512a7019436a7ab99 100644 (file)
@@ -119,6 +119,10 @@ Sub text
 Subtopic 2
 ----------
 Sub text
+
+Out-of-order subtopic
+---------------------
+Sub text
 ]]></String>
   <String Name="programs/topic2.rst"><![CDATA[
 Another topic
index c2d88baf68f32e077630dde6ae15bb9816f2c5f0..58be839ba3222b2400c08a6551fe92605a80cf9f 100644 (file)
@@ -88,15 +88,23 @@ void AbstractSimpleHelpTopic::writeHelp(const HelpWriterContext &context) const
 class AbstractCompositeHelpTopic::Impl
 {
     public:
+        //! Container for subtopics.
+        typedef std::vector<HelpTopicPointer> SubTopicList;
         //! Container for mapping subtopic names to help topic objects.
-        typedef std::map<std::string, HelpTopicPointer> SubTopicMap;
+        typedef std::map<std::string, const HelpTopicInterface *> 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
index 02cdfcb45a8f6ed53be911b24b4d15c6d8ca7d87..f51c0b5ff8ee27b05502798f12e21a970f1a127d 100644 (file)
@@ -683,14 +683,14 @@ void KeywordsHelpTopic::printKeywordList(const HelpWriterContext &context,
 HelpTopicPointer createSelectionHelpTopic()
 {
     CompositeHelpTopicPointer root(new CompositeHelpTopic<CommonHelpText>);
-    root->registerSubTopic<SimpleHelpTopic<ArithmeticHelpText> >();
     root->registerSubTopic<SimpleHelpTopic<CmdLineHelpText> >();
-    root->registerSubTopic<SimpleHelpTopic<EvaluationHelpText> >();
-    root->registerSubTopic<SimpleHelpTopic<ExamplesHelpText> >();
+    root->registerSubTopic<SimpleHelpTopic<SyntaxHelpText> >();
+    root->registerSubTopic<SimpleHelpTopic<PositionsHelpText> >();
+    root->registerSubTopic<SimpleHelpTopic<ArithmeticHelpText> >();
     root->registerSubTopic<KeywordsHelpTopic>();
+    root->registerSubTopic<SimpleHelpTopic<EvaluationHelpText> >();
     root->registerSubTopic<SimpleHelpTopic<LimitationsHelpText> >();
-    root->registerSubTopic<SimpleHelpTopic<PositionsHelpText> >();
-    root->registerSubTopic<SimpleHelpTopic<SyntaxHelpText> >();
+    root->registerSubTopic<SimpleHelpTopic<ExamplesHelpText> >();
     return move(root);
 }
 //! \endcond