From 0383e8dacdb1592ef6298d845319825dcd817683 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 13 Feb 2016 22:30:51 +0100 Subject: [PATCH] Add GFilename SWIG typemap that transparently converts a Python string into a GFilename object. This allows now replacing all std::string filenames by GFilename arguments. --- inst/com/pyext/com.i | 5 ++++- inst/cta/pyext/cta.i | 5 ++++- inst/lat/pyext/lat.i | 5 ++++- inst/mwl/pyext/mwl.i | 5 ++++- pyext/gammalib/app.i | 5 ++++- pyext/gammalib/base.i | 5 ++++- pyext/gammalib/fits.i | 5 ++++- pyext/gammalib/linalg.i | 5 ++++- pyext/gammalib/model.i | 5 ++++- pyext/gammalib/numerics.i | 5 ++++- pyext/gammalib/obs.i | 5 ++++- pyext/gammalib/opt.i | 5 ++++- pyext/gammalib/sky.i | 5 ++++- pyext/gammalib/support.i | 5 ++++- pyext/gammalib/test.i | 5 ++++- pyext/gammalib/vo.i | 5 ++++- pyext/gammalib/xml.i | 5 ++++- pyext/gammalib/xspec.i | 5 ++++- pyext/typemap_GFilename.i | 44 ++++++++++++++++++++++++++++++++++++++++++++ 19 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 pyext/typemap_GFilename.i diff --git a/inst/com/pyext/com.i b/inst/com/pyext/com.i index bf6b03c..b04ad4f 100644 --- a/inst/com/pyext/com.i +++ b/inst/com/pyext/com.i @@ -1,7 +1,7 @@ /*************************************************************************** * com.i - COMPTEL module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2013 by Juergen Knoedlseder * + * copyright (C) 2012-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GRegistry.i"; diff --git a/inst/cta/pyext/cta.i b/inst/cta/pyext/cta.i index 5256e91..56a4e9c 100644 --- a/inst/cta/pyext/cta.i +++ b/inst/cta/pyext/cta.i @@ -1,7 +1,7 @@ /*************************************************************************** * cta.i - Cherenkov Telescope Array module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/inst/lat/pyext/lat.i b/inst/lat/pyext/lat.i index a778ed5..3b01b3c 100644 --- a/inst/lat/pyext/lat.i +++ b/inst/lat/pyext/lat.i @@ -1,7 +1,7 @@ /*************************************************************************** * lat.i - Fermi/LAT module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/inst/mwl/pyext/mwl.i b/inst/mwl/pyext/mwl.i index 94520c8..91e9bf8 100644 --- a/inst/mwl/pyext/mwl.i +++ b/inst/mwl/pyext/mwl.i @@ -1,7 +1,7 @@ /*************************************************************************** * mwl.i - Multi-wavelength module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/pyext/gammalib/app.i b/pyext/gammalib/app.i index 0cdfe3b..4cba5fd 100644 --- a/pyext/gammalib/app.i +++ b/pyext/gammalib/app.i @@ -1,7 +1,7 @@ /*************************************************************************** * app.i - Application module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/base.i b/pyext/gammalib/base.i index 2dcd311..9ea8c9a 100644 --- a/pyext/gammalib/base.i +++ b/pyext/gammalib/base.i @@ -1,7 +1,7 @@ /*************************************************************************** * base.i - Base module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2013 by Juergen Knoedlseder * + * copyright (C) 2012-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Base module ________________________________________________________ */ %include "GBase.i" %include "GContainer.i" diff --git a/pyext/gammalib/fits.i b/pyext/gammalib/fits.i index 5534d3b..bff55fb 100644 --- a/pyext/gammalib/fits.i +++ b/pyext/gammalib/fits.i @@ -1,7 +1,7 @@ /*************************************************************************** * fits.i - FITS module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/linalg.i b/pyext/gammalib/linalg.i index 1d567e3..84f4b21 100644 --- a/pyext/gammalib/linalg.i +++ b/pyext/gammalib/linalg.i @@ -1,7 +1,7 @@ /*************************************************************************** * linalg.i - Linear algebra module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/pyext/gammalib/model.i b/pyext/gammalib/model.i index 6de942c..d17a4a2 100644 --- a/pyext/gammalib/model.i +++ b/pyext/gammalib/model.i @@ -1,7 +1,7 @@ /*************************************************************************** * model.i - Model module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/numerics.i b/pyext/gammalib/numerics.i index f0ecb70..dc2ada8 100644 --- a/pyext/gammalib/numerics.i +++ b/pyext/gammalib/numerics.i @@ -1,7 +1,7 @@ /*************************************************************************** * numerics.i - Numerics module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; diff --git a/pyext/gammalib/obs.i b/pyext/gammalib/obs.i index 19f3585..9613a7b 100644 --- a/pyext/gammalib/obs.i +++ b/pyext/gammalib/obs.i @@ -1,7 +1,7 @@ /*************************************************************************** * obs.i - Observation module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/opt.i b/pyext/gammalib/opt.i index 99c67a2..f480010 100644 --- a/pyext/gammalib/opt.i +++ b/pyext/gammalib/opt.i @@ -1,7 +1,7 @@ /*************************************************************************** * opt.i - Optimization module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/sky.i b/pyext/gammalib/sky.i index 3898b34..c0cecbf 100644 --- a/pyext/gammalib/sky.i +++ b/pyext/gammalib/sky.i @@ -1,7 +1,7 @@ /*************************************************************************** * sky.i - Sky module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Jurgen Knodlseder * + * copyright (C) 2011-2016 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/support.i b/pyext/gammalib/support.i index 1dfdf09..c4509ff 100644 --- a/pyext/gammalib/support.i +++ b/pyext/gammalib/support.i @@ -1,7 +1,7 @@ /*************************************************************************** * support.i - Support module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Jurgen Knodlseder * + * copyright (C) 2011-2016 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/test.i b/pyext/gammalib/test.i index 0e17c1d..2c202ff 100644 --- a/pyext/gammalib/test.i +++ b/pyext/gammalib/test.i @@ -1,7 +1,7 @@ /*************************************************************************** * test.i - Test module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2013 by Jean-Baptiste Cayrou * + * copyright (C) 2012-2016 by Jean-Baptiste Cayrou * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/vo.i b/pyext/gammalib/vo.i index cd92ac0..3de0e65 100644 --- a/pyext/gammalib/vo.i +++ b/pyext/gammalib/vo.i @@ -1,7 +1,7 @@ /*************************************************************************** * vo.i - Virtual Observatory module * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Juergen Knoedlseder * + * copyright (C) 2014-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; //%import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/xml.i b/pyext/gammalib/xml.i index 5017b16..8fcc6d4 100644 --- a/pyext/gammalib/xml.i +++ b/pyext/gammalib/xml.i @@ -1,7 +1,7 @@ /*************************************************************************** * xml.i - XML module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; %import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/gammalib/xspec.i b/pyext/gammalib/xspec.i index ee05ceb..af6200f 100644 --- a/pyext/gammalib/xspec.i +++ b/pyext/gammalib/xspec.i @@ -1,7 +1,7 @@ /*************************************************************************** * xspec.i - XSPEC module * * ----------------------------------------------------------------------- * - * copyright (C) 2013 by Juergen Knoedlseder * + * copyright (C) 2013-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,6 +39,9 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +/* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GFilename.i + /* __ Include interface classes __________________________________________ */ %import(module="gammalib.base") "GBase.i"; //%import(module="gammalib.base") "GContainer.i"; diff --git a/pyext/typemap_GFilename.i b/pyext/typemap_GFilename.i new file mode 100644 index 0000000..6a2b119 --- /dev/null +++ b/pyext/typemap_GFilename.i @@ -0,0 +1,44 @@ +/*************************************************************************** + * typemap_GFilename.i - Filename typemap * + * ----------------------------------------------------------------------- * + * copyright (C) 2016 by Juergen Knoedlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ + +/***********************************************************************//** + * @brief Input typemap for GFilename + * + * This typemap allows to pass a string for a GFilename& argument. In that + * way the user can simply pass a string to any function or method that has + * a GFilename argument, and the typemap transparently converts a string + * into a GFilename object. + ***************************************************************************/ +%typemap(in) GFilename& (GFilename temp) { + if (PyString_Check($input)) { + temp = GFilename(std::string(PyString_AsString($input))); + $1 = &temp; + } + else { + void *filename_argp1 = 0; + if (SWIG_IsOK(SWIG_ConvertPtr($input, &filename_argp1, SWIGTYPE_p_GFilename, 0))) { + $1 = reinterpret_cast(filename_argp1); + } + else { + SWIG_exception(SWIG_TypeError, "GFilename expected"); + } + } +} -- libgit2 0.21.4