From 48d0f7f845aabf14786ea7563c180f6204bb48ba Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 17 Nov 2020 21:30:26 +0100 Subject: [PATCH] Resolve more SWIG warnings --- inst/cta/pyext/GCTAResponseTable.i | 88 +++++++++------------------------------------------------------------------------------- inst/cta/pyext/cta.i | 2 ++ pyext/GCsv.i | 57 +++++---------------------------------------------------- pyext/GFitsImageByte.i | 6 +++--- pyext/GFitsImageDouble.i | 6 +++--- pyext/GFitsImageFloat.i | 4 ++-- pyext/GFitsImageLong.i | 6 +++--- pyext/GFitsImageLongLong.i | 6 +++--- pyext/GFitsImageSByte.i | 6 +++--- pyext/GFitsImageShort.i | 6 +++--- pyext/GFitsImageULong.i | 6 +++--- pyext/GFitsImageUShort.i | 6 +++--- pyext/GFitsTable.i | 73 +------------------------------------------------------------------------ pyext/GFitsTableBitCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableBoolCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableByteCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableCDoubleCol.i | 41 ++++++++++++++++++++--------------------- pyext/GFitsTableCFloatCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableCol.i | 119 +++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- pyext/GFitsTableDoubleCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableFloatCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableLongCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableLongLongCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableShortCol.i | 40 +++++++++++++++++++--------------------- pyext/GFitsTableStringCol.i | 59 ++++++++++++++++++++++++++++------------------------------- pyext/GFitsTableULongCol.i | 41 ++++++++++++++++++++--------------------- pyext/GFitsTableUShortCol.i | 41 ++++++++++++++++++++--------------------- pyext/GMatrix.i | 10 +++++----- pyext/GMatrixSparse.i | 10 +++++----- pyext/GMatrixSymmetric.i | 10 +++++----- pyext/GResponseVectorCache.i | 5 +++-- pyext/GRmf.i | 8 ++++---- pyext/GSkyMap.i | 102 ++++++++++++++++-------------------------------------------------------------------------------------- pyext/gammalib/fits.i | 1 + pyext/gammalib/obs.i | 16 ---------------- pyext/gammalib/sky.i | 1 + pyext/gammalib/support.i | 1 + pyext/typemap_GTuple.i | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 38 files changed, 457 insertions(+), 714 deletions(-) diff --git a/inst/cta/pyext/GCTAResponseTable.i b/inst/cta/pyext/GCTAResponseTable.i index f24a95d..4fc9ac7 100644 --- a/inst/cta/pyext/GCTAResponseTable.i +++ b/inst/cta/pyext/GCTAResponseTable.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAResponseTable.i - CTA response table class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2018 by Juergen Knoedlseder * + * copyright (C) 2012-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -36,76 +36,6 @@ /***********************************************************************//** - * @brief Tuple to index conversion to provide pixel access. - * - * The following function provides conversion between a Python tuple and - * an integer array. This allows CTAResponseTable pixel access via tuples, - * such as in a[3,5,10] = 10.0 or c = a[2,9]. - ***************************************************************************/ -%{ -static int rsp_table_tuple(PyObject *input, int *ptr) { - if (PySequence_Check(input)) { - int size = PyObject_Length(input); - if (size > 2) { - PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); - return 0; - } - ptr[0] = size; - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyInt_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); - return 0; - } - ptr[i+1] = (int)PyInt_AsLong(o); - Py_DECREF(o); - } - return 1; - } - else { - ptr[0] = 1; - if (!PyInt_Check(input)) { - PyErr_SetString(PyExc_ValueError,"Expecting an integer"); - return 0; - } - ptr[1] = (int)PyInt_AsLong(input); - return 1; - } -} -%} - -// This is the typemap that makes use of the function defined above -%typemap(in) int GCTAResponseTableInx[ANY](int temp[3]) { - if (!rsp_table_tuple($input,temp)) { - return NULL; - } - $1 = &temp[0]; -} - -// This typecheck verifies that all arguments are integers. The typecheck -// is needed for using "int GCTAResponseTableInx" in overloaded methods. -%typemap(typecheck) int GCTAResponseTableInx[ANY] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - - -/***********************************************************************//** * @class GCTAResponseTable * * @brief Interface for the CTA response table class @@ -171,20 +101,20 @@ public: * @brief GCTAResponse class extension ***************************************************************************/ %extend GCTAResponseTable { - double __getitem__(int GCTAResponseTableInx[]) { - if (GCTAResponseTableInx[0] == 1) { - return (*self)(GCTAResponseTableInx[1]); + double __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - return (*self)(GCTAResponseTableInx[1], GCTAResponseTableInx[2]); + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } } - void __setitem__(int GCTAResponseTableInx[], double value) { - if (GCTAResponseTableInx[0] == 1) { - (*self)(GCTAResponseTableInx[1]) = value; + void __setitem__(int GTuple1D2D[], double value) { + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - (*self)(GCTAResponseTableInx[1], GCTAResponseTableInx[2]) = value; + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } } GCTAResponseTable copy() { diff --git a/inst/cta/pyext/cta.i b/inst/cta/pyext/cta.i index 7e85707..32833d5 100644 --- a/inst/cta/pyext/cta.i +++ b/inst/cta/pyext/cta.i @@ -82,7 +82,9 @@ %include stl.i /* __ Include GammaLib typemaps __________________________________________ */ +%include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i %include typemap_slices.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/GCsv.i b/pyext/GCsv.i index bc74232..6b6c5e1 100644 --- a/pyext/GCsv.i +++ b/pyext/GCsv.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCsv.i - Comma-separated values table class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -31,53 +31,6 @@ /***********************************************************************//** - * @brief Tuple to index conversion to provide element access. - * - * The following function provides conversion between a Python tuple and - * an integer array. This allows table element access via tuples, such as in - * a[3,5] = 10.0 or c = a[2,9]. Note that the typemap will be globally - * defined after inclusing of this file. - ***************************************************************************/ -%{ -static int csv_tuple(PyObject *input, int *ptr) { - if (PySequence_Check(input)) { - int size = PyObject_Length(input); - if (size > 2) { - PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); - return 0; - } - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyInt_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); - return 0; - } - ptr[i] = (int)PyInt_AsLong(o); - Py_DECREF(o); - } - return 1; - } - else { - ptr[0] = 1; - if (!PyInt_Check(input)) { - PyErr_SetString(PyExc_ValueError,"Expecting an integer"); - return 0; - } - ptr[1] = (int)PyInt_AsLong(input); - return 1; - } -} -%} -%typemap(in) int GCsvInx[ANY](int temp[2]) { - if (!csv_tuple($input,temp)) { - return NULL; - } - $1 = &temp[0]; -} - - -/***********************************************************************//** * @class GCsv * * @brief Comma-separated values table class definition @@ -117,11 +70,11 @@ public: * @brief GCsv class extension ***************************************************************************/ %extend GCsv { - std::string __getitem__(int GCsvInx[]) { - return (*self)(GCsvInx[0], GCsvInx[1]); + std::string __getitem__(int GTuple2D[]) { + return (*self)(GTuple2D[0], GTuple2D[1]); } - void __setitem__(int GCsvInx[], std::string value) { - (*self)(GCsvInx[0], GCsvInx[1]) = value; + void __setitem__(int GTuple2D[], std::string value) { + (*self)(GTuple2D[0], GTuple2D[1]) = value; } int __len__() { return (self->size()); diff --git a/pyext/GFitsImageByte.i b/pyext/GFitsImageByte.i index 9c51030..944465e 100644 --- a/pyext/GFitsImageByte.i +++ b/pyext/GFitsImageByte.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageByte.i - FITS Byte image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (unsigned char*)malloc(num*sizeof(unsigned char)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageDouble.i b/pyext/GFitsImageDouble.i index de42599..a3d1832 100644 --- a/pyext/GFitsImageDouble.i +++ b/pyext/GFitsImageDouble.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageDouble.i - Double precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (double*)malloc(num*sizeof(double)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyFloat_Check(s)) { free($1); diff --git a/pyext/GFitsImageFloat.i b/pyext/GFitsImageFloat.i index 4fc1ef5..ed767fc 100644 --- a/pyext/GFitsImageFloat.i +++ b/pyext/GFitsImageFloat.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageFloat.i - Single precision FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,7 +33,7 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (float*)malloc(num*sizeof(float)); for (int i = 0; i < num; ++i) { diff --git a/pyext/GFitsImageLong.i b/pyext/GFitsImageLong.i index f19c47f..18a86cf 100644 --- a/pyext/GFitsImageLong.i +++ b/pyext/GFitsImageLong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLong.i - Long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (long*)malloc(num*sizeof(long)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageLongLong.i b/pyext/GFitsImageLongLong.i index d7dac2a..37bb910 100644 --- a/pyext/GFitsImageLongLong.i +++ b/pyext/GFitsImageLongLong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageLongLong.i - Long long integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (long long*)malloc(num*sizeof(long long)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageSByte.i b/pyext/GFitsImageSByte.i index 8b35078..bcdb113 100644 --- a/pyext/GFitsImageSByte.i +++ b/pyext/GFitsImageSByte.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageSByte.i - Signed Byte FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (char*)malloc(num*sizeof(char)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageShort.i b/pyext/GFitsImageShort.i index 0ee0b66..e14eb5d 100644 --- a/pyext/GFitsImageShort.i +++ b/pyext/GFitsImageShort.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageShort.i - Short integer FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (short*)malloc(num*sizeof(short)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageULong.i b/pyext/GFitsImageULong.i index 9afd020..4d27b99 100644 --- a/pyext/GFitsImageULong.i +++ b/pyext/GFitsImageULong.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageULong.i - Unsigned long image FITS class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (unsigned long*)malloc(num*sizeof(unsigned long)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsImageUShort.i b/pyext/GFitsImageUShort.i index 721358a..3a1972a 100644 --- a/pyext/GFitsImageUShort.i +++ b/pyext/GFitsImageUShort.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsImageUShort.i - Unsigned short FITS image class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,10 +33,10 @@ if (!PyList_Check($input)) { SWIG_exception(SWIG_ValueError, "List expected"); } - int num = PyList_Size($input); + Py_ssize_t num = PyList_Size($input); if (num > 0) { $1 = (unsigned short*)malloc(num*sizeof(unsigned short)); - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; ++i) { PyObject *s = PyList_GetItem($input,i); if (!PyInt_Check(s)) { free($1); diff --git a/pyext/GFitsTable.i b/pyext/GFitsTable.i index c2812e4..0427841 100644 --- a/pyext/GFitsTable.i +++ b/pyext/GFitsTable.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTable.i - FITS abstract table base class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -28,77 +28,6 @@ #include "GFitsTable.hpp" %} -/***********************************************************************//** - * @brief Tuple to index conversion to provide column access. - * - * The following function provides conversion between a Python tuple and - * an integer array. This allows table column access via tuples, such as in - * a[(3,5,10)] = 10.0 or c = a[(2,9)]. Note that the typemap will be - * globally defined after inclusing of this file, hence GFitsTable.i has - * to be included before all table class swig files. - ***************************************************************************/ -%{ -static int table_column_tuple(PyObject *input, int *ptr) { - if (PySequence_Check(input)) { - int size = PyObject_Length(input); - if (size > 2) { - PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); - return 0; - } - ptr[0] = size; - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyInt_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); - return 0; - } - ptr[i+1] = (int)PyInt_AsLong(o); - Py_DECREF(o); - } - return 1; - } - else { - ptr[0] = 1; - if (!PyInt_Check(input)) { - PyErr_SetString(PyExc_ValueError,"Expecting an integer"); - return 0; - } - ptr[1] = (int)PyInt_AsLong(input); - return 1; - } -} -%} - -// This is the typemap that makes use of the function defined above -%typemap(in) int GFitsTableColInx[ANY](int temp[3]) { - if (!table_column_tuple($input,temp)) { - return NULL; - } - $1 = &temp[0]; -} - -// This typecheck verifies that all arguments are integers. The typecheck -// is needed for using "int GFitsTableColInx" in overloaded methods. -%typemap(typecheck) int GFitsTableColInx[ANY] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - /***********************************************************************//** * @class GFitsTable diff --git a/pyext/GFitsTableBitCol.i b/pyext/GFitsTableBitCol.i index 827e021..39f774b 100644 --- a/pyext/GFitsTableBitCol.i +++ b/pyext/GFitsTableBitCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableBitCol.i - FITS table bit column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableBitCol { - bool __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + bool __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], bool value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], bool value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableBoolCol.i b/pyext/GFitsTableBoolCol.i index 84f14bd..2d30af6 100644 --- a/pyext/GFitsTableBoolCol.i +++ b/pyext/GFitsTableBoolCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableBoolCol.i - FITS table boolean column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableBoolCol { - bool __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + bool __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], bool value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], bool value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableByteCol.i b/pyext/GFitsTableByteCol.i index 6a99a4c..ae2b7ef 100644 --- a/pyext/GFitsTableByteCol.i +++ b/pyext/GFitsTableByteCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableByteCol.i - FITS table Byte column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableByteCol { - unsigned char __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + unsigned char __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], unsigned char value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], unsigned char value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableCDoubleCol.i b/pyext/GFitsTableCDoubleCol.i index 8730c4f..68bc223 100644 --- a/pyext/GFitsTableCDoubleCol.i +++ b/pyext/GFitsTableCDoubleCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableCDoubleCol.i - FITS table double precision complex column * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2017 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -74,44 +74,43 @@ public: ***************************************************************************/ %extend GFitsTableCDoubleCol { /* - GFits::cdouble __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + GFits::cdouble __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } */ - void __setitem__(int GFitsTableColInx[], GFits::cdouble value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], GFits::cdouble value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < + self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableCFloatCol.i b/pyext/GFitsTableCFloatCol.i index c88fd03..8c83bc8 100644 --- a/pyext/GFitsTableCFloatCol.i +++ b/pyext/GFitsTableCFloatCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableCFloatCol.i - FITS table single precision complex column * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2017 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -74,44 +74,42 @@ public: ***************************************************************************/ %extend GFitsTableCFloatCol { /* - GFits::cfloat __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + GFits::cfloat __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } */ - void __setitem__(int GFitsTableColInx[], GFits::cfloat value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], GFits::cfloat value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableCol.i b/pyext/GFitsTableCol.i index ccc1a80..2e46235 100644 --- a/pyext/GFitsTableCol.i +++ b/pyext/GFitsTableCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableCol.i - FITS abstract table column base class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -42,27 +42,6 @@ %} %include "std_vector.i" -// This typecheck verifies that all arguments are integers. The typecheck -// is needed for using "int GFitsTableColInx" in overloaded methods. -%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) int GFitsTableColInx[ANY] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - /***********************************************************************//** * @class GFitsTableCol @@ -141,120 +120,120 @@ public: * @todo Add range checking for type casting ***************************************************************************/ %extend GFitsTableCol { - + // String setting - void __setitem__(int GFitsTableColInx[], std::string value) { + void __setitem__(int GTuple1D2D[], std::string value) { if (dynamic_cast(self) != NULL) { GFitsTableStringCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::bad_type("GFitsTableCol::__setitem__", - "Column type does not support string setting."); + "Column type does not support string setting."); } } - + // Integer setting - void __setitem__(int GFitsTableColInx[], int value) { + void __setitem__(int GTuple1D2D[], int value) { if (dynamic_cast(self) != NULL) { GFitsTableBitCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (bool)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (bool)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (bool)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (bool)value; } else if (dynamic_cast(self) != NULL) { GFitsTableBoolCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (bool)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (bool)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (bool)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (bool)value; } else if (dynamic_cast(self) != NULL) { GFitsTableByteCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (unsigned char)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (unsigned char)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (unsigned char)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (unsigned char)value; } else if (dynamic_cast(self) != NULL) { GFitsTableLongCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (long)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (long)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (long)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (long)value; } else if (dynamic_cast(self) != NULL) { GFitsTableLongLongCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (long long)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (long long)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (long long)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (long long)value; } else if (dynamic_cast(self) != NULL) { GFitsTableShortCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (short)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (short)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (short)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (short)value; } else if (dynamic_cast(self) != NULL) { GFitsTableULongCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (unsigned long)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (unsigned long)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (unsigned long)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (unsigned long)value; } else if (dynamic_cast(self) != NULL) { GFitsTableUShortCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (unsigned short)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (unsigned short)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (unsigned short)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (unsigned short)value; } else if (dynamic_cast(self) != NULL) { GFitsTableDoubleCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (double)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (double)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (double)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (double)value; } else if (dynamic_cast(self) != NULL) { GFitsTableFloatCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (float)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (float)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (float)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (float)value; } else { throw GException::bad_type("GFitsTableCol::__setitem__", - "Column type does not support integer setting."); + "Column type does not support integer setting."); } } - + // Floating point setting - void __setitem__(int GFitsTableColInx[], double value) { + void __setitem__(int GTuple1D2D[], double value) { if (dynamic_cast(self) != NULL) { GFitsTableDoubleCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else if (dynamic_cast(self) != NULL) { GFitsTableFloatCol* col = dynamic_cast(self); - if (GFitsTableColInx[0] == 1) - (*col)(GFitsTableColInx[1]) = (float)value; + if (GTuple1D2D[0] == 1) + (*col)(GTuple1D2D[1]) = (float)value; else - (*col)(GFitsTableColInx[1], GFitsTableColInx[2]) = (float)value; + (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (float)value; } else { throw GException::bad_type("GFitsTableCol::__setitem__", - "Column type does not support floating point setting."); + "Column type does not support floating point setting."); } } }; diff --git a/pyext/GFitsTableDoubleCol.i b/pyext/GFitsTableDoubleCol.i index 0b73dbe..a5ae53e 100644 --- a/pyext/GFitsTableDoubleCol.i +++ b/pyext/GFitsTableDoubleCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableDoubleCol.i - FITS table double precision column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableDoubleCol { - double __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + double __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], double value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], double value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableFloatCol.i b/pyext/GFitsTableFloatCol.i index f7de789..e0ca241 100644 --- a/pyext/GFitsTableFloatCol.i +++ b/pyext/GFitsTableFloatCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableFloatCol.i - FITS table single precision column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableFloatCol { - float __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + float __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], float value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], float value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableLongCol.i b/pyext/GFitsTableLongCol.i index 517737a..d9c0db9 100644 --- a/pyext/GFitsTableLongCol.i +++ b/pyext/GFitsTableLongCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableLongCol.i - FITS table long integer column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableLongCol { - long __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + long __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], long value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], long value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableLongLongCol.i b/pyext/GFitsTableLongLongCol.i index d34ebea..be43cba 100644 --- a/pyext/GFitsTableLongLongCol.i +++ b/pyext/GFitsTableLongLongCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableLongLongCol.i - FITS table long long integer column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableLongLongCol { - long long __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + long long __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], long long value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], long long value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableShortCol.i b/pyext/GFitsTableShortCol.i index 9cc8613..77064ef 100644 --- a/pyext/GFitsTableShortCol.i +++ b/pyext/GFitsTableShortCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableShortCol.i - FITS table short integer column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,41 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableShortCol { - short __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + short __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], short value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], short value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableStringCol.i b/pyext/GFitsTableStringCol.i index c18741e..62c6e6f 100644 --- a/pyext/GFitsTableStringCol.i +++ b/pyext/GFitsTableStringCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableStringCol.i - FITS table string column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -71,63 +71,60 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableStringCol { - std::string __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + std::string __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], std::string value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], std::string value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], GFilename value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], GFilename value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = std::string(value); + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = std::string(value); } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = std::string(value); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = std::string(value); } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableULongCol.i b/pyext/GFitsTableULongCol.i index 4759b50..6bdb350 100644 --- a/pyext/GFitsTableULongCol.i +++ b/pyext/GFitsTableULongCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableULongCol.i - FITS table unsigned long integer column class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,42 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableULongCol { - unsigned long __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + unsigned long __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && + GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], unsigned long value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], unsigned long value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GFitsTableUShortCol.i b/pyext/GFitsTableUShortCol.i index 7ee1f75..e677961 100644 --- a/pyext/GFitsTableUShortCol.i +++ b/pyext/GFitsTableUShortCol.i @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsTableUShortCol.i - FITS table unsigned short integer column class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,43 +70,42 @@ public: * find out how to implement this (e.g. via typemaps). ***************************************************************************/ %extend GFitsTableUShortCol { - unsigned short __getitem__(int GFitsTableColInx[]) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + unsigned short __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__getitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - return (*self)(GFitsTableColInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GFitsTableColInx[2] >= 0 && - GFitsTableColInx[2] < self->elements(GFitsTableColInx[1])) { - return (*self)(GFitsTableColInx[1], GFitsTableColInx[2]); + if (GTuple1D2D[2] >= 0 && + GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("__getitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } - void __setitem__(int GFitsTableColInx[], unsigned short value) { - if (GFitsTableColInx[1] < 0 || GFitsTableColInx[1] >= self->nrows()) { + void __setitem__(int GTuple1D2D[], unsigned short value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->nrows()) { throw GException::out_of_range("__setitem__()", "Row index", - GFitsTableColInx[1], self->nrows()); + GTuple1D2D[1], self->nrows()); } - if (GFitsTableColInx[0] == 1) { - (*self)(GFitsTableColInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GFitsTableColInx[2] >= 0 && GFitsTableColInx[2] < - self->elements(GFitsTableColInx[1])) { - (*self)(GFitsTableColInx[1], GFitsTableColInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->elements(GTuple1D2D[1])) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("__setitem__()", "Column index", - GFitsTableColInx[2], - self->elements(GFitsTableColInx[1])); + GTuple1D2D[2], + self->elements(GTuple1D2D[1])); } } } diff --git a/pyext/GMatrix.i b/pyext/GMatrix.i index a2bda51..230c63a 100755 --- a/pyext/GMatrix.i +++ b/pyext/GMatrix.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrix.i - General Matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -94,11 +94,11 @@ public: * @brief GMatrix class extension ***************************************************************************/ %extend GMatrix { - double __getitem__(int GTuple[2]) { - return (*self)(GTuple[0], GTuple[1]); + double __getitem__(int GTuple2D[]) { + return (*self)(GTuple2D[0], GTuple2D[1]); } - void __setitem__(int GTuple[2], double value) { - (*self)(GTuple[0], GTuple[1]) = value; + void __setitem__(int GTuple2D[], double value) { + (*self)(GTuple2D[0], GTuple2D[1]) = value; } GVector __mul__(const GVector& vector) { return ((*self) * vector); diff --git a/pyext/GMatrixSparse.i b/pyext/GMatrixSparse.i index 4479d57..b14b5f2 100644 --- a/pyext/GMatrixSparse.i +++ b/pyext/GMatrixSparse.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSparse.i - Sparse matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -108,11 +108,11 @@ public: * @brief GMatrixSparse class extension ***************************************************************************/ %extend GMatrixSparse { - double __getitem__(int GTuple[2]) { - return (*self)(GTuple[0], GTuple[1]); + double __getitem__(int GTuple2D[]) { + return (*self)(GTuple2D[0], GTuple2D[1]); } - void __setitem__(int GTuple[2], double value) { - (*self)(GTuple[0], GTuple[1]) = value; + void __setitem__(int GTuple2D[], double value) { + (*self)(GTuple2D[0], GTuple2D[1]) = value; } GVector __mul__(const GVector& vector) { return ((*self) * vector); diff --git a/pyext/GMatrixSymmetric.i b/pyext/GMatrixSymmetric.i index e8cc8ce..b251871 100644 --- a/pyext/GMatrixSymmetric.i +++ b/pyext/GMatrixSymmetric.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSymmetric.i - Symmetric matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2018 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -93,11 +93,11 @@ public: * @brief GMatrixSymmetric class extension ***************************************************************************/ %extend GMatrixSymmetric { - double __getitem__(int GTuple[2]) { - return (*self)(GTuple[0], GTuple[1]); + double __getitem__(int GTuple2D[]) { + return (*self)(GTuple2D[0], GTuple2D[1]); } - void __setitem__(int GTuple[2], double value) { - (*self)(GTuple[0], GTuple[1]) = value; + void __setitem__(int GTuple2D[], double value) { + (*self)(GTuple2D[0], GTuple2D[1]) = value; } GVector __mul__(const GVector& vector) { return ((*self) * vector); diff --git a/pyext/GResponseVectorCache.i b/pyext/GResponseVectorCache.i index 7aaf501..2bdc30a 100644 --- a/pyext/GResponseVectorCache.i +++ b/pyext/GResponseVectorCache.i @@ -38,8 +38,9 @@ * */ %include "typemaps.i" -%apply GVector *OUTPUT { GVector* value }; - +%typemap(argout) GVector *OUTPUT { + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), SWIGTYPE_p_GVector, 0 | 0); +} /***********************************************************************//** * @class GResponseVectorCache diff --git a/pyext/GRmf.i b/pyext/GRmf.i index 25ab75e..90c929b 100644 --- a/pyext/GRmf.i +++ b/pyext/GRmf.i @@ -85,11 +85,11 @@ public: * @brief GRmf class extension ***************************************************************************/ %extend GRmf { - double __getitem__(int GTuple[2]) { - return self->at(GTuple[0], GTuple[1]); + double __getitem__(int GTuple2D[]) { + return self->at(GTuple2D[0], GTuple2D[1]); } - void __setitem__(int GTuple[2], const double& value) { - self->at(GTuple[0], GTuple[1]) = value; + void __setitem__(int GTuple2D[], const double& value) { + self->at(GTuple2D[0], GTuple2D[1]) = value; } int __len__() { return (self->size()); diff --git a/pyext/GSkyMap.i b/pyext/GSkyMap.i index e625552..211aad1 100644 --- a/pyext/GSkyMap.i +++ b/pyext/GSkyMap.i @@ -31,76 +31,6 @@ /***********************************************************************//** - * @brief Tuple to index conversion to provide pixel access. - * - * The following function provides conversion between a Python tuple and - * an integer array. This allows skymap pixel access via tuples, such as in - * a[3,5,10] = 10.0 or c = a[2,9]. - ***************************************************************************/ -%{ -static int skymap_tuple(PyObject *input, int *ptr) { - if (PySequence_Check(input)) { - int size = PyObject_Length(input); - if (size > 2) { - PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); - return 0; - } - ptr[0] = size; - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem(input,i); - if (!PyInt_Check(o)) { - Py_XDECREF(o); - PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); - return 0; - } - ptr[i+1] = (int)PyInt_AsLong(o); - Py_DECREF(o); - } - return 1; - } - else { - ptr[0] = 1; - if (!PyInt_Check(input)) { - PyErr_SetString(PyExc_ValueError,"Expecting an integer"); - return 0; - } - ptr[1] = (int)PyInt_AsLong(input); - return 1; - } -} -%} - -// This is the typemap that makes use of the function defined above -%typemap(in) int GSkyMapInx[ANY](int temp[3]) { - if (!skymap_tuple($input,temp)) { - return NULL; - } - $1 = &temp[0]; -} - -// This typecheck verifies that all arguments are integers. The typecheck -// is needed for using "int GSkyMapInx" in overloaded methods. -%typemap(typecheck) int GSkyMapInx[ANY] { - $1 = 1; - if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { - PyObject *o = PySequence_GetItem($input,i); - if (!PyInt_Check(o)) { - $1 = 0; - break; - } - } - } - else { - if (!PyInt_Check($input)) { - $1 = 0; - } - } -} - - -/***********************************************************************//** * @class GSkyMap * * @brief GSkyMap class interface definition @@ -200,23 +130,23 @@ public: * GSkyDir ***************************************************************************/ %extend GSkyMap { - double __getitem__(int GSkyMapInx[]) { - if (GSkyMapInx[1] < 0 || GSkyMapInx[1] >= self->npix()) { + double __getitem__(int GTuple1D2D[]) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->npix()) { throw GException::out_of_range("GSkyMap::__getitem__(int*)", "Sky map index", - GSkyMapInx[1], self->npix()); + GTuple1D2D[1], self->npix()); } - if (GSkyMapInx[0] == 1) { - return (*self)(GSkyMapInx[1]); + if (GTuple1D2D[0] == 1) { + return (*self)(GTuple1D2D[1]); } else { - if (GSkyMapInx[2] >= 0 && GSkyMapInx[2] < self->nmaps()) { - return (*self)(GSkyMapInx[1], GSkyMapInx[2]); + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->nmaps()) { + return (*self)(GTuple1D2D[1], GTuple1D2D[2]); } else { throw GException::out_of_range("GSkyMap::__getitem__(int*)", "Sky map number", - GSkyMapInx[2], self->nmaps()); + GTuple1D2D[2], self->nmaps()); } } } @@ -225,23 +155,23 @@ public: return (*self)(pixel); } */ - void __setitem__(int GSkyMapInx[], double value) { - if (GSkyMapInx[1] < 0 || GSkyMapInx[1] >= self->npix()) { + void __setitem__(int GTuple1D2D[], double value) { + if (GTuple1D2D[1] < 0 || GTuple1D2D[1] >= self->npix()) { throw GException::out_of_range("GSkyMap::__setitem__(int*,double&)", "Sky map index", - GSkyMapInx[1], self->npix()); + GTuple1D2D[1], self->npix()); } - if (GSkyMapInx[0] == 1) { - (*self)(GSkyMapInx[1]) = value; + if (GTuple1D2D[0] == 1) { + (*self)(GTuple1D2D[1]) = value; } else { - if (GSkyMapInx[2] >= 0 && GSkyMapInx[2] < self->nmaps()) { - (*self)(GSkyMapInx[1], GSkyMapInx[2]) = value; + if (GTuple1D2D[2] >= 0 && GTuple1D2D[2] < self->nmaps()) { + (*self)(GTuple1D2D[1], GTuple1D2D[2]) = value; } else { throw GException::out_of_range("GSkyMap::__setitem__(int*,double&)", "Sky map number", - GSkyMapInx[2], self->nmaps()); + GTuple1D2D[2], self->nmaps()); } } } diff --git a/pyext/gammalib/fits.i b/pyext/gammalib/fits.i index 04279d7..e6f7704 100644 --- a/pyext/gammalib/fits.i +++ b/pyext/gammalib/fits.i @@ -47,6 +47,7 @@ namespace std { /* __ Include GammaLib typemaps __________________________________________ */ %include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i %include typemap_slices.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/gammalib/obs.i b/pyext/gammalib/obs.i index a9410e5..18f7c51 100644 --- a/pyext/gammalib/obs.i +++ b/pyext/gammalib/obs.i @@ -216,22 +216,6 @@ $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); } } -%typemap(out) GVector* { - char classname[80]; - strcpy(classname, "_p_"); - strcat(classname, result->classname().c_str()); - swig_type_info *myinfo = SWIGTYPE_p_GVector; - swig_cast_info *mycast = 0; - mycast = myinfo->cast; - while (mycast != 0) { - if (strcmp(classname, mycast->type->name) == 0) { - myinfo = mycast->type; - break; - } - mycast = mycast->next; - } - $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); -} /* __ Observation handling _______________________________________________ */ %include "GEnergy.i" diff --git a/pyext/gammalib/sky.i b/pyext/gammalib/sky.i index 2c4d38c..1bcc34e 100644 --- a/pyext/gammalib/sky.i +++ b/pyext/gammalib/sky.i @@ -49,6 +49,7 @@ namespace std { /* __ Include GammaLib typemaps __________________________________________ */ %include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i %include typemap_slices.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/gammalib/support.i b/pyext/gammalib/support.i index aa803d6..78c6e1a 100644 --- a/pyext/gammalib/support.i +++ b/pyext/gammalib/support.i @@ -46,6 +46,7 @@ /* __ Include GammaLib typemaps __________________________________________ */ %include typemap_GChatter.i %include typemap_GFilename.i +%include typemap_GTuple.i %include typemap_slices.i /* __ Include interface classes __________________________________________ */ diff --git a/pyext/typemap_GTuple.i b/pyext/typemap_GTuple.i index cb3de2e..5eb555f 100644 --- a/pyext/typemap_GTuple.i +++ b/pyext/typemap_GTuple.i @@ -36,7 +36,7 @@ * in a[3,5] = 10.0 or c = a[2,9]. A typecheck typemap is provided to allow * overloading. ***************************************************************************/ -%typemap(in) int GTuple[2] (int temp[2]) { +%typemap(in) int GTuple2D[] (int temp[2]) { if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a sequence"); return NULL; @@ -57,13 +57,70 @@ } $1 = temp; } -%typemap(typecheck) int GTuple[2] { +%typemap(typecheck) int GTuple2D[] { $1 = 1; if (PySequence_Check($input)) { - int size = PyObject_Length($input); + Py_ssize_t size = PyObject_Length($input); + for (int i = 0; i < size; ++i) { + PyObject *o = PySequence_GetItem($input,i); + if (!PyInt_Check(o)) { + $1 = 0; + break; + } + } + } + else { + if (!PyInt_Check($input)) { + $1 = 0; + } + } +} + + +/***********************************************************************//** + * @brief 1D or 2D tuple to index conversion + * + * The following typemap provides conversion between a 1-dimensional or + * or 2-dimensional Python tuple and an integer array. This allows index + * access via tuples, such as in a[3] = 10.0 or c = a[2,9]. A typecheck + * typemap is provided to allow overloading. + ***************************************************************************/ +%typemap(in) int GTuple1D2D[] (int temp[3]) { + if (PySequence_Check($input)) { + Py_ssize_t size = PyObject_Length($input); + if (size > 2) { + PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); + return NULL; + } + temp[0] = size; for (int i = 0; i < size; i++) { PyObject *o = PySequence_GetItem($input,i); if (!PyInt_Check(o)) { + Py_XDECREF(o); + PyErr_SetString(PyExc_ValueError,"Expecting a tuple of integers"); + return NULL; + } + temp[i+1] = (int)PyInt_AsLong(o); + Py_DECREF(o); + } + } + else { + temp[0] = 1; + if (!PyInt_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expecting an integer"); + return NULL; + } + temp[1] = (int)PyInt_AsLong($input); + } + $1 = temp; +} +%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) int GTuple1D2D[] { + $1 = 1; + if (PySequence_Check($input)) { + Py_ssize_t size = PyObject_Length($input); + for (int i = 0; i < size; ++i) { + PyObject *o = PySequence_GetItem($input,i); + if (!PyInt_Check(o)) { $1 = 0; break; } @@ -86,13 +143,13 @@ ***************************************************************************/ %typemap(in) int GTuple[ANY] (int temp[11]) { if (PySequence_Check($input)) { - int size = PyObject_Length($input); + Py_ssize_t size = PyObject_Length($input); if (size > 10) { PyErr_SetString(PyExc_ValueError,"Too many arguments in tuple"); return NULL; } temp[0] = size; - for (int i = 0; i < size; i++) { + for (int i = 0; i < size; ++i) { PyObject *o = PySequence_GetItem($input,i); if (!PyInt_Check(o)) { Py_XDECREF(o); @@ -102,7 +159,6 @@ temp[i+1] = (int)PyInt_AsLong(o); Py_DECREF(o); } - $1 = &temp[0]; } else { temp[0] = 1; @@ -111,14 +167,14 @@ return NULL; } temp[1] = (int)PyInt_AsLong($input); - $1 = &temp[0]; } + $1 = temp; } %typemap(typecheck) int GTuple[ANY] { $1 = 1; if (PySequence_Check($input)) { - int size = PyObject_Length($input); - for (int i = 0; i < size; i++) { + Py_ssize_t size = PyObject_Length($input); + for (int i = 0; i < size; ++i) { PyObject *o = PySequence_GetItem($input,i); if (!PyInt_Check(o)) { $1 = 0; -- libgit2 0.21.4