Mercurial > pytave
comparison octave_to_python.cc @ 320:c2aa34730dc9
Convert scalar struct into Python dict (fixes issue #57)
* oct-py-types.cc, oct-py-types.h: New files for conversion of objects between
Octave and Python APIs.
* Makefile.am (COMMON_SOURCE_FILES, PYTAVE_HEADER_FILES): Include new files.
* octave_to_python.cc (pytave::octvalue_to_pyobj): Add case to handle scalar
struct instead of struct array.
* @pyobject/pyobject.m: Add %!tests for pyobject from scalar struct and %!error
tests for failure with struct array.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 11 Aug 2016 16:12:35 -0700 |
parents | a133564f4af7 |
children | fd5881d48238 |
comparison
equal
deleted
inserted
replaced
319:1231dc878600 | 320:c2aa34730dc9 |
---|---|
35 | 35 |
36 #include <iostream> | 36 #include <iostream> |
37 #include "arrayobjectdefs.h" | 37 #include "arrayobjectdefs.h" |
38 #include "exceptions.h" | 38 #include "exceptions.h" |
39 #include "octave_to_python.h" | 39 #include "octave_to_python.h" |
40 #include "oct-py-types.h" | |
40 | 41 |
41 using namespace boost::python; | 42 using namespace boost::python; |
42 | 43 |
43 namespace pytave | 44 namespace pytave |
44 { | 45 { |
330 else if (octvalue.is_cell ()) | 331 else if (octvalue.is_cell ()) |
331 octcell_to_pyobject (py_object, octvalue.cell_value ()); | 332 octcell_to_pyobject (py_object, octvalue.cell_value ()); |
332 else if (octvalue.is_numeric_type () || octvalue.is_string () | 333 else if (octvalue.is_numeric_type () || octvalue.is_string () |
333 || octvalue.is_bool_type ()) | 334 || octvalue.is_bool_type ()) |
334 octvalue_to_pyarr (py_object, octvalue); | 335 octvalue_to_pyarr (py_object, octvalue); |
335 else if (octvalue.is_map ()) | 336 else if (octvalue.is_map () && octvalue.numel () == 1) |
336 octmap_to_pyobject (py_object, octvalue.map_value ()); | 337 { |
338 PyObject *obj = make_py_dict (octvalue.scalar_map_value ()); | |
339 py_object = object (handle<PyObject> (obj)); | |
340 } | |
337 else if (octvalue.is_object () && octvalue.class_name () == "pyobject") | 341 else if (octvalue.is_object () && octvalue.class_name () == "pyobject") |
338 { | 342 { |
339 octave_value_list tmp = feval ("getid", ovl (octvalue), 1); | 343 octave_value_list tmp = feval ("getid", ovl (octvalue), 1); |
340 std::string hexid = tmp(0).string_value (); | 344 std::string hexid = tmp(0).string_value (); |
341 // FIXME: added a messy ref to __InOct__ in __main__, find a better way | 345 // FIXME: added a messy ref to __InOct__ in __main__, find a better way |