Remove obsolete pointers in options handling.
authorTeemu Murtola <teemu.murtola@gmail.com>
Mon, 27 Feb 2012 19:43:12 +0000 (21:43 +0200)
committerRoland Schulz <roland@utk.edu>
Sun, 18 Mar 2012 21:23:52 +0000 (17:23 -0400)
After OptionsGlobalProperties was removed, it is no longer necessary to
be able to access the parent Options object from individual options.
Removed the related code (mainly removing "Options *" parameters from
constructors).

Change-Id: I794fa3821be34ea9bde34c169ea5f4ce40147fb9

12 files changed:
src/gromacs/options/abstractoption.cpp
src/gromacs/options/abstractoption.h
src/gromacs/options/abstractoptionstorage.h
src/gromacs/options/basicoptions.cpp
src/gromacs/options/basicoptions.h
src/gromacs/options/basicoptionstorage.h
src/gromacs/options/options.cpp
src/gromacs/options/optionstoragetemplate.h
src/gromacs/options/tests/abstractoptionstorage.cpp
src/gromacs/selection/selectionoption.cpp
src/gromacs/selection/selectionoption.h
src/gromacs/selection/selectionoptionstorage.h

index af18299d55f801fc9940d6c12e1529f315ba7c24..6dc97bfea9f52f2acec3ffb9869005acc2d52a1b 100644 (file)
@@ -52,13 +52,11 @@ namespace gmx
  */
 
 AbstractOptionStorage::AbstractOptionStorage(const AbstractOption &settings,
-                                             Options *options,
                                              OptionFlags staticFlags)
     : _flags(settings._flags | staticFlags),
       _minValueCount(settings._minValueCount),
       _maxValueCount(settings._maxValueCount),
-      _inSet(false),
-      _options(*options)
+      _inSet(false)
 {
     // If the maximum number of values is not known, storage to
     // caller-allocated memory is unsafe.
index f0218711b5a1de18ba985cfa0efccf21d8ffb1ef..bf0d393a4f7b2e33d776e41e33a744aa7e1552de 100644 (file)
@@ -78,7 +78,7 @@ typedef gmx_unique_ptr<AbstractOptionStorage>::type
  * them.  All error checking and memory management should be postponed to the
  * point when the actual option is created.
  *
- * Subclasses should override createDefaultStorage() to create the correct type
+ * Subclasses should override createStorage() to create the correct type
  * of storage object.
  *
  * \ingroup module_options
@@ -100,12 +100,11 @@ class AbstractOption
         /*! \brief
          * Creates a default storage object for the option.
          *
-         * \param[in]  options  Option collection object.
          * \returns The created storage object.
          * \throws  APIError if invalid option settings have been provided.
          *
-         * This method is called by when creating an option object
-         * The \p options object is used to implement global properties.
+         * This method is called by Options::addOption() when initializing an
+         * option from the settings.
          *
          * Derived classes should implement the method to create an actual
          * storage object and populate it with correct values.
@@ -113,7 +112,7 @@ class AbstractOption
          *
          * Should only be called by Options::addOption().
          */
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const = 0;
+        virtual AbstractOptionStoragePointer createStorage() const = 0;
 
         /*! \brief
          * Creates the description string for the option.
@@ -180,7 +179,7 @@ class AbstractOption
          */
         friend class AbstractOptionStorage;
         /*! \brief
-         * Needed to be able to call createDefaultStorage().
+         * Needed to be able to call createStorage().
          */
         friend class Options;
 };
index 118aa11b31467073aaa589eeb9be1bcacaf8124d..55e46dfe232f1c41af56228c0b9efdbabc6369b4 100644 (file)
@@ -181,13 +181,11 @@ class AbstractOptionStorage
          * Initializes the storage object from the settings object.
          *
          * \param[in] settings  Option settings.
-         * \param[in] options   Option collection that will contain the
-         *      option.
          * \param[in] staticFlags Option flags that are always set and specify
          *      generic behavior of the option.
          * \throws  APIError if invalid settings have been provided.
          */
