* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
+#include "gmxpre.h"
+
#include "selectionoptionmanager.h"
#include <cstdio>
-#include "gromacs/options/optionsvisitor.h"
#include "gromacs/selection/selection.h"
#include "gromacs/selection/selectioncollection.h"
-#include "gromacs/selection/selectionoption.h"
#include "gromacs/selection/selectionfileoption.h"
+#include "gromacs/selection/selectionoption.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/stringutil.h"
for (i = impl_->requests_.begin(); i != impl_->requests_.end(); ++i)
{
const Impl::SelectionRequest &request = *i;
- if (bInteractive)
- {
- std::fprintf(stderr, "\nSpecify ");
- if (request.count() < 0)
- {
- std::fprintf(stderr, "any number of selections");
- }
- else if (request.count() == 1)
- {
- std::fprintf(stderr, "a selection");
- }
- else
- {
- std::fprintf(stderr, "%d selections", request.count());
- }
- std::fprintf(stderr, " for option '%s' (%s):\n",
+ std::string context =
+ formatString("for option '%s'\n(%s)",
request.name().c_str(), request.description().c_str());
- std::fprintf(stderr, "(one selection per line, 'help' for help%s)\n",
- request.count() < 0 ? ", Ctrl-D to end" : "");
- }
SelectionList selections
- = impl_->collection_.parseFromStdin(request.count(), bInteractive);
+ = impl_->collection_.parseFromStdin(request.count(), bInteractive,
+ context);
request.storage_->addSelections(selections, true);
}
}
impl_->placeSelectionsInRequests(selections);
}
-/********************************************************************
- * Global functions
- */
-
-namespace
-{
-
-/*! \internal \brief
- * Visitor that sets the manager for each selection option.
- *
- * \ingroup module_selection
- */
-class SelectionOptionManagerSetter : public OptionsModifyingVisitor
-{
- public:
- //! Construct a visitor that sets given manager.
- explicit SelectionOptionManagerSetter(SelectionOptionManager *manager)
- : manager_(manager)
- {
- }
-
- void visitSubSection(Options *section)
- {
- OptionsModifyingIterator iterator(section);
- iterator.acceptSubSections(this);
- iterator.acceptOptions(this);
- }
-
- void visitOption(OptionInfo *option)
- {
- SelectionOptionInfo *selOption
- = option->toType<SelectionOptionInfo>();
- if (selOption != NULL)
- {
- selOption->setManager(manager_);
- }
- SelectionFileOptionInfo *selFileOption
- = option->toType<SelectionFileOptionInfo>();
- if (selFileOption != NULL)
- {
- selFileOption->setManager(manager_);
- }
- }
-
- private:
- SelectionOptionManager *manager_;
-};
-
-} // namespace
-
-void setManagerForSelectionOptions(Options *options,
- SelectionOptionManager *manager)
-{
- SelectionOptionManagerSetter(manager).visitSubSection(options);
-}
-
} // namespace gmx