Extract IOptionsContainer from Options
[alexxy/gromacs.git] / src / gromacs / selection / selectioncollection.h
index 7da3d427d46c621efcf09b04e3d2aea69cc3cd13..663667abc7696d573459a2368ffc87da0e234937 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,2015, 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.
 #ifndef GMX_SELECTION_SELECTIONCOLLECTION_H
 #define GMX_SELECTION_SELECTIONCOLLECTION_H
 
+#include <cstdio>
+
 #include <string>
 #include <vector>
 
-#include "../legacyheaders/typedefs.h"
-
-#include "../onlinehelp/helptopicinterface.h"
-#include "../utility/common.h"
-#include "selection.h" // For gmx::SelectionList
+#include "gromacs/legacyheaders/types/oenv.h"
+#include "gromacs/selection/selection.h" // For gmx::SelectionList
+#include "gromacs/utility/classhelpers.h"
 
 struct gmx_ana_indexgrps_t;
+struct t_pbc;
+struct t_topology;
+struct t_trxframe;
 
 namespace gmx
 {
 
-class Options;
+class IOptionsContainer;
 class SelectionCompiler;
 class SelectionEvaluator;
+class TextInputStream;
+class TextOutputStream;
 
 /*! \brief
  * Collection of selections.
@@ -76,7 +81,7 @@ class SelectionEvaluator;
  * initialization options.
  *
  * After setting the default values, one or more selections can be parsed with
- * one or more calls to parseFromStdin(), parseFromFile(), and/or
+ * one or more calls to parseInteractive(), parseFromStdin(), parseFromFile(), and/or
  * parseFromString().  After all selections are parsed, the topology must be
  * set with setTopology() unless requiresTopology() returns false (the topology
  * can also be set earlier).
@@ -107,14 +112,6 @@ class SelectionEvaluator;
 class SelectionCollection
 {
     public:
-        /*! \brief
-         * Creates a help tree for selections.
-         *
-         * \throws   std::bad_alloc if out of memory.
-         * \returns  Root topic of the created selection tree.
-         */
-        static HelpTopicPointer createDefaultHelpTopic();
-
         /*! \brief
          * Creates an empty selection collection.
          *
@@ -133,7 +130,7 @@ class SelectionCollection
          * position types (see setReferencePosType() and setOutputPosType())
          * and debugging flags.
          */
-        void initOptions(Options *options);
+        void initOptions(IOptionsContainer *options);
 
         /*! \brief
          * Sets the default reference position handling for a selection
@@ -245,6 +242,7 @@ class SelectionCollection
          *      (if -1, parse as many as provided by the user).
          * \param[in]  bInteractive Whether the parser should behave
          *      interactively.
+         * \param[in]  context  Context to print for interactive input.
          * \returns    Vector of parsed selections.
          * \throws     std::bad_alloc if out of memory.
          * \throws     InvalidInputError if there is a parsing error
@@ -255,8 +253,37 @@ class SelectionCollection
          * the selection collection.
          * Some information about the selections only becomes available once
          * compile() has been called; see \ref Selection.
+         *
+         * The string provided to \p context should be such that it can replace
+         * the three dots in "Specify selections ...:".  It can be empty.
+         */
+        SelectionList parseFromStdin(int count, bool bInteractive,
+                                     const std::string &context);
+        /*! \brief
+         * Parses selection(s) interactively using provided streams.
+         *
+         * \param[in]  count    Number of selections to parse
+         *      (if -1, parse as many as provided by the user).
+         * \param[in]  inputStream  Stream to use for input.
+         * \param[in]  outputStream Stream to use for output
+         *      (if NULL, the parser runs non-interactively and does not
+         *      produce any status messages).
+         * \param[in]  context  Context to print for interactive input.
+         * \returns    Vector of parsed selections.
+         * \throws     std::bad_alloc if out of memory.
+         * \throws     InvalidInputError if there is a parsing error
+         *      (an interactive parser only throws this if too few selections
+         *      are provided and the user forced the end of input).
+         *
+         * Works the same as parseFromStdin(), except that the caller can
+         * provide streams to use instead of `stdin` and `stderr`.
+         *
+         * Mainly usable for unit testing interactive input.
          */
-        SelectionList parseFromStdin(int count, bool bInteractive);
+        SelectionList parseInteractive(int                count,
+                                       TextInputStream   *inputStream,
+                                       TextOutputStream  *outputStream,
+                                       const std::string &context);
         /*! \brief
          * Parses selection(s) from a file.
          *