-        AbstractOptionStorage(const AbstractOption &settings, Options *options,
+        AbstractOptionStorage(const AbstractOption &settings,
                               OptionFlags staticFlags);
 
         //! Returns true if the given flag is set.
@@ -231,11 +229,6 @@ class AbstractOptionStorage
          */
         void setMaxValueCount(int count);
 
-        //! Returns the Options object that houses the option.
-        Options &hostOptions() { return _options; }
-        //! \copydoc hostOptions()
-        const Options &hostOptions() const { return _options; }
-
         /*! \brief
          * Removes all values from temporary storage for a set.
          *
@@ -297,8 +290,6 @@ class AbstractOptionStorage
         int                     _maxValueCount;
         //! Whether we are currently assigning values to a set.
         bool                    _inSet;
-        //! Parent Options object.
-        Options                &_options;
 
         GMX_DISALLOW_COPY_AND_ASSIGN(AbstractOptionStorage);
 };
index f165232e9472e3529ffbd0c7ed0ab89ece2c2297..cc63721f81605787abc425d83b2660fd249a9e9d 100644 (file)
@@ -107,9 +107,9 @@ BooleanOptionInfo::BooleanOptionInfo(BooleanOptionStorage *option)
  * BooleanOption
  */
 
-AbstractOptionStoragePointer BooleanOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer BooleanOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new BooleanOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new BooleanOptionStorage(*this));
 }
 
 
@@ -156,9 +156,9 @@ IntegerOptionInfo::IntegerOptionInfo(IntegerOptionStorage *option)
  * IntegerOption
  */
 
-AbstractOptionStoragePointer IntegerOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer IntegerOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new IntegerOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new IntegerOptionStorage(*this));
 }
 
 
@@ -166,8 +166,8 @@ AbstractOptionStoragePointer IntegerOption::createDefaultStorage(Options *option
  * DoubleOptionStorage
  */
 
-DoubleOptionStorage::DoubleOptionStorage(const DoubleOption &settings, Options *options)
-    : MyBase(settings, options), info_(this), bTime_(settings._bTime), factor_(1.0)
+DoubleOptionStorage::DoubleOptionStorage(const DoubleOption &settings)
+    : MyBase(settings), info_(this), bTime_(settings._bTime), factor_(1.0)
 {
 }
 
@@ -254,9 +254,9 @@ void DoubleOptionInfo::setScaleFactor(double factor)
  * DoubleOption
  */
 
-AbstractOptionStoragePointer DoubleOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer DoubleOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new DoubleOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new DoubleOptionStorage(*this));
 }
 
 
@@ -264,8 +264,8 @@ AbstractOptionStoragePointer DoubleOption::createDefaultStorage(Options *options
  * StringOptionStorage
  */
 
-StringOptionStorage::StringOptionStorage(const StringOption &settings, Options *options)
-    : MyBase(settings, options), _info(this), _enumIndexStore(NULL)
+StringOptionStorage::StringOptionStorage(const StringOption &settings)
+    : MyBase(settings), _info(this), _enumIndexStore(NULL)
 {
     if (settings._defaultEnumIndex >= 0 && settings._enumValues == NULL)
     {
@@ -387,9 +387,9 @@ StringOptionInfo::StringOptionInfo(StringOptionStorage *option)
  * StringOption
  */
 
-AbstractOptionStoragePointer StringOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer StringOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new StringOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new StringOptionStorage(*this));
 }
 
 std::string StringOption::createDescription() const
@@ -416,8 +416,8 @@ std::string StringOption::createDescription() const
  * FileNameOptionStorage
  */
 
-FileNameOptionStorage::FileNameOptionStorage(const FileNameOption &settings, Options *options)
-    : MyBase(settings, options), info_(this), filetype_(settings.filetype_),
+FileNameOptionStorage::FileNameOptionStorage(const FileNameOption &settings)
+    : MyBase(settings), info_(this), filetype_(settings.filetype_),
       bRead_(settings.bRead_), bWrite_(settings.bWrite_),
       bLibrary_(settings.bLibrary_)
 {
@@ -472,9 +472,9 @@ bool FileNameOptionInfo::isLibraryFile() const
  * FileNameOption
  */
 
-AbstractOptionStoragePointer FileNameOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer FileNameOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new FileNameOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new FileNameOptionStorage(*this));
 }
 
 } // namespace gmx
