Clean up option and selection flags.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 9 Jun 2012 11:09:37 +0000 (14:09 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Wed, 20 Jun 2012 17:52:53 +0000 (20:52 +0300)
Rename the enums used for flags such that they are more likely unique.
Also a bit of other clean-up to limit the use of the option flags more
into the generic parts.  Removed a few unnecessary flags.  Made
efClearOnNextSet work more correctly for classes that don't use
OptionStorageTemplate, although currently it didn't cause any issues
(noticed some issues while developing SelectionFileOption, but the final
version worked without these fixes).

Change-Id: I78c243c4f73b87b285eb54d6ff3ae42699678962

13 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/basicoptionstorage.h
src/gromacs/options/optionflags.h
src/gromacs/options/optionstoragetemplate.h
src/gromacs/options/tests/abstractoptionstorage.cpp
src/gromacs/selection/compiler.cpp
src/gromacs/selection/selection.cpp
src/gromacs/selection/selectionenums.h
src/gromacs/selection/selectionoption.cpp
src/gromacs/selection/selectionoption.h

index 4f37892c3bc3553328aff1e320fa65425941469b..7522211f47cc52a962eab317418ff86f64a4306a 100644 (file)
@@ -59,14 +59,8 @@ AbstractOptionStorage::AbstractOptionStorage(const AbstractOption &settings,
       maxValueCount_(settings.maxValueCount_),
       inSet_(false)
 {
-    // If the maximum number of values is not known, storage to
-    // caller-allocated memory is unsafe.
-    if ((maxValueCount_ < 0 || hasFlag(efMulti)) && hasFlag(efExternalStore))
-    {
-        GMX_THROW(APIError("Cannot set user-allocated storage for arbitrary number of values"));
-    }
     // Check that user has not provided incorrect values for vectors.
-    if (hasFlag(efVector) && (minValueCount_ > 1 || maxValueCount_ < 1))
+    if (hasFlag(efOption_Vector) && (minValueCount_ > 1 || maxValueCount_ < 1))
     {
         GMX_THROW(APIError("Inconsistent value counts for vector values"));
     }
@@ -76,6 +70,7 @@ AbstractOptionStorage::AbstractOptionStorage(const AbstractOption &settings,
         name_  = settings.name_;
     }
     descr_ = settings.createDescription();
+    setFlag(efOption_ClearOnNextSet);
 }
 
 AbstractOptionStorage::~AbstractOptionStorage()
@@ -89,7 +84,7 @@ bool AbstractOptionStorage::isBoolean() const
 
 void AbstractOptionStorage::startSource()
 {
-    setFlag(efClearOnNextSet);
+    setFlag(efOption_ClearOnNextSet);
 }
 
 void AbstractOptionStorage::startSet()
@@ -98,7 +93,8 @@ void AbstractOptionStorage::startSet()
     // The last condition takes care of the situation where multiple
     // sources are used, and a later source should be able to reassign
     // the value even though the option is already set.
-    if (isSet() && !hasFlag(efMulti) && !hasFlag(efClearOnNextSet))
+    if (isSet() && !hasFlag(efOption_MultipleTimes)
+        && !hasFlag(efOption_ClearOnNextSet))
     {
         GMX_THROW(InvalidInputError("Option specified multiple times"));
     }
@@ -116,16 +112,21 @@ void AbstractOptionStorage::finishSet()
 {
     GMX_RELEASE_ASSERT(inSet_, "startSet() not called");
     inSet_ = false;
-    // TODO: Should this be done only when processSet() does not throw?
-    setFlag(efSet);
+    // TODO: Should this be set or not when processSet() throws?
+    setFlag(efOption_Set);
+    // TODO: Correct handling of the efOption_ClearOnNextSet requires
+    // processSet() and/or convertValue() to check it internally.
+    // OptionStorageTemplate takes care of it, but it's error-prone if
+    // a custom option is implemented that doesn't use it.
     processSet();
+    clearFlag(efOption_ClearOnNextSet);
 }
 
 void AbstractOptionStorage::finish()
 {
     GMX_RELEASE_ASSERT(!inSet_, "finishSet() not called");
     processAll();
-    if (hasFlag(efRequired) && !isSet())
+    if (isRequired() && !isSet())
     {
         GMX_THROW(InvalidInputError("Option is required, but not set"));
     }
@@ -133,12 +134,12 @@ void AbstractOptionStorage::finish()
 
 void AbstractOptionStorage::setMinValueCount(int count)
 {
-    GMX_RELEASE_ASSERT(!hasFlag(efMulti),
-                       "setMinValueCount() not supported with efMulti");
+    GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
+                       "setMinValueCount() not supported with efOption_MultipleTimes");
     GMX_RELEASE_ASSERT(count >= 0, "Invalid value count");
     minValueCount_ = count;
-    if (isSet()
-        && !hasFlag(efDontCheckMinimumCount) && valueCount() < minValueCount_)
+    if (isSet() && !hasFlag(efOption_DontCheckMinimumCount)
+        && valueCount() < minValueCount_)
     {
         GMX_THROW(InvalidInputError("Too few values"));
     }
@@ -146,8 +147,8 @@ void AbstractOptionStorage::setMinValueCount(int count)
 
 void AbstractOptionStorage::setMaxValueCount(int count)
 {
-    GMX_RELEASE_ASSERT(!hasFlag(efMulti),
-                       "setMaxValueCount() not supported with efMulti");
+    GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
+                       "setMaxValueCount() not supported with efOption_MultipleTimes");
     GMX_RELEASE_ASSERT(count >= -1, "Invalid value count");
     maxValueCount_ = count;
     if (isSet() && maxValueCount_ >= 0 && valueCount() > maxValueCount_)
index 2c165a9f8e207d2423738aae76ccd8b5af2816dc..9658e83986bc1bc8e13cdef0afa3ca21bb675edb 100644 (file)
@@ -137,11 +137,24 @@ class AbstractOption
         //! Sets or clears a flag for the option.
         void setFlag(OptionFlag flag, bool bSet) { flags_.set(flag, bSet); }
         //! Returns true if the option is vector-valued.
-        bool isVector() const { return hasFlag(efVector); }
-        //! Sets the option to be vector-valued.
+        bool isVector() const { return hasFlag(efOption_Vector); }
+        /*! \brief
+         * Sets the option to be vector-valued.
+         *
+         * This method is provided for convenience to make management of value
+         * counts easier.  In order to implement a vector-valued option, the
+         * class derived from AbstractOption should expose a method that calls
+         * this method, and the storage object derived from
+         * AbstractOptionStorage should check isVector().
+         * If only a single value is provided, the storage object should fill
+         * the whole vector with that value.
+         *
+         * The length of the vector (the value of maxValueCount_) must be
+         * fixed.  The default length is 3 elements.
+         */
         void setVector()
         {
-            setFlag(efVector);
+            setFlag(efOption_Vector);
             minValueCount_ = 1;
             if (maxValueCount_ == 1)
             {
@@ -151,7 +164,7 @@ class AbstractOption
         //! Sets the required number of values for the option.
         void setValueCount(int count)
         {
-            if (!hasFlag(efVector))
+            if (!hasFlag(efOption_Vector))
             {
                 minValueCount_ = count;
             }
@@ -225,13 +238,13 @@ class OptionTemplate : public AbstractOption
         { setDescription(descr); return me(); }
         //! Hides the option from normal help output.
         MyClass &hidden(bool bHidden = true)
-        { setFlag(efHidden, bHidden); return me(); }
+        { setFlag(efOption_Hidden, bHidden); return me(); }
         //! Requires the option to be specified explicitly.
         MyClass &required(bool bRequired = true)
-        { setFlag(efRequired, bRequired); return me(); }
+        { setFlag(efOption_Required, bRequired); return me(); }
         //! Allows the option to be specified multiple times.
         MyClass &allowMultiple(bool bMulti = true)
-        { setFlag(efMulti, bMulti); return me(); }
+        { setFlag(efOption_MultipleTimes, bMulti); return me(); }
         //! Requires exactly \p count values for the option.
         MyClass &valueCount(int count) { setValueCount(count); return me(); }
         //! Allows any number of values for the option.
@@ -284,7 +297,7 @@ class OptionTemplate : public AbstractOption
          * Options object exists.
          */
         MyClass &store(T *store)
-        { setFlag(efExternalStore); store_ = store; return me(); }
+        { store_ = store; return me(); }
         /*! \brief
          * Stores number of values in the value pointed by \p countptr.
          *
@@ -312,7 +325,7 @@ class OptionTemplate : public AbstractOption
          * Options object exists.
          */
         MyClass &storeVector(std::vector<T> *store)
-        { setFlag(efExternalValueVector); storeVector_ = store; return me(); }
+        { storeVector_ = store; return me(); }
 
     protected:
         /*! \cond libapi */
index 5c102b5a83a0b34f76febe504e2e8b0d3baa7f76..6f8a7c023b5aefb46ea6aaeb46d1801612e6dda5 100644 (file)
@@ -85,7 +85,7 @@ class AbstractOptionStorage
         virtual ~AbstractOptionStorage();
 
         //! Returns true if the option has been set.
-        bool isSet() const { return hasFlag(efSet); }
+        bool isSet() const { return hasFlag(efOption_Set); }
         /*! \brief
          * Returns true if the option is a boolean option.
          *
@@ -95,9 +95,11 @@ class AbstractOptionStorage
          */
         bool isBoolean() const;
         //! Returns true if the option is a hidden option.
-        bool isHidden() const { return hasFlag(efHidden); }
+        bool isHidden() const { return hasFlag(efOption_Hidden); }
         //! Returns true if the option is required.
-        bool isRequired() const { return hasFlag(efRequired); }
+        bool isRequired() const { return hasFlag(efOption_Required); }
+        //! Returns true if the option is vector-valued.
+        bool isVector() const { return hasFlag(efOption_Vector); }
         //! Returns the name of the option.
         const std::string &name() const { return name_; }
         //! Returns the description of the option.
@@ -199,6 +201,8 @@ class AbstractOptionStorage
         AbstractOptionStorage(const AbstractOption &settings,
                               OptionFlags staticFlags);
 
+        //! Marks the option as set.
+        void markAsSet() { flags_.set(efOption_Set); }
         //! Returns true if the given flag is set.
         bool hasFlag(OptionFlag flag) const { return flags_.test(flag); }
         //! Sets the given flag.
@@ -219,8 +223,9 @@ class AbstractOptionStorage
          * If values have already been provided, it is checked that there are
          * enough.
          *
-         * Cannot be called for options with ::efMulti set, because it is
-         * impossible to check the requirement after the values have been set.
+         * Cannot be called for options with ::efOption_MultipleTimes set,
+         * because it is impossible to check the requirement after the values
+         * have been set.
          * If attempted, will assert.
          */
         void setMinValueCount(int count);
@@ -234,8 +239,9 @@ class AbstractOptionStorage
          * If values have already been provided, it is checked that there are
          * not too many.
          *
-         * Cannot be called for options with ::efMulti set, because it is
-         * impossible to check the requirement after the values have been set.
+         * Cannot be called for options with ::efOption_MultipleTimes set,
+         * because it is impossible to check the requirement after the values
+         * have been set.
          * If attempted, will assert.
          */
         void setMaxValueCount(int count);
index 42238819d37bbc5aac0bc564c5de8d640cb5f388..38e47b89ec30d119e0596f976952e42ca1e41205 100644 (file)
@@ -135,7 +135,7 @@ void IntegerOptionStorage::convertValue(const std::string &value)
 
 void IntegerOptionStorage::processSetValues(ValueList *values)
 {
-    if (hasFlag(efVector))
+    if (isVector())
     {
         expandVector(maxValueCount(), values);
     }
@@ -171,7 +171,7 @@ DoubleOptionStorage::DoubleOptionStorage(const DoubleOption &settings)
 
 const char *DoubleOptionStorage::typeString() const
 {
-    return hasFlag(efVector) ? "vector" : (isTime() ? "time" : "double");
+    return isVector() ? "vector" : (isTime() ? "time" : "double");
 }
 
 std::string DoubleOptionStorage::formatSingleValue(const double &value) const
@@ -193,7 +193,7 @@ void DoubleOptionStorage::convertValue(const std::string &value)
 
 void DoubleOptionStorage::processSetValues(ValueList *values)
 {
-    if (hasFlag(efVector))
+    if (isVector())
     {
         expandVector(maxValueCount(), values);
     }
@@ -206,7 +206,7 @@ void DoubleOptionStorage::processAll()
 void DoubleOptionStorage::setScaleFactor(double factor)
 {
     GMX_RELEASE_ASSERT(factor > 0.0, "Invalid scaling factor");
-    if (!hasFlag(efHasDefaultValue))
+    if (!hasFlag(efOption_HasDefaultValue))
     {
         double scale = factor / factor_;
         ValueList::iterator i;
index 6f96b008d88c7edbf9d5fac06b47d4e18c238341..8438135f5bfa1a7aa23c2540ee06e54ede91991b 100644 (file)
@@ -97,7 +97,7 @@ class IntegerOptionStorage : public OptionStorageTemplate<int>
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual const char *typeString() const
-        { return hasFlag(efVector) ? "vector" : "int"; }
+        { return isVector() ? "vector" : "int"; }
         virtual std::string formatSingleValue(const int &value) const;
 
     private:
index 7de2de50e757481cc4a095e2b824d071be55bfa0..77fe03ee06b54cff6976891020125be73e9a6fd2 100644 (file)
@@ -57,34 +57,30 @@ namespace gmx
 enum OptionFlag
 {
     //! %Option has been set.
-    efSet                 = 1<<0,
+    efOption_Set                        = 1<<0,
     //! The current value of the option is a programmatic default value.
-    efHasDefaultValue     = 1<<1,
+    efOption_HasDefaultValue            = 1<<1,
     /*! \brief
      * Next assignment to the option clears old values.
      *
      * This flag is set when a new option source starts, such that values
      * from the new source will overwrite old ones.
      */
-    efClearOnNextSet      = 1<<5,
+    efOption_ClearOnNextSet             = 1<<2,
     //! %Option is required to be set.
-    efRequired            = 1<<2,
+    efOption_Required                   = 1<<4,
     //! %Option can be specified multiple times.
-    efMulti               = 1<<3,
+    efOption_MultipleTimes              = 1<<5,
     //! %Option is hidden from standard help.
-    efHidden              = 1<<4,
+    efOption_Hidden                     = 1<<6,
     /*! \brief
      * %Option value is a vector, but a single value is also accepted.
      *
-     * If only a single value is provided, the storage object should fill the
-     * whole vector with that value.  The length of the vector must be fixed.
-     * The default length is 3 elements.
+     * \see AbstractOption::setVector()
      */
-    efVector              = 1<<6,
-    efExternalStore       = 1<<8,
-    efExternalValueVector = 1<<10,
+    efOption_Vector                     = 1<<8,
     //! %Option does not support default values.
-    efNoDefaultValue      = 1<<7,
+    efOption_NoDefaultValue             = 1<<9,
     /*! \brief
      * Storage object does its custom checking for minimum value count.
      *
@@ -94,13 +90,7 @@ enum OptionFlag
      * This is useful to override the default check, which is done in
      * OptionStorageTemplate::processSet().
      */
-    efDontCheckMinimumCount     = 1<<16,
-    //efDynamic             = 1<<16,
-    //efRanges              = 1<<17,
-    //efEnum                = 1<<18,
-    //efStaticEnum          = 1<<19,
-    //efVarNum              = 1<<20,
-    //efAtomVal             = 1<<21,
+    efOption_DontCheckMinimumCount      = 1<<10
 };
 
 //! \libinternal Holds a combination of ::OptionFlag values.
index 5b083d148508f3c347e5d61e766218cdd9373ea0..87299b8d5be265ec8e27ddd8641ea1e799df3531 100644 (file)
@@ -113,8 +113,8 @@ class OptionStorageTemplate : public AbstractOptionStorage
          * \throws  APIError if invalid settings have been provided.
          */
         template <class U>
-        OptionStorageTemplate(const OptionTemplate<T, U> &settings,
-                              OptionFlags staticFlags = OptionFlags());
+        explicit OptionStorageTemplate(const OptionTemplate<T, U> &settings,
+                                       OptionFlags staticFlags = OptionFlags());
 
 
         virtual void clearSet();
@@ -273,28 +273,31 @@ OptionStorageTemplate<T>::OptionStorageTemplate(const OptionTemplate<T, U> &sett
       store_(settings.store_),
       countptr_(settings.countptr_)
 {
+    // If the maximum number of values is not known, storage to
+    // caller-allocated memory is unsafe.
+    if (store_ != NULL && (maxValueCount() < 0 || hasFlag(efOption_MultipleTimes)))
+    {
+        GMX_THROW(APIError("Cannot set user-allocated storage for arbitrary number of values"));
+    }
     if (values_ == NULL)
     {
-        // The flag should be set for proper error checking.
-        GMX_RELEASE_ASSERT(!hasFlag(efExternalValueVector),
-                           "Internal inconsistency");
         ownedValues_.reset(new std::vector<T>);
         values_ = ownedValues_.get();
     }
-    if (hasFlag(efNoDefaultValue)
+    if (hasFlag(efOption_NoDefaultValue)
         && (settings.defaultValue_ != NULL
             || settings.defaultValueIfSet_ != NULL))
     {
         GMX_THROW(APIError("Option does not support default value, but one is set"));
     }
-    if (store_ != NULL && countptr_ == NULL && !hasFlag(efVector)
+    if (store_ != NULL && countptr_ == NULL && !isVector()
         && minValueCount() != maxValueCount())
     {
         GMX_THROW(APIError("Count storage is not set, although the number of produced values is not known"));
     }
-    if (!hasFlag(efNoDefaultValue))
+    if (!hasFlag(efOption_NoDefaultValue))
     {
-        setFlag(efHasDefaultValue);
+        setFlag(efOption_HasDefaultValue);
         if (settings.defaultValue_ != NULL)
         {
             values_->clear();
@@ -314,14 +317,13 @@ OptionStorageTemplate<T>::OptionStorageTemplate(const OptionTemplate<T, U> &sett
         }
         if (settings.defaultValueIfSet_ != NULL)
         {
-            if (hasFlag(efMulti))
+            if (hasFlag(efOption_MultipleTimes))
             {
                 GMX_THROW(APIError("defaultValueIfSet() is not supported with allowMultiple()"));
             }
             defaultValueIfSet_.reset(new T(*settings.defaultValueIfSet_));
         }
     }
-    setFlag(efClearOnNextSet);
 }
 
 
@@ -362,16 +364,15 @@ void OptionStorageTemplate<T>::processSet()
     if (setValues_.empty() && defaultValueIfSet_.get() != NULL)
     {
         addValue(*defaultValueIfSet_);
-        setFlag(efHasDefaultValue);
+        setFlag(efOption_HasDefaultValue);
     }
     else
     {
-        clearFlag(efHasDefaultValue);
+        clearFlag(efOption_HasDefaultValue);
     }
-    if (!hasFlag(efDontCheckMinimumCount)
+    if (!hasFlag(efOption_DontCheckMinimumCount)
         && setValues_.size() < static_cast<size_t>(minValueCount()))
     {
-        clearSet();
         GMX_THROW(InvalidInputError("Too few (valid) values"));
     }
     commitValues();
@@ -393,10 +394,9 @@ void OptionStorageTemplate<T>::addValue(const T &value)
 template <typename T>
 void OptionStorageTemplate<T>::commitValues()
 {
-    if (hasFlag(efClearOnNextSet))
+    if (hasFlag(efOption_ClearOnNextSet))
     {
         values_->swap(setValues_);
-        clearFlag(efClearOnNextSet);
     }
     else
     {
index 33d997f2eda6d3a1e18654b0479945ac1f82e8a1..d1b0595c9e118d158922588a94e24cb4f5e6b0ac 100644 (file)
@@ -81,16 +81,14 @@ class MockOptionStorage : public gmx::OptionStorageTemplate<std::string>
         {
             addValue("dummy");
         }
-        /*! \brief
-         * Calls setFlag(efSet).
-         */
-        void setOption()
-        {
-            setFlag(gmx::efSet);
-        }
+        // using MyBase::markAsSet;
         // using MyBase::addValue;
         // using MyBase::commitValues;
         // "using" is correct but MSVC gives error C2248. Workaround:
+        void markAsSet()
+        {
+            MyBase::markAsSet();
+        }
         void addValue(const std::string &value)
         {
             MyBase::addValue(value);
@@ -176,7 +174,7 @@ TEST(AbstractOptionStorageTest, HandlesSetInFinish)
         using ::testing::DoAll;
         using ::testing::InvokeWithoutArgs;
         EXPECT_CALL(*mock, processAll())
-            .WillOnce(DoAll(InvokeWithoutArgs(mock, &MockOptionStorage::setOption),
+            .WillOnce(DoAll(InvokeWithoutArgs(mock, &MockOptionStorage::markAsSet),
                             InvokeWithoutArgs(mock, &MockOptionStorage::addDummyValue),
                             InvokeWithoutArgs(mock, &MockOptionStorage::commitValues)));
     }
index 123858748b1fe3d3bb88d6d02ae9accafaedb24c..40145eda346e8c0fec747b7742828052ec43db1a 100644 (file)
@@ -568,15 +568,15 @@ init_pos_keyword_defaults(t_selelem *root, const char *spost, const char *rpost,
         int flags = bSelection ? POS_COMPLMAX : POS_COMPLWHOLE;
         if (bSelection)
         {
-            if (sel->hasFlag(gmx::efDynamicMask))
+            if (sel->hasFlag(gmx::efSelection_DynamicMask))
             {
                 flags |= POS_MASKONLY;
             }
-            if (sel->hasFlag(gmx::efEvaluateVelocities))
+            if (sel->hasFlag(gmx::efSelection_EvaluateVelocities))
             {
                 flags |= POS_VELOCITIES;
             }
-            if (sel->hasFlag(gmx::efEvaluateForces))
+            if (sel->hasFlag(gmx::efSelection_EvaluateForces))
             {
                 flags |= POS_FORCES;
             }
index 54427cb5c2a842dd299ef21251a97d00976ae3bd..d8a91583c41121200fb085e2d10bc997b1181046 100644 (file)
@@ -148,7 +148,7 @@ SelectionData::initializeMassesAndCharges(const t_topology *top)
         }
         posInfo_.push_back(PositionInfo(mass, charge));
     }
-    if (isDynamic() && !hasFlag(efDynamicMask))
+    if (isDynamic() && !hasFlag(efSelection_DynamicMask))
     {
         originalPosInfo_ = posInfo_;
     }
@@ -200,7 +200,7 @@ SelectionData::restoreOriginalPositions()
         gmx_ana_pos_t &p = rawPositions_;
         gmx_ana_index_copy(p.g, rootElement_->v.u.g, false);
         p.g->name = NULL;
-        gmx_ana_indexmap_update(&p.m, p.g, hasFlag(gmx::efDynamicMask));
+        gmx_ana_indexmap_update(&p.m, p.g, hasFlag(gmx::efSelection_DynamicMask));
         p.nr = p.m.nr;
         refreshMassesAndCharges();
     }
index 4ef8ca5f9ea9cfcb43488f913cdf464b1b2b8dfd..9a5fb32937d933f2623d25bb1b31c657cf6bf25d 100644 (file)
@@ -63,15 +63,15 @@ namespace gmx
  */
 enum SelectionFlag
 {
-    efOnlyStatic        = 1<<0,
-    efOnlyAtoms         = 1<<1,
+    efSelection_OnlyStatic              = 1<<0,
+    efSelection_OnlyAtoms               = 1<<1,
     //! Whether ::POS_MASKONLY should be used for output position evaluation.
-    efDynamicMask       = 1<<2,
-    efDynamicOnlyWhole  = 1<<3,
+    efSelection_DynamicMask             = 1<<2,
+    efSelection_DynamicOnlyWhole        = 1<<3,
     //! Whether velocities of output positions should be evaluated.
-    efEvaluateVelocities        = 1<<5,
+    efSelection_EvaluateVelocities      = 1<<5,
     //! Whether forces on output positions should be evaluated.
-    efEvaluateForces            = 1<<6,
+    efSelection_EvaluateForces          = 1<<6,
 };
 
 //! \internal Holds a collection of ::SelectionFlag values.
index 86bdf19a2c787ffbdfab2f1f2ee3d55bedb0dfa9..97570aeff6fbeab8e918cba084d99b9600349f92 100644 (file)
@@ -60,10 +60,11 @@ namespace gmx
  */
 
 SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings)
-    : MyBase(settings, OptionFlags() | efNoDefaultValue | efDontCheckMinimumCount),
+    : MyBase(settings, OptionFlags() | efOption_NoDefaultValue
+                           | efOption_DontCheckMinimumCount),
       info_(this), manager_(NULL), selectionFlags_(settings.selectionFlags_)
 {
-    GMX_RELEASE_ASSERT(!hasFlag(efMulti),
+    GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
                        "allowMultiple() is not supported for selection options");
     if (settings.infoPtr_ != NULL)
     {
@@ -107,7 +108,7 @@ void SelectionOptionStorage::addSelections(
     {
         // TODO: Having this check in the parser would make interactive input
         // behave better.
-        if (selectionFlags_.test(efOnlyStatic) && i->isDynamic())
+        if (selectionFlags_.test(efSelection_OnlyStatic) && i->isDynamic())
         {
             GMX_THROW(InvalidInputError("Dynamic selections not supported"));
         }
@@ -116,7 +117,7 @@ void SelectionOptionStorage::addSelections(
     if (bFullValue)
     {
         commitValues();
-        setFlag(efSet);
+        markAsSet();
     }
 }
 
@@ -154,7 +155,7 @@ void SelectionOptionStorage::processAll()
         GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
 
         manager_->requestOptionDelayedParsing(this);
-        setFlag(efSet);
+        markAsSet();
     }
 }
 
@@ -165,7 +166,7 @@ void SelectionOptionStorage::setAllowedValueCount(int count)
     errors.startContext("In option '" + name() + "'");
     if (count >= 0)
     {
-        // Should not throw because efDontCheckMinimumCount is set
+        // Should not throw because efOption_DontCheckMinimumCount is set.
         setMinValueCount(count);
         if (valueCount() > 0 && valueCount() < count)
         {
@@ -192,7 +193,7 @@ void SelectionOptionStorage::setSelectionFlag(SelectionFlag flag, bool bSet)
     ValueList::iterator i;
     for (i = values().begin(); i != values().end(); ++i)
     {
-        if (flag == efOnlyStatic && bSet && i->isDynamic())
+        if (flag == efSelection_OnlyStatic && bSet && i->isDynamic())
         {
             MessageStringCollector errors;
             errors.startContext("In option '" + name() + "'");
@@ -240,32 +241,32 @@ void SelectionOptionInfo::setValueCount(int count)
 
 void SelectionOptionInfo::setEvaluateVelocities(bool bEnabled)
 {
-    option().setSelectionFlag(efEvaluateVelocities, bEnabled);
+    option().setSelectionFlag(efSelection_EvaluateVelocities, bEnabled);
 }
 
 void SelectionOptionInfo::setEvaluateForces(bool bEnabled)
 {
-    option().setSelectionFlag(efEvaluateForces, bEnabled);
+    option().setSelectionFlag(efSelection_EvaluateForces, bEnabled);
 }
 
 void SelectionOptionInfo::setOnlyAtoms(bool bEnabled)
 {
-    option().setSelectionFlag(efOnlyAtoms, bEnabled);
+    option().setSelectionFlag(efSelection_OnlyAtoms, bEnabled);
 }
 
 void SelectionOptionInfo::setOnlyStatic(bool bEnabled)
 {
-    option().setSelectionFlag(efOnlyStatic, bEnabled);
+    option().setSelectionFlag(efSelection_OnlyStatic, bEnabled);
 }
 
 void SelectionOptionInfo::setDynamicMask(bool bEnabled)
 {
-    option().setSelectionFlag(efDynamicMask, bEnabled);
+    option().setSelectionFlag(efSelection_DynamicMask, bEnabled);
 }
 
 void SelectionOptionInfo::setDynamicOnlyWhole(bool bEnabled)
 {
-    option().setSelectionFlag(efDynamicOnlyWhole, bEnabled);
+    option().setSelectionFlag(efSelection_DynamicOnlyWhole, bEnabled);
 }
 
 
@@ -284,7 +285,8 @@ AbstractOptionStoragePointer SelectionOption::createStorage() const
  */
 
 SelectionFileOptionStorage::SelectionFileOptionStorage(const SelectionFileOption &settings)
-    : AbstractOptionStorage(settings, OptionFlags() | efMulti | efDontCheckMinimumCount),
+    : AbstractOptionStorage(settings, OptionFlags() | efOption_MultipleTimes
+                                          | efOption_DontCheckMinimumCount),
       info_(this), manager_(NULL), bValueParsed_(false)
 {
 }
index f3b60a71afa8f60ebdbbaf3729be6c06a87587a6..b02d082dc38052a8db617f0026e870416cdb64f2 100644 (file)
@@ -72,7 +72,7 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
          * in which case SelectionPosition::hasVelocity() returns false.
          */
         MyClass &evaluateVelocities()
-        { selectionFlags_.set(efEvaluateVelocities); return me(); }
+        { selectionFlags_.set(efSelection_EvaluateVelocities); return me(); }
         /*! \brief
          * Request force evaluation for output positions.
          *
@@ -80,19 +80,19 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
          * in which case SelectionPosition::hasForce() returns false.
          */
         MyClass &evaluateForces()
-        { selectionFlags_.set(efEvaluateForces); return me(); }
+        { selectionFlags_.set(efSelection_EvaluateForces); return me(); }
         /*! \brief
          * Only accept selections that evaluate to atom positions.
          *
          * TODO: This option is not yet implemented.
          */
         MyClass &onlyAtoms()
-        { selectionFlags_.set(efOnlyAtoms); return me(); }
+        { selectionFlags_.set(efSelection_OnlyAtoms); return me(); }
         /*! \brief
          * Only accept static selections for this option.
          */
         MyClass &onlyStatic()
-        { selectionFlags_.set(efOnlyStatic); return me(); }
+        { selectionFlags_.set(efSelection_OnlyStatic); return me(); }
         /*! \brief
          * Handle dynamic selections for this option with position masks.
          *
@@ -100,14 +100,14 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
          * \see SelectionPosition::selected()
          */
         MyClass &dynamicMask()
-        { selectionFlags_.set(efDynamicMask); return me(); }
+        { selectionFlags_.set(efSelection_DynamicMask); return me(); }
         /*! \brief
          * Disallow using atom coordinates as the reference positions.
          *
          * TODO: This option is not yet implemented.
          */
         MyClass &dynamicOnlyWhole()
-        { selectionFlags_.set(efDynamicOnlyWhole); return me(); }
+        { selectionFlags_.set(efSelection_DynamicOnlyWhole); return me(); }
 
         /*! \brief
          * Get an info object that can be used to alter the option after