From 37877b727954799ec8f265fb8e81ce7d75885d80 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Thu, 27 Mar 2014 06:22:49 +0200 Subject: [PATCH] Remove dependency on commandline/ from oenv.cpp 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 | 6 ++-- src/gromacs/analysisdata/modules/plot.cpp | 7 ++-- src/gromacs/commandline/pargs.cpp | 3 +- src/gromacs/gmxlib/oenv.cpp | 34 +++++++------------ src/gromacs/legacyheaders/oenv.h | 24 ++++++++----- .../trajectoryanalysis/runnercommon.cpp | 5 +-- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/share/template/cmake/FindGROMACS.cmakein b/share/template/cmake/FindGROMACS.cmakein index c8830815f2..84a0fa6ed1 100644 --- a/share/template/cmake/FindGROMACS.cmakein +++ b/share/template/cmake/FindGROMACS.cmakein @@ -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) diff --git a/src/gromacs/analysisdata/modules/plot.cpp b/src/gromacs/analysisdata/modules/plot.cpp index 8cc0ffbce9..ca66a1fdf7 100644 --- a/src/gromacs/analysisdata/modules/plot.cpp +++ b/src/gromacs/analysisdata/modules/plot.cpp @@ -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. @@ -49,18 +49,19 @@ #include -#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(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 oenvGuard(oenv, &output_env_done); impl_->fp_ = xvgropen(impl_->filename_.c_str(), impl_->title_.c_str(), impl_->xlabel_.c_str(), impl_->ylabel_.c_str(), diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 631cabd5e0..148f5a2217 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -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 */ diff --git a/src/gromacs/gmxlib/oenv.cpp b/src/gromacs/gmxlib/oenv.cpp index fc91346502..d38a037800 100644 --- a/src/gromacs/gmxlib/oenv.cpp +++ b/src/gromacs/gmxlib/oenv.cpp @@ -38,22 +38,13 @@ #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; diff --git a/src/gromacs/legacyheaders/oenv.h b/src/gromacs/legacyheaders/oenv.h index 11c4fe2ba3..efd24f896e 100644 --- a/src/gromacs/legacyheaders/oenv.h +++ b/src/gromacs/legacyheaders/oenv.h @@ -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 diff --git a/src/gromacs/trajectoryanalysis/runnercommon.cpp b/src/gromacs/trajectoryanalysis/runnercommon.cpp index c734b8fbb3..62793a6e93 100644 --- a/src/gromacs/trajectoryanalysis/runnercommon.cpp +++ b/src/gromacs/trajectoryanalysis/runnercommon.cpp @@ -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(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; -- 2.22.0