/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * Copyright (c) 2010,2011,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 classes in selectionoption.h and selectionoptionstorage.h.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
+#include "gmxpre.h"
+
#include "selectionoption.h"
-#include "selectionfileoption.h"
-#include "selectionoptionstorage.h"
-#include "selectionfileoptionstorage.h"
#include <string>
+#include "gromacs/options/optionmanagercontainer.h"
#include "gromacs/selection/selection.h"
+#include "gromacs/selection/selectionfileoption.h"
#include "gromacs/selection/selectionoptionmanager.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/messagestringcollector.h"
+#include "selectionfileoptionstorage.h"
+#include "selectionoptionstorage.h"
+
namespace gmx
{
* SelectionOptionStorage
*/
-SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings)
+SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings,
+ SelectionOptionManager *manager)
: MyBase(settings, OptionFlags() | efOption_NoDefaultValue
- | efOption_DontCheckMinimumCount),
- info_(this), manager_(NULL), selectionFlags_(settings.selectionFlags_)
+ | efOption_DontCheckMinimumCount),
+ info_(this), manager_(*manager), defaultText_(settings.defaultText_),
+ selectionFlags_(settings.selectionFlags_)
{
+ GMX_RELEASE_ASSERT(manager != NULL,
+ "SelectionOptionManager must be added before SelectionOption");
GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
"allowMultiple() is not supported for selection options");
-}
-
-
-void SelectionOptionStorage::setManager(SelectionOptionManager *manager)
-{
- GMX_RELEASE_ASSERT(manager_ == NULL || manager_ == manager,
- "Manager cannot be changed once set");
- if (manager_ == NULL)
- {
- manager->registerOption(this);
- manager_ = manager;
- }
+ manager_.registerOption(this);
}
void SelectionOptionStorage::addSelections(
const SelectionList &selections,
- bool bFullValue)
+ bool bFullValue)
{
if (bFullValue && selections.size() < static_cast<size_t>(minValueCount()))
{
{
GMX_THROW(InvalidInputError("Dynamic selections not supported"));
}
- addValue(*i);
+ // Create a copy to allow modifications.
+ Selection sel(*i);
+ sel.data().setFlags(selectionFlags_);
+ addValue(sel);
}
if (bFullValue)
{
void SelectionOptionStorage::convertValue(const std::string &value)
{
- GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
- manager_->convertOptionValue(this, value);
+ manager_.convertOptionValue(this, value, false);
}
void SelectionOptionStorage::processSetValues(ValueList *values)
{
- GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
if (values->size() == 0)
{
- manager_->requestOptionDelayedParsing(this);
+ manager_.requestOptionDelayedParsing(this);
}
else if (values->size() < static_cast<size_t>(minValueCount()))
{
GMX_THROW(InvalidInputError("Too few (valid) values provided"));
}
- ValueList::iterator i;
- for (i = values->begin(); i != values->end(); ++i)
- {
- i->data().setFlags(selectionFlags_);
- }
}
void SelectionOptionStorage::processAll()
{
+ if (!isSet() && !defaultText_.empty())
+ {
+ manager_.convertOptionValue(this, defaultText_, true);
+ }
if (isRequired() && !isSet())
{
- GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
- manager_->requestOptionDelayedParsing(this);
+ manager_.requestOptionDelayedParsing(this);
markAsSet();
}
}
return static_cast<const SelectionOptionStorage &>(OptionInfo::option());
}
-void SelectionOptionInfo::setManager(SelectionOptionManager *manager)
-{
- option().setManager(manager);
-}
-
void SelectionOptionInfo::setValueCount(int count)
{
option().setAllowedValueCount(count);
option().setSelectionFlag(efSelection_DynamicMask, bEnabled);
}
-void SelectionOptionInfo::setDynamicOnlyWhole(bool bEnabled)
-{
- option().setSelectionFlag(efSelection_DynamicOnlyWhole, bEnabled);
-}
-
/********************************************************************
* SelectionOption
*/
-AbstractOptionStoragePointer SelectionOption::createStorage() const
+AbstractOptionStorage *
+SelectionOption::createStorage(const OptionManagerContainer &managers) const
{
- return AbstractOptionStoragePointer(new SelectionOptionStorage(*this));
+ return new SelectionOptionStorage(
+ *this, managers.get<SelectionOptionManager>());
}
* SelectionFileOptionStorage
*/
-SelectionFileOptionStorage::SelectionFileOptionStorage(const SelectionFileOption &settings)
+SelectionFileOptionStorage::SelectionFileOptionStorage(
+ const SelectionFileOption &settings, SelectionOptionManager *manager)
: AbstractOptionStorage(settings, OptionFlags() | efOption_MultipleTimes
- | efOption_DontCheckMinimumCount),
- info_(this), manager_(NULL), bValueParsed_(false)
+ | efOption_DontCheckMinimumCount),
+ info_(this), manager_(*manager), bValueParsed_(false)
{
+ GMX_RELEASE_ASSERT(manager != NULL,
+ "SelectionOptionManager must be added before SelectionFileOption");
}
void SelectionFileOptionStorage::clearSet()
void SelectionFileOptionStorage::convertValue(const std::string &value)
{
- GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
if (bValueParsed_)
{
GMX_THROW(InvalidInputError("More than one file name provided"));
}
bValueParsed_ = true;
// TODO: Should we throw an InvalidInputError if the file does not exist?
- manager_->parseRequestedFromFile(value);
+ manager_.parseRequestedFromFile(value);
}
void SelectionFileOptionStorage::processSet()
{
}
-SelectionFileOptionStorage &SelectionFileOptionInfo::option()
-{
- return static_cast<SelectionFileOptionStorage &>(OptionInfo::option());
-}
-
-const SelectionFileOptionStorage &SelectionFileOptionInfo::option() const
-{
- return static_cast<const SelectionFileOptionStorage &>(OptionInfo::option());
-}
-
-void SelectionFileOptionInfo::setManager(SelectionOptionManager *manager)
-{
- option().setManager(manager);
-}
-
/********************************************************************
* SelectionFileOption
setDescription("Provide selections from files");
}
-AbstractOptionStoragePointer SelectionFileOption::createStorage() const
+AbstractOptionStorage *
+SelectionFileOption::createStorage(const OptionManagerContainer &managers) const
{
- return AbstractOptionStoragePointer(new SelectionFileOptionStorage(*this));
+ return new SelectionFileOptionStorage(
+ *this, managers.get<SelectionOptionManager>());
}
} // namespace gmx