Simplify Options::setDescription() usage
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 2 Feb 2014 06:22:52 +0000 (08:22 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 2 Feb 2014 16:12:37 +0000 (17:12 +0100)
Remove the need for all tools to call concatenateStrings() to pass the
description to Options::setDescription().  In addition to marginally
simplifying the calling code, this allows more elaborate processing of
the input array to fix issues that there currently are, e.g., with
descriptions that include significant leading spaces in the input
strings.  Not done in this change, though.

Change-Id: Ibe295d5e578222c43f01c1248989d119aa60f0bd

share/template/template.cpp
src/gromacs/options/options.cpp
src/gromacs/options/options.h
src/gromacs/trajectoryanalysis.h
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/tests/test_selection.cpp

index 9c568c9c454a5704373a8371e14ec1245de901f5..fe925a88b3b4f04e77d4100f683966c4df765b45 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,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.
@@ -101,7 +101,7 @@ AnalysisTemplate::initOptions(Options                    *options,
         "analysis groups."
     };
 
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     options->addOption(FileNameOption("o")
                            .filetype(eftPlot).outputFile()
index 2729d3f565a1418d66372cad5f9ac928b82b0b64..8b3c22e2646ec3970f1bff7054c397d1c187d1e9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * 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.
@@ -43,6 +43,7 @@
 
 #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"
@@ -142,6 +143,11 @@ void Options::setDescription(const std::string &desc)
     impl_->description_ = desc;
 }
 
+void Options::setDescription(const ConstArrayRef<const char *> &descArray)
+{
+    impl_->description_ = concatenateStrings(descArray.data(), descArray.size());
+}
+
 void Options::addSubSection(Options *section)
 {
     // Make sure that section is not already inserted somewhere.
index ad9517f2ea1c754db7675b784f1baf993f1888fd..cd5f1dc7b012c1cc5da47db40b596c08214c0aa2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * 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.
@@ -56,6 +56,8 @@
 namespace gmx
 {
 
+template <typename T> class ConstArrayRef;
+
 class AbstractOption;
 class OptionsAssigner;
 class OptionsIterator;
@@ -79,7 +81,7 @@ class OptionsIterator;
    options.addOption(StringOption("arg1").store(&arg1));
    options.addOption(IntegerOption("arg2").store(&arg2));
    return &options;
* \endcode
  \endcode
  * The caller of that method can then use a parser implementation such as
  * CommandLineParser to provide values for the options.
  *
@@ -122,10 +124,33 @@ class Options
          *
          * \param[in] desc  String to set as the description.
          *
-         * concatenateStrings() is useful for forming the input string.
+         * This overload is mainly useful if the description is very short.
+         * Currently this is mostly the case in unit testing.
          */
         void setDescription(const std::string &desc);
-        //int addBugs(int nbugs, const char *const *bugs);
+        /*! \brief
+         * Sets the full description of the option collection from string array.
+         *
+         * \param[in] descArray  String array to set as the description.
+         *
+         * All strings in `descArray` are concatenated to form the description.
+         * Spaces are inserted between strings if they are missing.
+         *
+         * Example usage:
+         * \code
+           const char *const desc[] = {
+               "This is the description",
+               "for the options"
+           };
+
+           gmx::Options options(NULL, NULL);
+           options.setDescription(desc);
+           \endcode
+         *
+         * To use this overload, you must also include
+         * `gromacs/utility/arrayref.h`.
+         */
+        void setDescription(const ConstArrayRef<const char *> &descArray);
 
         /*! \brief
          * Adds an option collection as a subsection of this collection.
index 3864f5dff8907ddf5af6faf09a8d144480d9c29f..2942a303a8ce7da30a95fdc6053af6ab19d957d7 100644 (file)
 #include "trajectoryanalysis/analysismodule.h"
 #include "trajectoryanalysis/analysissettings.h"
 #include "trajectoryanalysis/cmdlinerunner.h"
+#include "utility/arrayref.h"
 #include "utility/exceptions.h"
-#include "utility/stringutil.h"
 
 #endif
index 9f9e23e0a4a2acdd23b054823e0541941fd82142..25f8346dad0be3c013056b11b78c0857dfd6fd81 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,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.
@@ -58,6 +58,7 @@
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
@@ -367,7 +368,7 @@ Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
     static const char *const cGroup2TypeEnum[] =
     { "none", "vector", "plane", "t0", "z", "sphnorm" };
 
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("angaver")
index 253f2066d694b85521b569807a42bdef8c5a0046..13794cb2a9fea01427eb0124cd679e463ccb626e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,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.
@@ -56,6 +56,7 @@
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/stringutil.h"
 
@@ -149,7 +150,7 @@ Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*
         "each individual distance, calculated over the frames."
     };
 
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("distave")
index a29cf181b299e0c211b76993ef6d48f645087d01..3e24e2fbfc00b7a67f9786994e418222c0edfe7a 100644 (file)
@@ -59,8 +59,8 @@
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/stringutil.h"
 
 namespace gmx
 {
@@ -194,7 +194,7 @@ FreeVolume::initOptions(Options                    *options,
     };
 
     // Add the descriptive text (program help text) to the options
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     // Add option for optional output file
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
index df2bea69279ef4eee75f8f1969440b3285a0c073..9122b8dbbf63364af6b39e9bb6f2968bb3cbbce2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,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.
@@ -65,6 +65,7 @@
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoption.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/stringutil.h"
@@ -386,7 +387,7 @@ Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
         "dynamic selections."
     };
 
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     options->addOption(FileNameOption("os").filetype(eftPlot).outputFile()
                            .store(&fnSize_).defaultBasename("size")
index 35244dd2a334fff48be395afee0840db12abc7df..e76e3abc09a503955fc3bf95af53c56c55b0ca58 100644 (file)
@@ -44,8 +44,8 @@
 #include "gromacs/trajectoryanalysis/analysismodule.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
 #include "gromacs/trajectoryanalysis/cmdlinerunner.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/stringutil.h"
 
 namespace gmx
 {
@@ -103,7 +103,7 @@ SelectionTester::initOptions(Options                   *options,
         "This is a test program for selections."
     };
 
-    options->setDescription(concatenateStrings(desc));
+    options->setDescription(desc);
 
     options->addOption(SelectionOption("select").storeVector(&selections_)
                            .required().multiValue()