index aaec5d52dc425e84cd7902bf0a8dbf05b2d4d5a7..48b0bbdce4a3aef3b74a08eefb3f1c959d7ff872 100644 (file)
@@ -84,7 +84,7 @@ class BooleanOption : public OptionTemplate<bool, BooleanOption>
 
     private:
         //! Creates a BooleanOptionStorage object.
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
 };
 
 /*! \brief
@@ -123,7 +123,7 @@ class IntegerOption : public OptionTemplate<int, IntegerOption>
 
     private:
         //! Creates an IntegerOptionStorage object.
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
 
         /*! \brief
          * Needed to initialize IntegerOptionStorage from this class without
@@ -165,7 +165,7 @@ class DoubleOption : public OptionTemplate<double, DoubleOption>
 
     private:
         //! Creates a DoubleOptionStorage object.
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
 
         bool _bTime;
 
@@ -252,7 +252,7 @@ class StringOption : public OptionTemplate<std::string, StringOption>
 
     private:
         //! Creates a StringOptionStorage object.
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
         virtual std::string createDescription() const;
 
         const char *const      *_enumValues;
@@ -312,7 +312,7 @@ class FileNameOption : public OptionTemplate<std::string, FileNameOption>
 
     private:
         //! Creates a FileNameOptionStorage object.
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
 
         OptionFileType          filetype_;
         bool                    bRead_;
index c605dd0e01da7017cf5c2854bcf9a31ad53cbaed..c51a650c0a5093171ca6a1a9b1ebedde0aa445e9 100644 (file)
@@ -69,10 +69,9 @@ class BooleanOptionStorage : public OptionStorageTemplate<bool>
          * Initializes the storage from option settings.
          *
          * \param[in] settings   Storage settings.
-         * \param[in] options    Options object.
          */
-        BooleanOptionStorage(const BooleanOption &settings, Options *options)
-            : MyBase(settings, options), info_(this)
+        explicit BooleanOptionStorage(const BooleanOption &settings)
+            : MyBase(settings), info_(this)
         {
         }
 
