/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * Copyright (c) 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.
*
- * G R O M A C S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
*
- * GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements classes and functions from helptopic.h.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_onlinehelp
*/
+#include "gmxpre.h"
+
#include "helptopic.h"
#include <map>
#include "gromacs/onlinehelp/helpformat.h"
#include "gromacs/onlinehelp/helpwritercontext.h"
#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/file.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
namespace gmx
{
-/*! \cond libapi */
-void writeBasicHelpTopic(const HelpWriterContext &context,
- const HelpTopicInterface &topic,
- const std::string &text)
-{
- const char *title = topic.title();
- if (title != NULL && title[0] != '\0')
- {
- context.writeTitle(title);
- }
- context.writeTextBlock(text);
-}
-//! \endcond
-
/********************************************************************
* AbstractSimpleHelpTopic
*/
return false;
}
-const HelpTopicInterface *
-AbstractSimpleHelpTopic::findSubTopic(const char *name) const
+const IHelpTopic *
+AbstractSimpleHelpTopic::findSubTopic(const char * /* name */) const
{
return NULL;
}
void AbstractSimpleHelpTopic::writeHelp(const HelpWriterContext &context) const
{
- writeBasicHelpTopic(context, *this, helpText());
+ context.writeTextBlock(helpText());
}
/********************************************************************
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 IHelpTopic *> 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_;
};
/********************************************************************
bool AbstractCompositeHelpTopic::hasSubTopics() const
{
- return !impl_->subtopics_.empty();
+ return !impl_->subTopics_.empty();
}
-const HelpTopicInterface *
+const IHelpTopic *
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
{
- writeBasicHelpTopic(context, *this, helpText());
+ context.writeTextBlock(helpText());
writeSubTopicList(context, "\nAvailable subtopics:");
}
bool
AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context,
- const std::string &title) const
+ const std::string &title) const
{
if (context.outputFormat() != eHelpOutputFormat_Console)
{
- // TODO: Implement once the situation with Redmine issue #969 is more
- // clear.
- GMX_THROW(NotImplementedError(
- "Subtopic listing is not implemented for this output format"));
+ Impl::SubTopicList::const_iterator topic;
+ for (topic = impl_->subTopics_.begin(); topic != impl_->subTopics_.end(); ++topic)
+ {
+ const char *const title = (*topic)->title();
+ if (!isNullOrEmpty(title))
+ {
+ context.outputFile().writeLine();
+ HelpWriterContext subContext(context);
+ subContext.enterSubSection(title);
+ (*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 *title = topic->second->title();
- if (title == NULL || title[0] == '\0')
- {
- continue;
- }
- int nameLength = static_cast<int>(topic->first.length());
- if (nameLength > maxNameLength)
+ const char *const title = topic->second->title();
+ if (!isNullOrEmpty(title))
{
- maxNameLength = nameLength;
+ int nameLength = static_cast<int>(topic->first.length());
+ if (nameLength > maxNameLength)
+ {
+ maxNameLength = nameLength;
+ }
}
}
if (maxNameLength == 0)
{
return false;
}
- File &file = context.outputFile();
+ TextWriter &file = context.outputFile();
TextTableFormatter formatter;
formatter.addColumn(NULL, maxNameLength + 1, false);
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 *name = topic->first.c_str();
- const char *title = topic->second->title();
- if (title != NULL && title[0] != '\0')
+ const char *const name = topic->first.c_str();
+ const char *const title = topic->second->title();
+ if (!isNullOrEmpty(title))
{
formatter.clear();
formatter.addColumnLine(0, name);
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 IHelpTopic *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