Remove dependency on commandline/ from oenv.cpp
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 27 Mar 2014 04:22:49 +0000 (06:22 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 31 Mar 2014 07:23:04 +0000 (09:23 +0200)
This was unnecessary, and this simplifies the module dependency graph.
With some simple changes, oenv only needs to use
utility/programcontext.h.

Change-Id: I794b15cee88bf49379fd8c783672df5f57628c97

share/template/cmake/FindGROMACS.cmakein
src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/commandline/pargs.cpp
src/gromacs/gmxlib/oenv.cpp
src/gromacs/legacyheaders/oenv.h
src/gromacs/trajectoryanalysis/runnercommon.cpp

index c8830815f20770e9829723d189dfad528ef2b822..84a0fa6ed18591dd0718ace7f99bda9e46d7f92f 100644 (file)
@@ -115,10 +115,10 @@ if (GROMACS_LIBRARY)
     message(FATAL_ERROR "Could not find init_mtop in the GROMACS library, take look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what was going wrong. This most likely means that your GROMACS version is too old, we need at least GROMACS 4.0.7.")
   endif(NOT FOUND_GROMACS_INIT_MTOP)
   set(GROMACS_VERSION 40000)
-  check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" output_env_init "" FOUND_GROMACS_OUTPUT_ENV_INIT)
-  if(FOUND_GROMACS_OUTPUT_ENV_INIT)
+  check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" output_env_done "" FOUND_GROMACS_OUTPUT_ENV_DONE)
+  if(FOUND_GROMACS_OUTPUT_ENV_DONE)
     set(GROMACS_VERSION 40500)
-  endif(FOUND_GROMACS_OUTPUT_ENV_INIT)
+  endif(FOUND_GROMACS_OUTPUT_ENV_DONE)
   check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" gmx_nonbonded_setup "" FOUND_GROMACS_GMX_NONBONDED_SETUP)
   if(FOUND_GROMACS_GMX_NONBONDED_SETUP)
     set(GROMACS_VERSION 40600)
index 8cc0ffbce913caa6c3d383eac5090f9a46c548ed..ca66a1fdf75716ed9b2fa210f05570b4c2264ebe 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.
 
 #include <boost/shared_ptr.hpp>
 
-#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/legacyheaders/oenv.h"
 #include "gromacs/legacyheaders/vec.h"
 #include "gromacs/legacyheaders/xvgr.h"
 
 #include "gromacs/analysisdata/dataframe.h"
+#include "gromacs/fileio/gmxfio.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/selection/selectioncollection.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/stringutil.h"
 
 namespace
@@ -330,7 +331,7 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData * /* data */)
                    ? static_cast<xvg_format_t>(impl_->settings_.plotFormat())
                    : exvgNONE);
             output_env_t                  oenv;
-            output_env_init(&oenv, 0, NULL, time_unit, FALSE, xvg_format, 0, 0);
+            output_env_init(&oenv, getProgramContext(), time_unit, FALSE, xvg_format, 0, 0);
             boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done);
             impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(),
                                   impl_->xlabel_.c_str(), impl_->ylabel_.c_str(),
index 631cabd5e085baa077bef7d77a249d96b173ba9e..148f5a2217153c0d42efecd4806af8c8b2bb9150 100644 (file)
@@ -74,6 +74,7 @@
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/stringutil.h"
 
 /* The source code in this file should be thread-safe.
@@ -786,7 +787,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
     get_pargs(argc, argv, npall, all_pa);
 
     /* set program name, command line, and default values for output options */
