casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PycArray.h
Go to the documentation of this file.
1 //# PycArray.h: Class to convert an Array to/from Python
2 //# Copyright (C) 2006
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: PycArray.h,v 1.4 2006/11/06 00:14:44 gvandiep Exp $
27 
28 
29 #ifndef PYRAP_PYCARRAY_H
30 #define PYRAP_PYCARRAY_H
31 
32 //# Includes
33 // include first to avoid _POSIX_C_SOURCE redefined warnings
34 #include <boost/python.hpp>
35 #include <boost/python/object.hpp>
40 #include <iostream>
41 
42 namespace casacore { namespace python {
43 
44 
45  // <summary>
46  // A class to convert an Array to/from Python objects.
47  // </summary>
48 
49  // <use visibility=export>
50  // <reviewed reviewer="" date="" tests="">
51  // </reviewed>
52 
53  // <synopsis>
54  // </synopsis>
55 
56  // Check if the PyObject is an array object.
57  Bool PycArrayCheck (PyObject* obj_ptr);
58 
59  // Check if the PyObject is an array scalar object.
60  Bool PycArrayScalarCheck (PyObject* obj_ptr);
61 
62  // Get the data type of the array scalar object.
63  // It returns TpBool, TpInt, TpFloat, or TpComplex.
64  // TpOther is returned if unrecognized.
65  DataType PycArrayScalarType (PyObject* obj_ptr);
66 
68  {
69  // Constructs an Array from a Python object.
70  // If copyData=False, the array data is only copied if needed meaning
71  // that the Array object in the ValueHolder can reference the data in
72  // Python array.
73  // That should only be used if the ValueHolder and its Array will be
74  // destructed before the Python array.
75  static ValueHolder makeArray(PyObject* obj_ptr, Bool copyData=False);
76 
77  // Construct an Array<String> from a special Python dict object.
78  static ValueHolder makeArrayFromDict (PyObject* obj_ptr);
79 
80  // Construct a scalar from an array scalar (i.e. element in array).
81  static ValueHolder makeScalar (PyObject* obj_ptr);
82  };
83 
84  // Do the actual making of the PyArrayObject.
85  // Specialize for strings.
86  // <group>
87  template <typename T>
89  template <>
91  // </group>
92 
93  // Convert Array to Python.
94  template <typename T>
96  {
98  { return makePyArrayObject (arr); }
99  static PyObject* convert (Array<T> const& c)
100  { return boost::python::incref(makeobject(c).ptr()); }
101  };
102 
103 }}
104 
105 #endif
static boost::python::object makeobject(Array< T > const &arr)
Definition: PycArray.h:97
DataType PycArrayScalarType(PyObject *obj_ptr)
Get the data type of the array scalar object.
boost::python::object makePyArrayObject(casacore::Array< T > const &arr)
Do the actual making of the PyArrayObject.
static ValueHolder makeScalar(PyObject *obj_ptr)
Construct a scalar from an array scalar (i.e.
static ValueHolder makeArrayFromDict(PyObject *obj_ptr)
Construct an Array&lt;String&gt; from a special Python dict object.
Convert Array to Python.
Definition: PycArray.h:95
std::string object(const std::string &name)
A holder for a value of any basic Casacore data type.
Definition: ValueHolder.h:67
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool PycArrayScalarCheck(PyObject *obj_ptr)
Check if the PyObject is an array scalar object.
const Bool False
Definition: aipstype.h:44
static ValueHolder makeArray(PyObject *obj_ptr, Bool copyData=False)
Constructs an Array from a Python object.
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
const Double c
Fundamental physical constants (SI units):
static PyObject * convert(Array< T > const &c)
Definition: PycArray.h:99
Bool PycArrayCheck(PyObject *obj_ptr)
A class to convert an Array to/from Python objects.
Definition: PycArrayComCC.h:35
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42