/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2010,2011,2012,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.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_options
*/
-#include "gromacs/options/options.h"
+#include "gmxpre.h"
+
+#include "options.h"
#include "gromacs/options/abstractoption.h"
#include "gromacs/options/abstractoptionstorage.h"
+#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/messagestringcollector.h"
namespace gmx
{
+/********************************************************************
+ * OptionManagerInterface
+ */
+
+OptionManagerInterface::~OptionManagerInterface()
+{
+}
+
/********************************************************************
* Options::Impl
*/
impl_->description_ = desc;
}
+void Options::setDescription(const ConstArrayRef<const char *> &descArray)
+{
+ impl_->description_ = concatenateStrings(descArray.data(), descArray.size());
+}
+
+void Options::addManager(OptionManagerInterface *manager)
+{
+ GMX_RELEASE_ASSERT(impl_->parent_ == NULL,
+ "Can only add a manager in a top-level Options object");
+ // This ensures that all options see the same set of managers.
+ GMX_RELEASE_ASSERT(impl_->options_.empty(),
+ "Can only add a manager before options");
+ // This check could be relaxed if we instead checked that the subsections
+ // do not have options.
+ GMX_RELEASE_ASSERT(impl_->subSections_.empty(),
+ "Can only add a manager before subsections");
+ impl_->managers_.add(manager);
+}
+
void Options::addSubSection(Options *section)
{
+ // This is required, because managers are used from the root Options
+ // object, so they are only seen after the subsection has been added.
+ GMX_RELEASE_ASSERT(section->impl_->options_.empty(),
+ "Can only add a subsection before it has any options");
+ GMX_RELEASE_ASSERT(section->impl_->managers_.empty(),
+ "Can only have managers in a top-level Options object");
// Make sure that section is not already inserted somewhere.
GMX_RELEASE_ASSERT(section->impl_->parent_ == NULL,
"Cannot add as subsection twice");
OptionInfo *Options::addOption(const AbstractOption &settings)
{
- AbstractOptionStoragePointer option(settings.createStorage());
+ Options::Impl *root = impl_.get();
+ while (root->parent_ != NULL)
+ {
+ root = root->parent_->impl_.get();
+ }
+ Impl::AbstractOptionStoragePointer option(settings.createStorage(root->managers_));
if (impl_->findOption(option->name().c_str()) != NULL)
{
GMX_THROW(APIError("Duplicate option: " + option->name()));