3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Implements gmx::HelpManager.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_onlinehelp
38 #include "helpmanager.h"
43 #include "gromacs/onlinehelp/helptopicinterface.h"
44 #include "gromacs/utility/exceptions.h"
45 #include "gromacs/utility/stringutil.h"
50 /********************************************************************
55 * Private implementation class for HelpManager.
57 * \ingroup module_onlinehelp
59 class HelpManager::Impl
62 //! Container type for keeping the stack of active topics.
63 typedef std::vector<const HelpTopicInterface *> TopicStack;
65 //! Initializes a new manager with the given context.
66 explicit Impl(const HelpWriterContext &context)
67 : rootContext_(context)
71 //! Whether the active topic is the root topic.
72 bool isAtRootTopic() const { return topicStack_.size() == 1; }
73 //! Returns the active topic.
74 const HelpTopicInterface ¤tTopic() const
76 return *topicStack_.back();
78 //! Formats the active topic as a string, including its parent topics.
79 std::string currentTopicAsString() const;
81 //! Context with which the manager was initialized.
82 const HelpWriterContext &rootContext_;
84 * Stack of active topics.
86 * The first item is always the root topic, and each item is a subtopic
87 * of the preceding item. The last item is the currently active topic.
89 TopicStack topicStack_;
92 std::string HelpManager::Impl::currentTopicAsString() const
95 TopicStack::const_iterator topic;
96 for (topic = topicStack_.begin() + 1; topic != topicStack_.end(); ++topic)
102 result.append((*topic)->name());
107 /********************************************************************
111 HelpManager::HelpManager(const HelpTopicInterface &rootTopic,
112 const HelpWriterContext &context)
113 : impl_(new Impl(context))
115 impl_->topicStack_.push_back(&rootTopic);
118 HelpManager::~HelpManager()
122 void HelpManager::enterTopic(const char *name)
124 const HelpTopicInterface &topic = impl_->currentTopic();
125 if (!topic.hasSubTopics())
127 GMX_THROW(InvalidInputError(
128 formatString("Help topic '%s' has no subtopics",
129 impl_->currentTopicAsString().c_str())));
131 const HelpTopicInterface *newTopic = topic.findSubTopic(name);
132 if (newTopic == NULL)
134 if (impl_->isAtRootTopic())
136 GMX_THROW(InvalidInputError(
137 formatString("No help available for '%s'", name)));
141 GMX_THROW(InvalidInputError(
142 formatString("Help topic '%s' has no subtopic '%s'",
143 impl_->currentTopicAsString().c_str(), name)));
146 impl_->topicStack_.push_back(newTopic);
149 void HelpManager::enterTopic(const std::string &name)
151 enterTopic(name.c_str());
154 void HelpManager::writeCurrentTopic() const
156 const HelpTopicInterface &topic = impl_->currentTopic();
157 topic.writeHelp(impl_->rootContext_);