Mercurial > pytave
annotate oct-py-types.h @ 337:d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
* oct-py-types.cc, oct-py-types.h (pytave::make_py_bool,
pytave::make_py_complex, pytave::make_py_float, pytave::make_py_int): New
functions to construct Python numeric types.
(pytave::make_py_numeric_value): New function to construct the appropriate
Python type for a given Octave scalar value.
* octave_to_python.cc (pytave::octvalue_to_pyobj): Use make_py_numeric_value.
(pytave::octscalar_to_pyobject, pytave::python_integer_value): Delete.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Mon, 15 Aug 2016 21:53:16 -0700 |
parents | c081e30c2f64 |
children | 832ee1f14862 |
rev | line source |
---|---|
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
1 /* |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
2 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2016 Mike Miller |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
4 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
5 This file is part of Pytave. |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
6 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
7 Pytave is free software; you can redistribute it and/or modify it |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
11 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
12 Pytave is distributed in the hope that it will be useful, but WITHOUT |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
15 for more details. |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
16 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
18 along with Pytave; see the file COPYING. If not, see |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
20 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
21 */ |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
22 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
23 #if ! defined (pytave_oct_py_types_h) |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
24 #define pytave_oct_py_types_h 1 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
25 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
26 #include <Python.h> |
337
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
27 #include <complex> |
325
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
28 #include <string> |
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
29 |
336
c081e30c2f64
Overhaul Python list creation from cell array
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
30 class Cell; |
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
31 class octave_scalar_map; |
337
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
32 class octave_value; |
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
33 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
34 namespace pytave |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
35 { |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
36 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
37 PyObject * |
337
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
38 make_py_bool (bool value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
39 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
40 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
41 make_py_complex (std::complex<double> value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
42 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
43 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
44 make_py_float (double value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
45 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
46 PyObject * |
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
47 make_py_dict (const octave_scalar_map& map); |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
48 |
328
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
325
diff
changeset
|
49 int64_t |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
325
diff
changeset
|
50 extract_py_int64 (PyObject *obj); |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
325
diff
changeset
|
51 |
336
c081e30c2f64
Overhaul Python list creation from cell array
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
52 PyObject * |
337
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
53 make_py_int (int32_t value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
54 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
55 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
56 make_py_int (uint32_t value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
57 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
58 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
59 make_py_int (int64_t value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
60 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
61 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
62 make_py_int (uint64_t value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
63 |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
64 PyObject * |
336
c081e30c2f64
Overhaul Python list creation from cell array
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
65 make_py_list (const Cell& cell); |
c081e30c2f64
Overhaul Python list creation from cell array
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
66 |
337
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
67 PyObject * |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
68 make_py_numeric_value (const octave_value& value); |
d3d355dc44ad
Overhaul Python numeric type creation from Octave scalar types
Mike Miller <mtmiller@octave.org>
parents:
336
diff
changeset
|
69 |
325
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
70 std::string |
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
71 extract_py_str (PyObject *obj); |
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
72 |
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
73 PyObject * |
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
74 make_py_str (const std::string& str); |
fd5881d48238
Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents:
320
diff
changeset
|
75 |
320
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
76 } |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
77 |
c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
78 #endif |