-    output_env_init(oenv, *argc, argv, (time_unit_t)nenum(time_units), bView,
+    output_env_init(oenv, gmx::getProgramContext(), (time_unit_t)nenum(time_units), bView,
                     (xvg_format_t)nenum(xvg_format), 0, debug_level);
 
     /* Parse the file args */
index fc9134650260b51f3d46f641ac060e08b06ad19b..d38a037800ec3a8fe7c2c2b21a7d8708815bbbc6 100644 (file)
 
 #include "smalloc.h"
 
-#include "gromacs/commandline/cmdlineprogramcontext.h"
+#include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/exceptions.h"
 
 struct output_env
 {
-    output_env()
-    {
-        setDefaults();
-    }
-    output_env(int argc, const char *const argv[])
-        : programContext(argc, argv)
-    {
-        setDefaults();
-    }
-
-    void setDefaults()
+    explicit output_env(const gmx::ProgramContextInterface &context)
+        : programContext(context)
     {
         time_unit   = time_ps;
         view        = FALSE;
@@ -62,18 +53,18 @@ struct output_env
         debug_level = 0;
     }
 
-    gmx::CommandLineProgramContext programContext;
+    const gmx::ProgramContextInterface  &programContext;
 
     /* the time unit, enum defined in oenv.h */
-    time_unit_t                    time_unit;
+    time_unit_t                          time_unit;
     /* view of file requested */
-    gmx_bool                       view;
+    gmx_bool                             view;
     /* xvg output format, enum defined in oenv.h */
-    xvg_format_t                   xvg_format;
+    xvg_format_t                         xvg_format;
     /* The level of verbosity for this program */
-    int                            verbosity;
+    int                                  verbosity;
     /* the debug level */
-    int                            debug_level;
+    int                                  debug_level;
 };
 
 /* The source code in this file should be thread-safe.
@@ -101,13 +92,14 @@ static const char *time_units_xvgr[] = {
 
 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
 
-void output_env_init(output_env_t *oenvp, int argc, char *argv[],
+void output_env_init(output_env_t *oenvp,
+                     const gmx::ProgramContextInterface &context,
                      time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
                      int verbosity, int debug_level)
 {
     try
     {
-        output_env_t oenv = new output_env(argc, argv);
+        output_env_t oenv = new output_env(context);
         *oenvp            = oenv;
         oenv->time_unit   = tmu;
         oenv->view        = view;
@@ -122,7 +114,7 @@ void output_env_init_default(output_env_t *oenvp)
 {
     try
     {
-        output_env_t oenv = new output_env();
+        output_env_t oenv = new output_env(gmx::getProgramContext());
         *oenvp = oenv;
     }
     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
index 11c4fe2ba3af22d151bf266e6bd12e98977501e3..efd24f896e8cdc0f6a7ef6df7ee05ab8102b418f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -69,14 +69,6 @@ typedef enum {
 /* the xvg output formattings */
 
 
-void output_env_init(output_env_t *oenvp,  int argc, char *argv[],
-                     time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
-                     int verbosity, int debug_level);
-/* initialize an output_env structure, setting the command line,
-   the default time value a gmx_boolean view that is set to TRUE when the
-   user requests direct viewing of graphs,
-   the graph formatting type, the verbosity, and debug level */
-
 void output_env_init_default(output_env_t *oenvp);
 /* initialize an output_env structure, with reasonable default settings.
     (the time unit is set to time_ps, which means no conversion).  */
@@ -129,6 +121,20 @@ const char *output_env_get_short_program_name(const output_env_t oenv);
 
 #ifdef __cplusplus
 }
+
+namespace gmx
+{
+class ProgramContextInterface;
+} // namespace gmx
+
+void output_env_init(output_env_t *oenvp,
+                     const gmx::ProgramContextInterface &context,
+                     time_unit_t tmu, gmx_bool view, xvg_format_t xvg_format,
+                     int verbosity, int debug_level);
+/* initialize an output_env structure, setting the command line,
+   the default time value a gmx_boolean view that is set to TRUE when the
+   user requests direct viewing of graphs,
+   the graph formatting type, the verbosity, and debug level */
 #endif
 
 #endif
index c734b8fbb317b5d9e5c47ce0cf30ee797756cdb3..62793a6e932919cb743d58a3acd95eced41effae 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.
@@ -64,6 +64,7 @@
 #include "gromacs/trajectoryanalysis/analysissettings.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/programcontext.h"
 #include "gromacs/utility/stringutil.h"
 
 #include "analysissettings-impl.h"
@@ -347,7 +348,7 @@ TrajectoryAnalysisRunnerCommon::initFirstFrame()
     }
     time_unit_t time_unit
         = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1);
-    output_env_init(&impl_->oenv_, 0, NULL, time_unit, FALSE, exvgNONE, 0, 0);
+    output_env_init(&impl_->oenv_, getProgramContext(), time_unit, FALSE, exvgNONE, 0, 0);
 
     int frflags = impl_->settings_.frflags();
     frflags |= TRX_NEED_X;