Update headers, fix style for some py files
[alexxy/gromacs.git] / src / python / sip / trajectoryanalysis / TrajectoryAnalysis.sip
index 837a29164c89a771c473808f907494eb07bfe88e..cbcd919b4e8d70b989eff1993c642c2292dac582 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 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.
 
 %Module gromacs.TrajectoryAnalysis
 
+%DefaultEncoding "UTF-8"
+
 %Import options/Options.sip
 %Import topology/Topology.sip
 
 %Include definitions.sip
 
 %Include analysissettings.sip
+%Include analysisdata.sip
 %Include analysismodule.sip
 
+%Include modules.sip
+
 %ModuleCode
 #include "gromacs/trajectoryanalysis/analysismodule.h"
 #include "gromacs/trajectoryanalysis/cmdlinerunner.h"
 #include "gromacs/utility/exceptions.h"
 
-class PyFactory {
+class PyFactory : public gmx::TrajectoryAnalysisCommandLineRunner::ModuleFactoryFunctor {
 public:
     PyFactory(PyObject *mod) : mod(mod) {} ;
     gmx::TrajectoryAnalysisModulePointer operator () () {
@@ -67,8 +72,11 @@ void runAsMain(PyObject *mod, PyObject *py_argv) {
     int argc = PyList_GET_SIZE(py_argv);
 
     char **argv = new char *[argc + 1];
+    bool to_free[argc];
+    std::fill(to_free, to_free+argc, false);
 
     // Convert the list.
+    // TODO: Use something better than AsLatin1String to avoid unicode errors
     for (int a = 0; a < argc; ++a)
     {
         PyObject *arg_obj = PyList_GET_ITEM(py_argv, a);
@@ -78,6 +86,7 @@ void runAsMain(PyObject *mod, PyObject *py_argv) {
         {
             arg = strdup(arg);
             Py_DECREF(arg_obj);
+            to_free[a] = true;
         }
         else
         {
@@ -89,7 +98,13 @@ void runAsMain(PyObject *mod, PyObject *py_argv) {
 
     argv[argc] = NULL;
 
-    TrajectoryAnalysisCommandLineRunner::runAsMain(argc, argv, PyFactory(mod));
+    PyFactory factory(mod);
+    TrajectoryAnalysisCommandLineRunner::runAsMain(argc, argv, &factory);
+
+    for (int i = 0; i < argc; i++)
+        if (to_free[i])
+            free(argv[i]);
+    delete[] argv;
 }
 
 %End