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
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 &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;
MockHelpTopic &topic2 = addHelpTopic("topic2", "Another topic");
using ::testing::_;
using ::testing::Invoke;
EXPECT_CALL(topic1, writeHelp(_));
EXPECT_CALL(sub1, writeHelp(_));
EXPECT_CALL(sub2, writeHelp(_));
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()));
EXPECT_CALL(topic2, writeHelp(_));
int rc = 0;
ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
Subtopic 2
----------
Sub text
Subtopic 2
----------
Sub text
+
+Out-of-order subtopic
+---------------------
+Sub text
]]></String>
<String Name="programs/topic2.rst"><![CDATA[
Another topic
]]></String>
<String Name="programs/topic2.rst"><![CDATA[
Another topic
class AbstractCompositeHelpTopic::Impl
{
public:
class AbstractCompositeHelpTopic::Impl
{
public:
+ //! Container for subtopics.
+ typedef std::vector<HelpTopicPointer> SubTopicList;
//! Container for mapping subtopic names to help topic objects.
//! Container for mapping subtopic names to help topic objects.
- typedef std::map<std::string, HelpTopicPointer> SubTopicMap;
+ typedef std::map<std::string, const HelpTopicInterface *> SubTopicMap;
- * Maps subtopic names to help topic objects.
+ * Subtopics in the order they were added.
*
* Owns the contained subtopics.
*/
*
* 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_;
};
/********************************************************************
};
/********************************************************************
bool AbstractCompositeHelpTopic::hasSubTopics() const
{
bool AbstractCompositeHelpTopic::hasSubTopics() const
{
- return !impl_->subtopics_.empty();
+ return !impl_->subTopics_.empty();
}
const HelpTopicInterface *
AbstractCompositeHelpTopic::findSubTopic(const char *name) const
{
}
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 topic->second.get();
}
void AbstractCompositeHelpTopic::writeHelp(const HelpWriterContext &context) const
}
void AbstractCompositeHelpTopic::writeHelp(const HelpWriterContext &context) const
{
if (context.outputFormat() != eHelpOutputFormat_Console)
{
{
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);
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;
}
}
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))
{
const char *const title = topic->second->title();
if (!isNullOrEmpty(title))
formatter.addColumn(NULL, 72 - maxNameLength, true);
formatter.setFirstColumnIndent(4);
file.writeLine(title);
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();
{
const char *const name = topic->first.c_str();
const char *const title = topic->second->title();
void AbstractCompositeHelpTopic::addSubTopic(HelpTopicPointer topic)
{
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");
"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));
HelpTopicPointer createSelectionHelpTopic()
{
CompositeHelpTopicPointer root(new CompositeHelpTopic<CommonHelpText>);
HelpTopicPointer createSelectionHelpTopic()
{
CompositeHelpTopicPointer root(new CompositeHelpTopic<CommonHelpText>);
- root->registerSubTopic<SimpleHelpTopic<ArithmeticHelpText> >();
root->registerSubTopic<SimpleHelpTopic<CmdLineHelpText> >();
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<KeywordsHelpTopic>();
+ root->registerSubTopic<SimpleHelpTopic<EvaluationHelpText> >();
root->registerSubTopic<SimpleHelpTopic<LimitationsHelpText> >();
root->registerSubTopic<SimpleHelpTopic<LimitationsHelpText> >();
- root->registerSubTopic<SimpleHelpTopic<PositionsHelpText> >();
- root->registerSubTopic<SimpleHelpTopic<SyntaxHelpText> >();
+ root->registerSubTopic<SimpleHelpTopic<ExamplesHelpText> >();
return move(root);
}
//! \endcond
return move(root);
}
//! \endcond