Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / options / options.cpp
index 8b3c22e2646ec3970f1bff7054c397d1c187d1e9..aec42fc98ffc71d58cb297f04513c0f237b1dab4 100644 (file)
@@ -39,7 +39,9 @@
  * \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"
 namespace gmx
 {
 
+/********************************************************************
+ * OptionManagerInterface
+ */
+
+OptionManagerInterface::~OptionManagerInterface()
+{
+}
+
 /********************************************************************
  * Options::Impl
  */
@@ -148,8 +158,28 @@ 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");
@@ -162,7 +192,12 @@ void Options::addSubSection(Options *section)
 
 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()));