@@ -93,8 +92,8 @@ class IntegerOptionStorage : public OptionStorageTemplate<int>
 {
     public:
         //! \copydoc BooleanOptionStorage::BooleanOptionStorage()
-        IntegerOptionStorage(const IntegerOption &settings, Options *options)
-            : MyBase(settings, options), info_(this)
+        explicit IntegerOptionStorage(const IntegerOption &settings)
+            : MyBase(settings), info_(this)
         {
         }
 
@@ -117,7 +116,7 @@ class DoubleOptionStorage : public OptionStorageTemplate<double>
 {
     public:
         //! \copydoc IntegerOptionStorage::IntegerOptionStorage()
-        DoubleOptionStorage(const DoubleOption &settings, Options *options);
+        explicit DoubleOptionStorage(const DoubleOption &settings);
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual const char *typeString() const;
@@ -143,7 +142,7 @@ class StringOptionStorage : public OptionStorageTemplate<std::string>
 {
     public:
         //! \copydoc DoubleOptionStorage::DoubleOptionStorage()
-        StringOptionStorage(const StringOption &settings, Options *options);
+        explicit StringOptionStorage(const StringOption &settings);
 
         virtual OptionInfo &optionInfo() { return _info; }
         virtual const char *typeString() const { return _allowed.empty() ? "string" : "enum"; }
@@ -165,7 +164,7 @@ class FileNameOptionStorage : public OptionStorageTemplate<std::string>
 {
     public:
         //! \copydoc StringOptionStorage::StringOptionStorage()
-        FileNameOptionStorage(const FileNameOption &settings, Options *options);
+        explicit FileNameOptionStorage(const FileNameOption &settings);
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual const char *typeString() const { return "file"; }
index d4204d06f065b7e6ddeedd8ff036775f1994dc55..08b9709a538fec9b599ef41e79b5033c8bd7c9ef 100644 (file)
@@ -175,7 +175,7 @@ void Options::addSubSection(Options *section)
 
 void Options::addOption(const AbstractOption &settings)
 {
-    AbstractOptionStoragePointer option(settings.createDefaultStorage(this));
+    AbstractOptionStoragePointer option(settings.createStorage());
     if (_impl->findOption(option->name().c_str()) != NULL)
     {
         GMX_THROW(APIError("Duplicate option: " + option->name()));
index 5b0aa58d4600378a52fcfc21ebd390ceeead8741..4b2a41825cce67449fd1e84d68cc47b6e453345e 100644 (file)
@@ -101,14 +101,12 @@ class OptionStorageTemplate : public AbstractOptionStorage
          * Initializes the storage from option settings.
          *
          * \param[in] settings  Option settings.
-         * \param[in] options   Option collection that will contain the
-         *     option.
          * \param[in] staticFlags Option flags that are always set and specify
          *      generic behavior of the option.
          * \throws  APIError if invalid settings have been provided.
          */
         template <class U>
-        OptionStorageTemplate(const OptionTemplate<T, U> &settings, Options *options,
+        OptionStorageTemplate(const OptionTemplate<T, U> &settings,
                               OptionFlags staticFlags = OptionFlags());
 
 
@@ -249,9 +247,8 @@ class OptionStorageTemplate : public AbstractOptionStorage
 template <typename T>
 template <class U>
 OptionStorageTemplate<T>::OptionStorageTemplate(const OptionTemplate<T, U> &settings,
-                                                Options *options,
                                                 OptionFlags staticFlags)
-    : AbstractOptionStorage(settings, options, staticFlags),
+    : AbstractOptionStorage(settings, staticFlags),
       _values(settings._storeVector),
       _store(settings._store),
       _countptr(settings._countptr)
index ffecbab76f8d0587c314a53fcbf39c32ceed3e58..0c88cfd6c4da1c877384c351faf71a074c920d24 100644 (file)
@@ -71,9 +71,8 @@ class MockOptionStorage : public gmx::OptionStorageTemplate<std::string>
          * Initializes the storage from option settings.
          *
          * \param[in] settings   Storage settings.
-         * \param[in] options    Options object.
          */
-        MockOptionStorage(const MockOption &settings, gmx::Options *options);
+        MockOptionStorage(const MockOption &settings);
 
         /*! \brief
          * Calls addValue("dummy") in the base class.
@@ -133,9 +132,9 @@ class MockOption : public gmx::OptionTemplate<std::string, MockOption>
         { _storagePtr = storagePtr; return me(); }
 
     private:
-        virtual gmx::AbstractOptionStoragePointer createDefaultStorage(gmx::Options *options) const
+        virtual gmx::AbstractOptionStoragePointer createStorage() const
         {
-            MockOptionStorage *storage = new MockOptionStorage(*this, options);
+            MockOptionStorage *storage = new MockOptionStorage(*this);
             if (_storagePtr != NULL)
             {
                 *_storagePtr = storage;
@@ -146,8 +145,8 @@ class MockOption : public gmx::OptionTemplate<std::string, MockOption>
         MockOptionStorage     **_storagePtr;
 };
 
-MockOptionStorage::MockOptionStorage(const MockOption &settings, gmx::Options *options)
-    : MyBase(settings, options)
+MockOptionStorage::MockOptionStorage(const MockOption &settings)
+    : MyBase(settings)
 {
     using ::testing::_;
     using ::testing::Invoke;
index e18e3971693f39d19cb31742cba33176bb123d56..cac7113a1b84c64aecdbff420439d9aa142e0e09 100644 (file)
@@ -59,10 +59,8 @@ namespace gmx
  * SelectionOptionStorage
  */
 
-SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings,
-                                               Options *options)
-    : MyBase(settings, options,
-             OptionFlags() | efNoDefaultValue | efDontCheckMinimumCount),
+SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings)
+    : MyBase(settings, OptionFlags() | efNoDefaultValue | efDontCheckMinimumCount),
       _info(this), _sc(NULL), _selectionFlags(settings._selectionFlags)
 {
     if (settings._infoPtr != NULL)
@@ -250,9 +248,9 @@ void SelectionOptionInfo::setDynamicOnlyWhole(bool bEnabled)
  * SelectionOption
  */
 
-AbstractOptionStoragePointer SelectionOption::createDefaultStorage(Options *options) const
+AbstractOptionStoragePointer SelectionOption::createStorage() const
 {
-    return AbstractOptionStoragePointer(new SelectionOptionStorage(*this, options));
+    return AbstractOptionStoragePointer(new SelectionOptionStorage(*this));
 }
 
 
index 84d2e573ad7cd59364d0b0c4e258649a8842e232..675911d19281dc2e35691b3159bbfaabc2cd8e54 100644 (file)
@@ -115,7 +115,7 @@ class SelectionOption : public OptionTemplate<Selection *, SelectionOption>
         using MyBase::defaultValue;
         using MyBase::defaultValueIfSet;
 
-        virtual AbstractOptionStoragePointer createDefaultStorage(Options *options) const;
+        virtual AbstractOptionStoragePointer createStorage() const;
 
         SelectionFlags          _selectionFlags;
         SelectionOptionInfo   **_infoPtr;
index 30b1fea08459a9e991d6df283fe5054e2d9ebb31..b42284d9dd478eaa2cdd3f2bf97540a178a9e771 100644 (file)
@@ -61,9 +61,8 @@ class SelectionOptionStorage : public OptionStorageTemplate<Selection *>
          * Initializes the storage from option settings.
          *
          * \param[in] settings   Storage settings.
-         * \param[in] options    Options object.
          */
-        SelectionOptionStorage(const SelectionOption &settings, Options *options);
+        SelectionOptionStorage(const SelectionOption &settings);
 
         virtual OptionInfo &optionInfo() { return _info; }
         virtual const char *typeString() const { return "sel"; }