/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * Copyright (c) 2012,2013,2014, 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 gmx::SelectionOptionManager.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \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"
requestUnsetRequiredOptions();
}
- RequestsClearer clearRequestsOnExit(&requests_);
+ RequestsClearer clearRequestsOnExit(&requests_);
SelectionList::const_iterator first = selections.begin();
- SelectionList::const_iterator last = first;
- RequestList::const_iterator i;
+ SelectionList::const_iterator last = first;
+ RequestList::const_iterator i;
for (i = requests_.begin(); i != requests_.end(); ++i)
{
const SelectionRequest &request = *i;
{
int assigned = first - selections.begin();
GMX_THROW(InvalidInputError(formatString(
- "Too few selections provided for '%s': "
- "Expected %d selections, but only %d left "
- "after assigning the first %d to other selections.",
- request.name().c_str(), request.count(),
- remaining, assigned)));
+ "Too few selections provided for '%s': "
+ "Expected %d selections, but only %d left "
+ "after assigning the first %d to other selections.",
+ request.name().c_str(), request.count(),
+ remaining, assigned)));
}
last = first + request.count();
}
++nextRequest;
if (nextRequest != requests_.end())
{
- const char *name = request.name().c_str();
+ const char *name = request.name().c_str();
const char *conflictName = nextRequest->name().c_str();
GMX_THROW(InvalidInputError(formatString(
- "Ambiguous selections for '%s' and '%s': "
- "Any number of selections is acceptable for "
- "'%s', but you have requested subsequent "
- "selections to be assigned to '%s'. "
- "Resolution for such cases is not implemented, "
- "and may be impossible.",
- name, conflictName, name, conflictName)));
+ "Ambiguous selections for '%s' and '%s': "
+ "Any number of selections is acceptable for "
+ "'%s', but you have requested subsequent "
+ "selections to be assigned to '%s'. "
+ "Resolution for such cases is not implemented, "
+ "and may be impossible.",
+ name, conflictName, name, conflictName)));
}
last = selections.end();
}
}
if (last != selections.end())
{
- int count = selections.end() - selections.begin();
+ int count = selections.end() - selections.begin();
int remaining = selections.end() - last;
- int assigned = last - selections.begin();
+ int assigned = last - selections.begin();
GMX_THROW(InvalidInputError(formatString(
- "Too many selections provided: "
- "Expected %d selections, but %d provided. "
- "Last %d selections could not be assigned to any option.",
- assigned, count, remaining)));
+ "Too many selections provided: "
+ "Expected %d selections, but %d provided. "
+ "Last %d selections could not be assigned to any option.",
+ assigned, count, remaining)));
}
}
void
SelectionOptionManager::convertOptionValue(SelectionOptionStorage *storage,
- const std::string &value)
+ const std::string &value,
+ bool bFullValue)
{
SelectionList selections = impl_->collection_.parseFromString(value);
- storage->addSelections(selections, false);
+ storage->addSelections(selections, bFullValue);
}
void
void
SelectionOptionManager::parseRequestedFromStdin(bool bInteractive)
{
- Impl::RequestsClearer clearRequestsOnExit(&impl_->requests_);
+ Impl::RequestsClearer clearRequestsOnExit(&impl_->requests_);
Impl::RequestList::const_iterator i;
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);
}
}
catch (GromacsException &ex)
{
ex.prependContext(formatString(
- "Error in adding selections from file '%s'",
- filename.c_str()));
+ "Error in adding selections from file '%s'",
+ filename.c_str()));
throw;
}
}
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