Misc. option fixes.
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 25 Apr 2012 15:19:29 +0000 (18:19 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Thu, 26 Apr 2012 08:30:50 +0000 (11:30 +0300)
- Fix two bugs introduced by earlier refactoring (one-liners in
  optionstoragetemplate.h and cmdlinehelpwriter.cpp).
  Both noticed when starting to work on #666, subsequent commits will
  add tests that failed because of these.
- Added isRequired() to OptionInfo and related classes.
  Needed for IssueID #666, but doing this in a separate commit to reduce
  the footprint of bigger subsequent commits.

Change-Id: Ifee906fe589fd93ff259a02166c41c9b1568439c

src/gromacs/commandline/cmdlinehelpwriter.cpp
src/gromacs/options/abstractoptionstorage.h
src/gromacs/options/optioninfo.h
src/gromacs/options/optionstoragetemplate.h
src/gromacs/options/optionsvisitor.cpp
src/gromacs/selection/selectionoption.cpp

index 21561530eec78cc71185865d27966a14979623bb..74fdc4e0d6ce985536dcb6010a25fef198d35bc5 100644 (file)
@@ -293,7 +293,7 @@ void ParameterWriter::visitOption(const OptionInfo &option)
  */
 
 CommandLineHelpWriter::Impl::Impl(const Options &options)
-    : options_(options)
+    : options_(options), bShowDescriptions_(false), bShowHidden_(false)
 {
 }
 
index 55e46dfe232f1c41af56228c0b9efdbabc6369b4..ae89ba91e9f43a49df5d6d83b37e772b0ac1cb2b 100644 (file)
@@ -96,6 +96,8 @@ class AbstractOptionStorage
         bool isBoolean() const;
         //! Returns true if the option is a hidden option.
         bool isHidden() const { return hasFlag(efHidden); }
+        //! Returns true if the option is required.
+        bool isRequired() const { return hasFlag(efRequired); }
         //! Returns the name of the option.
         const std::string &name() const { return _name; }
         //! Returns the description of the option.
index 8958ba0531840b9ba39d49190b0783fd6ca2825b..f4be835492f92f3998ed83359712f27e21e2b442 100644 (file)
@@ -104,6 +104,8 @@ class OptionInfo
         bool isSet() const;
         //! Returns true if the option is a hidden option.
         bool isHidden() const;
+        //! Returns true if the option is required.
+        bool isRequired() const;
         //! Returns the name of the option.
         const std::string &name() const;
         //! Returns the description of the option.
index f97397818916e2bb6d87df1fc6f83ebc09bcf9b4..a6dd8c455cacd6a6a7ee25a626c478cee9a52f96 100644 (file)
@@ -285,7 +285,7 @@ OptionStorageTemplate<T>::OptionStorageTemplate(const OptionTemplate<T, U> &sett
             // TODO: This is a bit hairy, as it indirectly calls a virtual function.
             commitValues();
         }
-        else if (_ownedValues.get() == NULL && _store != NULL)
+        else if (_ownedValues.get() != NULL && _store != NULL)
         {
             _values->clear();
             int count = (settings.isVector() ?
index 7dc0429c002af687d8cdc90bc9dde0314c9c154b..69c1b7bb68d55f103f76d0d012820ee335ece279 100644 (file)
@@ -71,6 +71,11 @@ bool OptionInfo::isHidden() const
     return _option.isHidden();
 }
 
+bool OptionInfo::isRequired() const
+{
+    return _option.isRequired();
+}
+
 const std::string &OptionInfo::name() const
 {
     return _option.name();
index 056e8795ce74396a68cda37dc326076a24ff7a15..78d3794c997e821e11f34edd17bbdde356766b0d 100644 (file)
@@ -131,7 +131,7 @@ void SelectionOptionStorage::processSetValues(ValueList *values)
 
 void SelectionOptionStorage::processAll()
 {
-    if ((hasFlag(efRequired) || hasFlag(efSet)) && valueCount() == 0)
+    if ((isRequired() || isSet()) && valueCount() == 0)
     {
         GMX_RELEASE_ASSERT(_sc != NULL, "Selection collection is not set");