Mercurial > pytave
annotate __py_struct_from_dict__.cc @ 402:c4b78e449c62
maint: indent functions declared in the pytave namespace
* oct-py-eval.cc, oct-py-eval.h, oct-py-types.cc, oct-py-types.h,
oct-py-util.cc, oct-py-util.h: Indent functions declared in the pytave
namespace, adjust line wrap where necessary.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 28 Apr 2017 14:07:57 -0700 |
parents | 668fcb0f68ef |
children | 3644df6564bc |
rev | line source |
---|---|
345
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
1 /* |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
2 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2016 Mike Miller |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
4 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
5 This file is part of Pytave. |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
6 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
7 Pytave is free software: you can redistribute it and/or modify it |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
11 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
12 Pytave is distributed in the hope that it will be useful, but WITHOUT |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
15 for more details. |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
16 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
18 along with Pytave; see the file COPYING. If not, see |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
20 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
21 */ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
22 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
24 # include <config.h> |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
25 #endif |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
26 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
27 #include <Python.h> |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
28 #include <octave/oct.h> |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
29 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
30 #define PYTAVE_DO_DECLARE_SYMBOL |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
31 #include "arrayobjectdefs.h" |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
32 #include "exceptions.h" |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
33 #include "oct-py-types.h" |
358
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
34 #include "oct-py-util.h" |
345
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
35 #include "octave_to_python.h" |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
36 |
373
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
37 DEFUN_DLD (__py_class_name__, args, , |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
38 "-*- texinfo -*-\n\ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
39 @deftypefn {} {} __py_class_name__ (@var{obj})\n\ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
40 Return the name of the class of the Python object @var{obj}.\n\ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
41 \n\ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
42 This is a private internal function not intended for direct use.\n\ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
43 @end deftypefn") |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
44 { |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
45 if (args.length () != 1) |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
46 print_usage (); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
47 |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
48 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
49 error ("__py_class_name__: argument must be a valid Python object"); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
50 |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
51 Py_Initialize (); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
52 |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
53 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
54 std::string name = pytave::py_object_class_name (obj); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
55 Py_DECREF (obj); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
56 |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
57 return ovl (name); |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
58 } |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
59 |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
60 /* |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
61 %!assert (__py_class_name__ (pyeval ("None")), "NoneType") |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
62 %!assert (__py_class_name__ (pyeval ("'Octave'")), "str") |
375
d0a7f66393fc
Fix __py_class_name__ tests to work with Python 2
Mike Miller <mtmiller@octave.org>
parents:
374
diff
changeset
|
63 %!assert (__py_class_name__ (pyeval ("{}")), "dict") |
373
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
64 %!assert (__py_class_name__ (pyeval ("[]")), "list") |
375
d0a7f66393fc
Fix __py_class_name__ tests to work with Python 2
Mike Miller <mtmiller@octave.org>
parents:
374
diff
changeset
|
65 %!assert (__py_class_name__ (pyeval ("()")), "tuple") |
373
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
66 %!assert (__py_class_name__ (pyeval ("__import__('array').array('d')")), "array.array") |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
67 |
386
668fcb0f68ef
Fix extraction of class name for Python types without a module (fixes issue #79)
Mike Miller <mtmiller@octave.org>
parents:
375
diff
changeset
|
68 %% Test an anonymous class with its __module__ property set to None |
668fcb0f68ef
Fix extraction of class name for Python types without a module (fixes issue #79)
Mike Miller <mtmiller@octave.org>
parents:
375
diff
changeset
|
69 %!assert (__py_class_name__ (pyeval ("[[t() for t.__module__ in (None,)][0] for t in (type('foo', (), {}),)][0]")), "foo") |
668fcb0f68ef
Fix extraction of class name for Python types without a module (fixes issue #79)
Mike Miller <mtmiller@octave.org>
parents:
375
diff
changeset
|
70 |
373
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
71 %!error __py_class_name__ () |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
72 %!error __py_class_name__ (1) |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
73 %!error __py_class_name__ (1, 2) |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
74 */ |
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
368
diff
changeset
|
75 |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
76 DEFUN_DLD (__py_int64_scalar_value__, args, nargout, |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
77 "-*- texinfo -*-\n\ |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
78 @deftypefn {} {} __py_int64_scalar_value__ (@var{x})\n\ |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
79 Extract a scalar int64 value from the Python integer @var{x}.\n\ |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
80 \n\ |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
81 This is a private internal function not intended for direct use.\n\ |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
82 @end deftypefn") |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
83 { |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
84 if (args.length () != 1) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
85 print_usage (); |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
86 |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
87 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
88 error ("pyobject.int64: argument must be a Python object"); |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
89 |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
90 Py_Initialize (); |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
91 |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
92 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
93 if (! obj) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
94 error ("pyobject.int64: argument must be a valid Python object"); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
95 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
96 octave_int64 retval; |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
97 |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
98 try |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
99 { |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
100 retval = pytave::extract_py_int64 (obj); |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
101 } |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
102 catch (pytave::object_convert_exception const &) |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
103 { |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
104 error ("pyobject.int64: argument must be a Python int or long object"); |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
105 } |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
106 catch (boost::python::error_already_set const &) |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
107 { |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
108 std::string message = pytave::fetch_exception_message (); |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
109 error ("pyobject.int64: %s", message.c_str ()); |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
110 } |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
111 Py_DECREF (obj); |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
112 |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
113 return ovl (retval); |
356
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
114 } |
6cd581661176
pyobject.int64: New method to convert integer object to Octave int64
Mike Miller <mtmiller@octave.org>
parents:
345
diff
changeset
|
115 |
374
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
116 /* |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
117 %!assert (__py_int64_scalar_value__ (pyobject (pyeval ("0"))), int64 (0)) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
118 %!assert (__py_int64_scalar_value__ (pyobject (pyeval ("2**62"))), int64 (2^62)) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
119 %!assert (__py_int64_scalar_value__ (pyobject (pyeval ("-2**62"))), int64 (-2^62)) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
120 %!assert (__py_int64_scalar_value__ (pyobject (pyeval ("2**128"))), intmax ("int64")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
121 %!assert (__py_int64_scalar_value__ (pyobject (pyeval ("-2**128"))), intmin ("int64")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
122 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
123 %!error __py_int64_scalar_value__ () |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
124 %!error __py_int64_scalar_value__ (1) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
125 %!error __py_int64_scalar_value__ (pyeval ("None")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
126 %!error __py_int64_scalar_value__ (1, 2) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
127 */ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
128 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
129 DEFUN_DLD (__py_uint64_scalar_value__, args, nargout, |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
130 "-*- texinfo -*-\n\ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
131 @deftypefn {} {} __py_uint64_scalar_value__ (@var{x})\n\ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
132 Extract a scalar uint64 value from the Python integer @var{x}.\n\ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
133 \n\ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
134 This is a private internal function not intended for direct use.\n\ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
135 @end deftypefn") |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
136 { |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
137 if (args.length () != 1) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
138 print_usage (); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
139 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
140 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
141 error ("pyobject.uint64: argument must be a Python object"); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
142 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
143 Py_Initialize (); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
144 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
145 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
146 if (! obj) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
147 error ("pyobject.uint64: argument must be a valid Python object"); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
148 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
149 octave_uint64 retval; |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
150 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
151 try |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
152 { |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
153 retval = pytave::extract_py_uint64 (obj); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
154 } |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
155 catch (pytave::object_convert_exception const &) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
156 { |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
157 error ("pyobject.uint64: argument must be a Python int or long object"); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
158 } |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
159 catch (boost::python::error_already_set const &) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
160 { |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
161 std::string message = pytave::fetch_exception_message (); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
162 error ("pyobject.uint64: %s", message.c_str ()); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
163 } |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
164 Py_DECREF (obj); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
165 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
166 return ovl (retval); |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
167 } |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
168 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
169 /* |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
170 %!assert (__py_uint64_scalar_value__ (pyobject (pyeval ("0"))), uint64 (0)) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
171 %!assert (__py_uint64_scalar_value__ (pyobject (pyeval ("2**62"))), uint64 (2^62)) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
172 %!assert (__py_uint64_scalar_value__ (pyobject (pyeval ("2**128"))), intmax ("uint64")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
173 %!assert (__py_uint64_scalar_value__ (pyobject (pyeval ("-2**128"))), intmin ("uint64")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
174 |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
175 %!error __py_uint64_scalar_value__ () |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
176 %!error __py_uint64_scalar_value__ (1) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
177 %!error __py_uint64_scalar_value__ (pyeval ("None")) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
178 %!error __py_uint64_scalar_value__ (1, 2) |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
179 */ |
d362cdd1ddeb
pyobject: add conversion methods for single, intX, and uintX types
Mike Miller <mtmiller@octave.org>
parents:
373
diff
changeset
|
180 |
368
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
181 DEFUN_DLD (__py_is_none__, args, nargout, |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
182 "-*- texinfo -*-\n\ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
183 @deftypefn {} {} __py_is_none__ (@var{x})\n\ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
184 Check whether the Python object @var{obj} is the @code{None} object.\n\ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
185 \n\ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
186 This is a private internal function not intended for direct use.\n\ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
187 @end deftypefn") |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
188 { |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
189 if (args.length () != 1) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
190 print_usage (); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
191 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
192 Py_Initialize (); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
193 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
194 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
195 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
196 bool retval = (obj && (obj == Py_None)); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
197 Py_XDECREF (obj); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
198 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
199 return ovl (retval); |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
200 } |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
201 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
202 /* |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
203 %!assert (__py_is_none__ (pyobject ())) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
204 %!assert (__py_is_none__ (pyeval ("None"))) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
205 %!assert (! __py_is_none__ (1)) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
206 %!assert (! __py_is_none__ ("None")) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
207 %!assert (! __py_is_none__ (pyobject (1))) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
208 %!assert (! __py_is_none__ (pyobject ("None"))) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
209 |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
210 %!error __py_is_none__ () |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
211 %!error __py_is_none__ (1, 2) |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
212 */ |
4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
213 |
358
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
214 DEFUN_DLD (__py_isinstance__, args, nargout, |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
215 "-*- texinfo -*-\n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
216 @deftypefn {} {} __py_isinstance__ (@var{x})\n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
217 Check whether the Python object @var{obj} is an instance of a Python type\n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
218 specified by the string @var{type}.\n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
219 \n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
220 This is a private internal function not intended for direct use.\n\ |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
221 @end deftypefn") |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
222 { |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
223 octave_value_list retval; |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
224 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
225 int nargin = args.length (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
226 if (nargin != 2) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
227 { |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
228 print_usage (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
229 return retval; |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
230 } |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
231 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
232 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
233 error ("pyobject.isa: OBJ must be a Python object"); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
234 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
235 if (! args(1).is_string ()) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
236 error ("pyobject.isa: TYPE must be a string naming a Python type (py.*)"); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
237 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
238 std::string typestr = args(1).string_value (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
239 if (! ((typestr.size () > 3) && (typestr.compare (0, 3, "py.") == 0))) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
240 error ("pyobject.isa: TYPE must be a string naming a Python type (py.*)"); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
241 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
242 typestr = typestr.substr (3); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
243 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
244 Py_Initialize (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
245 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
246 try |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
247 { |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
248 // FIXME: PyObject *obj = look up stored pyobject reference (args(0)); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
249 boost::python::object arg; |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
250 pytave::octvalue_to_pyobj (arg, args(0)); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
251 PyObject *obj = arg.ptr (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
252 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
253 PyObject *type = pytave::py_find_type (typestr); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
254 retval(0) = pytave::py_isinstance (obj, type); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
255 Py_XDECREF (type); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
256 } |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
257 catch (pytave::object_convert_exception const &) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
258 { |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
259 error ("pyobject.isa: error in return value type conversion"); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
260 } |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
261 catch (boost::python::error_already_set const &) |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
262 { |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
263 std::string message = pytave::fetch_exception_message (); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
264 error ("pyobject.isa: %s", message.c_str ()); |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
265 } |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
266 |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
267 return retval; |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
268 } |
d41fc23d4b9f
pyobject.isa: New overload method to handle Python types (fixes issue #49)
Mike Miller <mtmiller@octave.org>
parents:
356
diff
changeset
|
269 |
362
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
270 DEFUN_DLD (__py_objstore_del__, args, nargout, |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
271 "-*- texinfo -*-\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
272 @deftypefn {} {} __py_objstore_del__ (@var{key})\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
273 Delete the Python object stored under @var{key} from the object store.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
274 \n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
275 This is a private internal function not intended for direct use.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
276 @end deftypefn") |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
277 { |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
278 if (args.length () != 1) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
279 print_usage (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
280 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
281 Py_Initialize (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
282 uint64_t key = args(0).xuint64_scalar_value ("__py_objstore_del__: KEY must be an integer"); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
283 pytave::py_objstore_del (key); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
284 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
285 return ovl (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
286 } |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
287 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
288 DEFUN_DLD (__py_objstore_get__, args, nargout, |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
289 "-*- texinfo -*-\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
290 @deftypefn {} {} __py_objstore_get__ (@var{key})\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
291 Get the Python object stored under @var{key} from the object store.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
292 \n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
293 This is a private internal function not intended for direct use.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
294 @end deftypefn") |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
295 { |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
296 if (args.length () != 1) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
297 print_usage (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
298 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
299 Py_Initialize (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
300 uint64_t key = args(0).xuint64_scalar_value ("__py_objstore_get__: KEY must be an integer"); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
301 PyObject *obj = pytave::py_objstore_get (key); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
302 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
303 if (! obj) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
304 error ("__py_objstore_get__: no existing Python object found for key %ju", key); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
305 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
306 octave_value retval = pytave::pyobject_wrap_object (obj); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
307 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
308 return ovl (retval); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
309 } |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
310 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
311 DEFUN_DLD (__py_objstore_put__, args, nargout, |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
312 "-*- texinfo -*-\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
313 @deftypefn {} {} __py_objstore_put__ (@var{value})\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
314 Convert @var{value} to a Python value and store in the object store.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
315 \n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
316 This is a private internal function not intended for direct use.\n\ |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
317 @end deftypefn") |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
318 { |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
319 if (args.length () != 1) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
320 print_usage (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
321 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
322 Py_Initialize (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
323 boost::python::numeric::array::set_module_and_type ("numpy", "ndarray"); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
324 _import_array (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
325 // FIXME: PyObject *obj = convert argument to Python (args(0)); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
326 PyObject *obj = 0; |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
327 try |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
328 { |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
329 boost::python::object arg; |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
330 pytave::octvalue_to_pyobj (arg, args(0)); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
331 obj = arg.ptr (); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
332 Py_INCREF (obj); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
333 } |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
334 catch (pytave::value_convert_exception const &) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
335 { |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
336 } |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
337 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
338 if (! obj) |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
339 error ("__py_objstore_put__: VALUE must be convertible to a Python value"); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
340 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
341 uint64_t key = pytave::py_objstore_put (obj); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
342 Py_DECREF (obj); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
343 |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
344 return ovl (octave_uint64 (key)); |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
345 } |
b0677c492655
Overhaul Python object storage and wrapping in pyobject
Mike Miller <mtmiller@octave.org>
parents:
358
diff
changeset
|
346 |
365
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
347 DEFUN_DLD (__py_string_value__, args, nargout, |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
348 "-*- texinfo -*-\n\ |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
349 @deftypefn {} {} __py_string_value__ (@var{obj})\n\ |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
350 Return the string value or representation of the Python object @var{obj}.\n\ |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
351 \n\ |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
352 This is a private internal function not intended for direct use.\n\ |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
353 @end deftypefn") |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
354 { |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
355 if (args.length () != 1) |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
356 print_usage (); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
357 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
358 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
359 error ("pyobject.char: argument must be a valid Python object"); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
360 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
361 Py_Initialize (); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
362 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
363 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
364 if (! obj) |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
365 error ("pyobject.char: argument must be a valid Python object"); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
366 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
367 std::string str; |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
368 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
369 if (PyBytes_Check (obj) || PyUnicode_Check (obj)) |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
370 str = pytave::extract_py_str (obj); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
371 else if (Py_TYPE (obj)->tp_str != NULL) |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
372 { |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
373 PyObject *s = PyObject_Str (obj); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
374 str = pytave::extract_py_str (s); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
375 Py_DECREF (s); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
376 } |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
377 else |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
378 { |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
379 Py_DECREF (obj); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
380 error ("pyobject.char: cannot convert Python object to string"); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
381 } |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
382 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
383 Py_DECREF (obj); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
384 |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
385 return ovl (str); |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
386 } |
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
362
diff
changeset
|
387 |
345
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
388 DEFUN_DLD (__py_struct_from_dict__, args, nargout, |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
389 "-*- texinfo -*-\n\ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
390 @deftypefn {} {} __py_struct_from_dict__ (@var{dict})\n\ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
391 Extract a scalar struct from the Python dict @var{dict}.\n\ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
392 \n\ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
393 This is a private internal function not intended for direct use.\n\ |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
394 @end deftypefn") |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
395 { |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
396 octave_value_list retval; |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
397 std::string id; |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
398 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
399 int nargin = args.length (); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
400 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
401 if (nargin != 1) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
402 { |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
403 print_usage (); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
404 return retval; |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
405 } |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
406 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
407 if (! (args(0).is_object () && args(0).class_name () == "pyobject")) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
408 error ("pyobject.struct: argument must be a Python object"); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
409 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
410 Py_Initialize (); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
411 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
412 try |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
413 { |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
414 // FIXME: PyObject *obj = look up stored pyobject reference (args(0)); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
415 boost::python::object arg; |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
416 pytave::octvalue_to_pyobj (arg, args(0)); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
417 PyObject *obj = arg.ptr (); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
418 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
419 retval(0) = pytave::extract_py_scalar_map (obj); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
420 } |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
421 catch (pytave::object_convert_exception const &) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
422 { |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
423 error ("pyobject.struct: error in return value type conversion"); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
424 } |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
425 catch (boost::python::error_already_set const &) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
426 { |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
427 std::string message = pytave::fetch_exception_message (); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
428 error ("pyobject.struct: %s", message.c_str ()); |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
429 } |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
430 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
431 return retval; |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
432 } |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
433 |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
434 /* |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
435 ## No test needed for internal helper function. |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
436 %!assert (1) |
baff3b90dcb1
__py_struct_from_dict__: new private compiled conversion function
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
437 */ |