Make output_env struct properly private/opaque.
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 2 May 2012 07:06:12 +0000 (10:06 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Wed, 2 May 2012 07:06:12 +0000 (10:06 +0300)
All the necessary functions already existed to make the structure
private, only the signature of the initialization functions needed to be
changed.  Adjusted places where the structure was initialized to not
access the internals of the structure, but do everything through the
initialization functions.

Change-Id: Ia1f7fdeccd0678e41b5af4256fcf6f7a4014c59d

src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/gmxlib/oenv.c
src/gromacs/gmxlib/statutil.c
src/gromacs/legacyheaders/oenv.h
src/gromacs/trajectoryanalysis/runnercommon.cpp

index 4160b6cbaa4ea8348118e6806b950c2187b83c86..51bdec0643e53e59080913364f98ade8571c4168 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
-#include <gmxfio.h>
-#include <smalloc.h>
-#include <statutil.h>
-#include <vec.h>
-#include <xvgr.h>
+#include "gromacs/legacyheaders/gmxfio.h"
+#include "gromacs/legacyheaders/oenv.h"
+#include "gromacs/legacyheaders/vec.h"
+#include "gromacs/legacyheaders/xvgr.h"
 
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/analysisdata/dataframe.h"
@@ -277,15 +276,15 @@ AbstractPlotModule::dataStarted(AbstractAnalysisData *data)
         }
         else
         {
-            output_env_t oenv;
-            snew(oenv, 1);
-            output_env_init_default(oenv);
-            boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done);
-            oenv->time_unit = static_cast<time_unit_t>(_impl->settings.timeUnit() + 1);
-            oenv->xvg_format =
-                (_impl->settings.plotFormat() > 0
+            time_unit_t time_unit
+                = static_cast<time_unit_t>(_impl->settings.timeUnit() + 1);
+            xvg_format_t xvg_format
+                = (_impl->settings.plotFormat() > 0
                     ? 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);
+            boost::shared_ptr<output_env> oenvGuard(oenv, &output_env_done);
             _impl->fp = xvgropen(_impl->fnm.c_str(), _impl->title.c_str(),
                                  _impl->xlabel.c_str(), _impl->ylabel.c_str(),
                                  oenv);
index aea00e0eb2875e7c57d4923e8c6ac594a7551f1f..139fae0000acf3fd82f6668510fb8e641542512b 100644 (file)
 #include "thread_mpi.h"
 #endif
 
+struct output_env
+{
+    time_unit_t time_unit; /* the time unit, enum defined in oenv.h */
+    gmx_bool view;  /* view of file requested */
+    xvg_format_t xvg_format; /* xvg output format, enum defined in oenv.h */
+    int  verbosity; /* The level of verbosity for this program */
+    int debug_level; /* the debug level */
 
+    char *program_name; /* the program name */
+    char *cmd_line; /* the re-assembled command line */
+};
 
 /* The source code in this file should be thread-safe. 
       Please keep it that way. */
@@ -73,7 +83,7 @@
  ******************************************************************/
 
 /* read only time names */
-/* These must correspond to the time units type time_unit_t in statutil.h */
+/* These must correspond to the time units type time_unit_t in oenv.h */
 static const real timefactors[] =   { 0,  1e3,  1, 1e-3, 1e-6, 1e-9, 1e-12, 0 };
 static const real timeinvfactors[] ={ 0, 1e-3,  1,  1e3,  1e6,  1e9,  1e12, 0 };
 static const char *time_units_str[] = { NULL, "fs", "ps", "ns", "us", 
@@ -85,14 +95,17 @@ static const char *time_units_xvgr[] = { NULL, "fs", "ps", "ns",
 
 /***** OUTPUT_ENV MEMBER FUNCTIONS ******/
 
-void output_env_init(output_env_t oenv,  int argc, char *argv[],
+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)
 {
     int i;
     int cmdlength=0;
     char *argvzero=NULL;
+    output_env_t oenv;
 
+    snew(oenv, 1);
+    *oenvp = oenv;
     oenv->time_unit  = tmu;
     oenv->view=view;
     oenv->xvg_format = xvg_format;
@@ -141,9 +154,9 @@ void output_env_init(output_env_t oenv,  int argc, char *argv[],
 }
 
 
-void output_env_init_default(output_env_t oenv)
+void output_env_init_default(output_env_t *oenvp)
 {
-    output_env_init(oenv, 0, NULL, time_ps, FALSE, exvgNONE, 0, 0);
+    output_env_init(oenvp, 0, NULL, time_ps, FALSE, exvgNONE, 0, 0);
 }
 
 
index c60d624de82f34de1487e13fddcf77edeca2b46e..fbf928432181c4a21221eef2a901a32e9e1dadf3 100644 (file)
@@ -583,8 +583,6 @@ void parse_common_args(int *argc,char *argv[],unsigned long Flags,
     
 #define FF(arg) ((Flags & arg)==arg)
 
-    snew(*oenv, 1);
-    
     cmdlength = strlen(argv[0]);
     /* Check for double arguments */
     for (i=1; (i<*argc); i++) 
@@ -684,7 +682,7 @@ void parse_common_args(int *argc,char *argv[],unsigned long Flags,
     get_pargs(argc,argv,npall,all_pa,FF(PCA_KEEP_ARGS));
 
     /* 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, *argc, argv, (time_unit_t)nenum(time_units), bView,
                     (xvg_format_t)nenum(xvg_format), verbose_level, debug_level);
  
     if (bVersion) {
@@ -756,10 +754,6 @@ void parse_common_args(int *argc,char *argv[],unsigned long Flags,
     }
 #endif
 #endif
-   
-    /* Update oenv for parsed command line options settings. */
-    (*oenv)->xvg_format = (xvg_format_t)nenum(xvg_format);
-    (*oenv)->time_unit  = (time_unit_t)nenum(time_units);
     
     if (!(FF(PCA_QUIET) || bQuiet )) {
         if (bHelp)
index 70604fe50c300c62e5071d8700260aacbfbb65c7..9559080f1abf4973b6475c3f74acaa430d060263 100644 (file)
@@ -64,20 +64,7 @@ typedef enum { exvgNULL, exvgXMGRACE, exvgXMGR, exvgNONE } xvg_format_t;
 /* the xvg output formattings */
 
 
-struct output_env
-{
-    time_unit_t time_unit; /* the time unit, enum defined in statuti.h */
-    gmx_bool view;  /* view of file requested */
-    xvg_format_t xvg_format; /* xvg output format, enum defined in statutil.h */
-    int  verbosity; /* The level of verbosity for this program */
-    int debug_level; /* the debug level */
-
-    char *program_name; /* the program name */
-    char *cmd_line; /* the re-assembled command line */
-};
-
-
-void output_env_init(output_env_t oenv,  int argc, char *argv[],
+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, 
@@ -85,7 +72,7 @@ void output_env_init(output_env_t oenv,  int argc, char *argv[],
    user requests direct viewing of graphs, 
    the graph formatting type, the verbosity, and debug level */
 
-void output_env_init_default(output_env_t oenv);
+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).  */
 
index 8265ca22df951c4be60f440ef3db48d58fc0ec78..7868dafb32d676927a24987a37767cd0b118311f 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <string.h>
 
+#include "oenv.h"
 #include "rmpbc.h"
 #include "smalloc.h"
 #include "statutil.h"
@@ -341,10 +342,9 @@ TrajectoryAnalysisRunnerCommon::initFirstFrame()
     {
         return;
     }
-    snew(_impl->_oenv, 1);
-    output_env_init_default(_impl->_oenv);
-    _impl->_oenv->time_unit
+    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);
 
     int frflags = _impl->_settings.frflags();
     frflags |= TRX_NEED_X;