26 #if defined (HAVE_CONFIG_H)
104 std::string
type (
void)
const {
return "<invalid>"; }
130 std::string
type (
void)
const {
return "<internal>"; }
169 const std::string&
file =
"",
170 const std::string& =
"")
195 std::string
type (
void)
const {
return "simple"; }
216 bool save_binary (std::ostream& os,
bool save_as_floats);
221 bool save_as_floats);
226 void print_raw (std::ostream& os,
bool pr_as_read_syntax,
227 int current_print_indent_level)
const;
245 const std::string&
file =
"",
246 const std::string& =
"")
251 const std::list<std::string>& parentage);
262 std::string
type (
void)
const {
return "scopedfunction"; }
289 bool save_binary (std::ostream& os,
bool save_as_floats);
294 bool save_as_floats);
299 void print_raw (std::ostream&,
bool pr_as_read_syntax,
300 int current_print_indent_level)
const;
325 const std::string&
file =
"",
326 const std::string& =
"")
334 std::string
type (
void)
const {
return "nested"; }
363 bool save_binary (std::ostream& os,
bool save_as_floats);
368 bool save_as_floats);
373 void print_raw (std::ostream&,
bool pr_as_read_syntax,
374 int current_print_indent_level)
const;
390 const std::string&
file =
"",
391 const std::string& octaveroot =
"")
409 bool is_nested (
const std::shared_ptr<stack_frame>& frame)
const
479 const std::string&
file,
488 const std::string& meth_nm);
491 const std::string& class_nm,
492 const std::string& meth_nm);
495 const std::string& class_nm,
496 const std::string& meth_nm);
507 std::string
type (
void)
const {
return "classsimple"; }
554 bool save_binary (std::ostream& os,
bool save_as_floats);
559 bool save_as_floats);
564 void print_raw (std::ostream&,
bool pr_as_read_syntax,
565 int current_print_indent_level)
const;
632 std::string
type (
void)
const {
return "anonymous"; }
659 bool save_binary (std::ostream& os,
bool save_as_floats);
664 bool save_as_floats);
669 void print_raw (std::ostream&,
bool pr_as_read_syntax,
670 int current_print_indent_level)
const;
675 bool parse (
const std::string& fcn_text);
703 const std::shared_ptr<stack_frame>&
stack_context = std::shared_ptr<stack_frame> ());
773 error (
"invalid function handle, unable to find function for @%s",
779 std::string type_str =
type ();
780 error (
"invalid conversion from %s handle to weak nestead handle",
786 std::string type_str =
type ();
787 error (
"invalid conversion from %s handle to weak anonymous handle",
793 const std::list<octave_value_list>& idx,
802 int tmp_nargout = (
type.length () > 1 && nargout == 0) ? 1 : nargout;
804 retval =
call (tmp_nargout, idx.front ());
810 error (
"function handle cannot be indexed with %c",
type[0]);
821 retval = retval(0).next_subsref (nargout,
type, idx);
829 std::ostringstream buf;
884 std::string obj_type =
type ();
887 (
"Octave:load-save-unavailable",
888 "%s: loading %s files not available in this version of Octave",
889 obj_type.c_str (), file_type);
894 std::string obj_type =
type ();
897 (
"Octave:load-save-unavailable",
898 "%s: saving %s files not available in this version of Octave",
899 obj_type.c_str (), file_type);
904 std::string htype =
type ();
906 warning (
"%s for %s handles with %s format is not implemented",
907 op, htype.c_str (), fmt);
913 error (
"invalid call to invalid function handle");
929 m.setfield (
"type",
type ());
930 m.setfield (
"file",
"");
962 std::size_t pos =
m_name.find (
'.');
964 if (pos != std::string::npos)
985 std::size_t end = pos;
987 std::vector<std::string> idx_elts;
991 end =
m_name.find (
'.', beg);
993 idx_elts.push_back (
m_name.substr (beg, end-beg));
995 if (end == std::string::npos)
1001 std::size_t n_elts = idx_elts.size ();
1003 bool have_object =
false;
1010 partial_expr_val = interp.
varval (idx_elts[0]);
1023 std::list<octave_value_list> arg_list;
1025 for (std::size_t i = 1; i < n_elts; i++)
1033 arg_list.push_back (
ovl (idx_elts[i]));
1067 arg_list.push_back (
ovl (idx_elts[i]));
1068 arg_list.push_back (args);
1070 return partial_expr_val.
subsref (
type, arg_list, nargout);
1081 fcn_to_call = partial_expr_val;
1098 fcn_to_call =
m_fcn;
1112 fcn_to_call = ov_fcn;
1121 fcn_to_call = ov_fcn;
1128 return interp.
feval (fcn_to_call, args, nargout);
1190 m.setfield (
"type",
type ());
1192 m.setfield (
"file",
file ());
1201 std::string fnm =
file ();
1203 os <<
"# path: " << fnm <<
"\n";
1205 os <<
"# subtype: " <<
type () <<
"\n";
1223 std::ostringstream nmbuf;
1231 std::string buf_str = nmbuf.str ();
1232 int32_t tmp = buf_str.length ();
1233 os.write (
reinterpret_cast<char *
> (&tmp), 4);
1234 os.write (buf_str.c_str (), buf_str.length ());
1248 #if defined (HAVE_HDF5)
1253 #if defined (HAVE_HDF5_18)
1257 group_hid = H5Gcreate (loc_id, name, 0);
1263 space_hid = data_hid = type_hid = -1;
1266 type_hid = H5Tcopy (H5T_C_S1);
1267 H5Tset_size (type_hid,
m_name.length () + 1);
1270 H5Gclose (group_hid);
1277 space_hid = H5Screate_simple (0, hdims,
nullptr);
1280 H5Tclose (type_hid);
1281 H5Gclose (group_hid);
1284 #if defined (HAVE_HDF5_18)
1285 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
1289 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
1296 H5Sclose (space_hid);
1297 H5Tclose (type_hid);
1298 H5Gclose (group_hid);
1301 H5Dclose (data_hid);
1308 H5Sclose (space_hid);
1310 hdims[1] = octaveroot.length ();
1311 space_hid = H5Screate_simple (0, hdims,
nullptr);
1314 H5Tclose (type_hid);
1315 H5Gclose (group_hid);
1319 H5Tclose (type_hid);
1320 type_hid = H5Tcopy (H5T_C_S1);
1321 H5Tset_size (type_hid, octaveroot.length () + 1);
1323 #if defined (HAVE_HDF5_18)
1324 a_id = H5Acreate (group_hid,
"OCTAVEROOT", type_hid, space_hid,
1327 a_id = H5Acreate (group_hid,
"OCTAVEROOT", type_hid, space_hid,
1333 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0);
1339 H5Sclose (space_hid);
1340 H5Tclose (type_hid);
1341 H5Gclose (group_hid);
1345 H5Sclose (space_hid);
1347 hdims[1] = fpath.length ();
1348 space_hid = H5Screate_simple (0, hdims,
nullptr);
1351 H5Tclose (type_hid);
1352 H5Gclose (group_hid);
1356 H5Tclose (type_hid);
1357 type_hid = H5Tcopy (H5T_C_S1);
1358 H5Tset_size (type_hid, fpath.length () + 1);
1360 #if defined (HAVE_HDF5_18)
1361 a_id = H5Acreate (group_hid,
"FILE", type_hid, space_hid,
1364 a_id = H5Acreate (group_hid,
"FILE", type_hid, space_hid,
1370 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0);
1377 H5Sclose (space_hid);
1378 H5Tclose (type_hid);
1379 H5Gclose (group_hid);
1385 octave_unused_parameter (loc_id);
1386 octave_unused_parameter (name);
1399 #if defined (HAVE_HDF5)
1403 octave_unused_parameter (group_hid);
1404 octave_unused_parameter (space_hid);
1405 octave_unused_parameter (type_hid);
1411 octave_unused_parameter (group_hid);
1412 octave_unused_parameter (space_hid);
1413 octave_unused_parameter (type_hid);
1421 int current_print_indent_level)
const
1424 current_print_indent_level);
1442 const std::string& name,
1443 const std::list<std::string>& parentage)
1484 m.setfield (
"type",
type ());
1485 m.setfield (
"file",
file ());
1496 std::string fnm =
file ();
1498 os <<
"# path: " << fnm <<
"\n";
1500 os <<
"# subtype: " <<
type () <<
"\n";
1528 std::ostringstream nmbuf;
1530 std::string fnm =
file ();
1535 std::string buf_str = nmbuf.str ();
1536 int32_t
len = buf_str.length ();
1537 os.write (
reinterpret_cast<char *
> (&
len), 4);
1538 os.write (buf_str.c_str (), buf_str.length ());
1566 #if defined (HAVE_HDF5)
1572 octave_unused_parameter (loc_id);
1573 octave_unused_parameter (name);
1579 octave_unused_parameter (loc_id);
1580 octave_unused_parameter (name);
1593 #if defined (HAVE_HDF5)
1599 octave_unused_parameter (group_hid);
1600 octave_unused_parameter (space_hid);
1601 octave_unused_parameter (type_hid);
1607 octave_unused_parameter (group_hid);
1608 octave_unused_parameter (space_hid);
1609 octave_unused_parameter (type_hid);
1617 bool pr_as_read_syntax,
1618 int current_print_indent_level)
const
1621 current_print_indent_level);
1649 if (pos != std::string::npos)
1650 dir_name = dir_name.substr (0, pos);
1651 else if (dir_name ==
"private")
1664 std::string primary_parent_name =
m_parentage.back ();
1679 if (file_name.substr (0, oct_home.size ()) == oct_home)
1680 file_name = file_name.substr (oct_home.size ());
1696 m.setfield (
"type",
type ());
1697 m.setfield (
"file",
"");
1716 octave_unused_parameter (os);
1725 octave_unused_parameter (is);
1731 bool save_as_floats)
1735 octave_unused_parameter (os);
1736 octave_unused_parameter (save_as_floats);
1746 octave_unused_parameter (is);
1747 octave_unused_parameter (swap);
1748 octave_unused_parameter (fmt);
1754 const char *name,
bool)
1756 #if defined (HAVE_HDF5)
1760 octave_unused_parameter (loc_id);
1761 octave_unused_parameter (name);
1767 octave_unused_parameter (loc_id);
1768 octave_unused_parameter (name);
1781 #if defined (HAVE_HDF5)
1785 octave_unused_parameter (group_hid);
1786 octave_unused_parameter (space_hid);
1787 octave_unused_parameter (type_hid);
1793 octave_unused_parameter (group_hid);
1794 octave_unused_parameter (space_hid);
1795 octave_unused_parameter (type_hid);
1803 bool pr_as_read_syntax,
1804 int current_print_indent_level)
const
1807 current_print_indent_level);
1827 return oct_usr_fcn->
execute (tw, nargout, args);
1857 return oct_usr_fcn->
execute (tw, nargout, args);
1864 return frames ? frames->workspace () :
octave_value ();
1878 const std::string& meth_nm)
1880 m_dispatch_class (class_nm)
1884 const std::string& class_nm,
1885 const std::string& meth_nm)
1887 m_dispatch_class (class_nm)
1892 const std::string& class_nm,
1893 const std::string& meth_nm)
1895 m_dispatch_class (class_nm)
1908 return interp.
feval (
m_fcn, tmp_args, nargout);
1933 m.setfield (
"type",
type ());
1934 m.setfield (
"file",
"");
1949 octave_unused_parameter (os);
1958 octave_unused_parameter (is);
1964 bool save_as_floats)
1968 octave_unused_parameter (os);
1969 octave_unused_parameter (save_as_floats);
1979 octave_unused_parameter (is);
1980 octave_unused_parameter (swap);
1981 octave_unused_parameter (fmt);
1987 const char *name,
bool)
1989 #if defined (HAVE_HDF5)
1993 octave_unused_parameter (loc_id);
1994 octave_unused_parameter (name);
2000 octave_unused_parameter (loc_id);
2001 octave_unused_parameter (name);
2014 #if defined (HAVE_HDF5)
2018 octave_unused_parameter (group_hid);
2019 octave_unused_parameter (space_hid);
2020 octave_unused_parameter (type_hid);
2026 octave_unused_parameter (group_hid);
2027 octave_unused_parameter (space_hid);
2028 octave_unused_parameter (type_hid);
2036 bool pr_as_read_syntax,
2037 int current_print_indent_level)
const
2040 current_print_indent_level);
2061 std::ostringstream buf;
2063 m.setfield (
"function", buf.str ());
2065 m.setfield (
"type",
type ());
2066 m.setfield (
"file",
"");
2068 m.setfield (
"within_file_path",
"");
2089 os <<
"# length: " << varlen <<
"\n";
2093 if (!
save_text_data (os, nm_val.second, nm_val.first,
false, 0))
2094 return ! os.fail ();
2115 std::streampos pos = is.tellg ();
2141 error (
"load: failed to load anonymous function handle");
2160 bool save_as_floats)
2167 std::ostringstream nmbuf;
2173 nmbuf <<
' ' << varlen;
2175 std::string buf_str = nmbuf.str ();
2176 int32_t tmp = buf_str.length ();
2177 os.write (
reinterpret_cast<char *
> (&tmp), 4);
2178 os.write (buf_str.c_str (), buf_str.length ());
2180 std::ostringstream buf;
2182 std::string stmp = buf.str ();
2183 tmp = stmp.length ();
2184 os.write (
reinterpret_cast<char *
> (&tmp), 4);
2185 os.write (stmp.c_str (), stmp.length ());
2192 "", 0, save_as_floats))
2193 return ! os.fail ();
2208 if (
m_name.length () > anl)
2210 std::istringstream nm_is (
m_name.substr (anl));
2222 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
2230 is.read (ctmp2, tmp);
2255 error (
"load: failed to load anonymous function handle");
2262 return parse (ctmp2);
2269 bool save_as_floats)
2271 #if defined (HAVE_HDF5)
2276 #if defined (HAVE_HDF5_18)
2280 group_hid = H5Gcreate (loc_id, name, 0);
2286 space_hid = data_hid = type_hid = -1;
2289 type_hid = H5Tcopy (H5T_C_S1);
2290 H5Tset_size (type_hid,
m_name.length () + 1);
2293 H5Gclose (group_hid);
2300 space_hid = H5Screate_simple (0, hdims,
nullptr);
2303 H5Tclose (type_hid);
2304 H5Gclose (group_hid);
2307 #if defined (HAVE_HDF5_18)
2308 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
2312 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
2319 H5Sclose (space_hid);
2320 H5Tclose (type_hid);
2321 H5Gclose (group_hid);
2324 H5Dclose (data_hid);
2326 std::ostringstream buf;
2328 std::string stmp = buf.str ();
2331 H5Tset_size (type_hid, stmp.length () + 1);
2334 H5Sclose (space_hid);
2335 H5Gclose (group_hid);
2339 #if defined (HAVE_HDF5_18)
2340 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
2344 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
2351 H5Sclose (space_hid);
2352 H5Tclose (type_hid);
2353 H5Gclose (group_hid);
2357 H5Dclose (data_hid);
2368 #if defined (HAVE_HDF5_18)
2369 a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
H5T_NATIVE_IDX, as_id,
2373 a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
H5T_NATIVE_IDX, as_id,
2390 #if defined (HAVE_HDF5_18)
2391 data_hid = H5Gcreate (group_hid,
"symbol table",
2395 data_hid = H5Gcreate (group_hid,
"symbol table", 0);
2399 H5Sclose (space_hid);
2400 H5Tclose (type_hid);
2401 H5Gclose (group_hid);
2408 "",
false, save_as_floats))
2412 H5Gclose (data_hid);
2415 H5Sclose (space_hid);
2416 H5Tclose (type_hid);
2417 H5Gclose (group_hid);
2423 octave_unused_parameter (loc_id);
2424 octave_unused_parameter (name);
2425 octave_unused_parameter (save_as_floats);
2438 #if defined (HAVE_HDF5)
2440 bool success =
true;
2442 #if defined (HAVE_HDF5_18)
2450 H5Sclose (space_hid);
2451 H5Tclose (type_hid);
2452 H5Gclose (group_hid);
2456 H5Tclose (type_hid);
2457 type_hid = H5Dget_type (data_hid);
2460 if (type_class_hid != H5T_STRING)
2462 H5Sclose (space_hid);
2463 H5Tclose (type_hid);
2464 H5Dclose (data_hid);
2465 H5Gclose (group_hid);
2469 H5Sclose (space_hid);
2470 space_hid = H5Dget_space (data_hid);
2471 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
2475 H5Sclose (space_hid);
2476 H5Tclose (type_hid);
2477 H5Dclose (data_hid);
2478 H5Gclose (group_hid);
2482 int slen = H5Tget_size (type_hid);
2485 H5Sclose (space_hid);
2486 H5Tclose (type_hid);
2487 H5Dclose (data_hid);
2488 H5Gclose (group_hid);
2496 H5Tset_size (st_id, slen);
2503 H5Sclose (space_hid);
2504 H5Tclose (type_hid);
2505 H5Dclose (data_hid);
2506 H5Gclose (group_hid);
2510 H5Dclose (data_hid);
2523 #if defined (HAVE_HDF5_18)
2527 H5Eget_auto (&err_fcn, &err_fcn_data);
2528 H5Eset_auto (
nullptr,
nullptr);
2531 octave_hdf5_id attr_id = H5Aopen_name (group_hid,
"SYMBOL_TABLE");
2542 #if defined (HAVE_HDF5_18)
2545 H5Eset_auto (err_fcn, err_fcn_data);
2558 if (
len > 0 && success)
2560 hsize_t num_obj = 0;
2561 #if defined (HAVE_HDF5_18)
2564 data_hid = H5Gopen (group_hid,
"symbol table");
2566 H5Gget_num_objs (data_hid, &num_obj);
2567 H5Gclose (data_hid);
2569 if (num_obj !=
static_cast<hsize_t
> (
len))
2570 error (
"load: failed to load anonymous function handle");
2573 int current_item = 0;
2578 error (
"load: failed to load anonymous function handle");
2585 return parse (fcn_tmp);
2591 octave_unused_parameter (group_hid);
2592 octave_unused_parameter (space_hid);
2593 octave_unused_parameter (type_hid);
2607 error (
"invalid anonymous function handle");
2629 error (
"invalid anonymous function handle");
2636 error (
"invalid anonymous function handle");
2662 = interp.
eval_string (fcn_text,
true, parse_status);
2664 if (parse_status != 0)
2689 const std::shared_ptr<stack_frame>& stack_context)
2691 m_stack_context (stack_context)
2714 return oct_usr_fcn->
execute (tw, nargout, args);
2722 local_vars_map.
assign (nm_val.first, nm_val.second);
2738 Cell retval =
Cell (num_frames+1, 1);
2741 retval(i+1) = cell_frames(i);
2768 return oct_usr_fcn->
execute (tw, nargout, args);
2776 local_vars_map.
assign (nm_val.first, nm_val.second);
2796 Cell retval =
Cell (num_frames+1, 1);
2799 retval(i+1) = cell_frames(i);
2829 const std::string& name)
2834 const std::string& meth_nm)
2840 const std::string& class_nm,
2841 const std::string& meth_nm)
2848 const std::string& class_nm,
2849 const std::string& meth_nm)
2855 const std::string& name,
2856 const std::list<std::string>& parentage)
2862 const std::string& name,
2863 const std::shared_ptr<octave::stack_frame>& stack_context)
2869 const octave::stack_frame::local_vars_map& local_vars,
2870 const std::shared_ptr<octave::stack_frame>& stack_context)
2895 return m_rep->save_ascii (os);
2901 std::shared_ptr<octave::base_fcn_handle> new_rep;
2906 std::streampos pos = is.tellg ();
2909 if (octaveroot.empty ())
2924 if (! (octaveroot.empty () || fpath.empty ()))
2926 std::size_t
len = octaveroot.size ();
2927 if (octaveroot == fpath.substr (0,
len))
2934 if (subtype.empty ())
2946 new_rep.reset (
new octave::anonymous_fcn_handle ());
2948 new_rep.reset (
new octave::simple_fcn_handle (name, fpath, octaveroot));
2954 if (subtype ==
"simple")
2959 new_rep.reset (
new octave::simple_fcn_handle (name, fpath,
2962 else if (subtype ==
"scopedfunction")
2967 new_rep.reset (
new octave::scoped_fcn_handle (name, fpath,
2970 else if (subtype ==
"anonymous")
2971 new_rep.reset (
new octave::anonymous_fcn_handle ());
2972 else if (subtype ==
"nested")
2977 new_rep.reset (
new octave::nested_fcn_handle (name, fpath,
2980 else if (subtype ==
"classsimple")
2985 new_rep.reset (
new octave::class_simple_fcn_handle (name, fpath,
2993 if (! new_rep->load_ascii (is))
3004 return m_rep->save_binary (os, save_as_floats);
3015 if (! is.read (
reinterpret_cast<char *
> (&tmp), 4))
3023 is.read (ctmp1, tmp);
3025 std::string name (ctmp1);
3030 std::shared_ptr<octave::base_fcn_handle> new_rep;
3034 if (name.length () >= anl && name.substr (0, anl) ==
anonymous)
3041 new_rep.reset (
new octave::anonymous_fcn_handle (name));
3049 std::string octaveroot;
3051 std::string subtype =
"simple";
3053 if (name.find_first_of (
'\n') != std::string::npos)
3055 std::size_t pos1 = name.find_first_of (
'\n');
3056 std::size_t pos2 = name.find_first_of (
'\n', pos1 + 1);
3057 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
3058 fpath = name.substr (pos2 + 1);
3059 name = name.substr (0, pos1);
3062 std::size_t pos1 = name.find (
'@');
3063 if (pos1 != std::string::npos)
3065 if (name[pos1+1] ==
'<')
3067 std::size_t pos2 = name.find (
'>', pos1 + 2);
3069 if (pos2 != std::string::npos)
3070 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
3073 name = name.substr (0, pos1);
3079 if (subtype ==
"simple")
3080 new_rep.reset (
new octave::simple_fcn_handle (name, fpath, octaveroot));
3081 else if (subtype ==
"scopedfunction")
3082 new_rep.reset (
new octave::scoped_fcn_handle (name, fpath, octaveroot));
3083 else if (subtype ==
"nested")
3084 new_rep.reset (
new octave::nested_fcn_handle (name, fpath, octaveroot));
3085 else if (subtype ==
"classsimple")
3086 new_rep.reset (
new octave::class_simple_fcn_handle (name, fpath,
3093 if (! new_rep->load_binary (is, swap, fmt))
3103 bool save_as_floats)
3105 return m_rep->save_hdf5 (loc_id, name, save_as_floats);
3111 #if defined (HAVE_HDF5)
3113 #if defined (HAVE_HDF5_18)
3121 #if defined (HAVE_HDF5_18)
3129 H5Gclose (group_hid);
3136 if (type_class_hid != H5T_STRING)
3138 H5Tclose (type_hid);
3139 H5Dclose (data_hid);
3140 H5Gclose (group_hid);
3145 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
3149 H5Sclose (space_hid);
3150 H5Tclose (type_hid);
3151 H5Dclose (data_hid);
3152 H5Gclose (group_hid);
3156 int slen = H5Tget_size (type_hid);
3159 H5Sclose (space_hid);
3160 H5Tclose (type_hid);
3161 H5Dclose (data_hid);
3162 H5Gclose (group_hid);
3170 H5Tset_size (st_id, slen);
3177 H5Sclose (space_hid);
3178 H5Tclose (type_hid);
3179 H5Dclose (data_hid);
3180 H5Gclose (group_hid);
3184 H5Dclose (data_hid);
3186 std::string name (nm_tmp);
3188 std::shared_ptr<octave::base_fcn_handle> new_rep;
3195 new_rep.reset (
new octave::anonymous_fcn_handle ());
3203 std::string octaveroot;
3205 std::string subtype =
"simple";
3207 if (name.find_first_of (
'\n') != std::string::npos)
3209 std::size_t pos1 = name.find_first_of (
'\n');
3210 std::size_t pos2 = name.find_first_of (
'\n', pos1 + 1);
3211 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
3212 fpath = name.substr (pos2 + 1);
3213 name = name.substr (0, pos1);
3216 std::size_t pos1 = name.find (
'@');
3217 if (pos1 != std::string::npos)
3219 if (name[pos1+1] ==
'<')
3221 std::size_t pos2 = name.find (
'>', pos1 + 2);
3223 if (pos2 != std::string::npos)
3224 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
3227 name = name.substr (0, pos1);
3233 if (subtype ==
"simple")
3234 new_rep.reset (
new octave::simple_fcn_handle (name, fpath, octaveroot));
3235 else if (subtype ==
"scopedfunction")
3236 new_rep.reset (
new octave::scoped_fcn_handle (name, fpath, octaveroot));
3237 else if (subtype ==
"nested")
3238 new_rep.reset (
new octave::nested_fcn_handle (name, fpath, octaveroot));
3239 else if (subtype ==
"classsimple")
3240 new_rep.reset (
new octave::class_simple_fcn_handle (name, fpath,
3244 bool status =
false;
3246 if (new_rep && new_rep->load_hdf5 (group_hid, space_hid, type_hid))
3254 H5Tclose (type_hid);
3255 H5Sclose (space_hid);
3256 H5Gclose (group_hid);
3262 octave_unused_parameter (loc_id);
3263 octave_unused_parameter (name_arg);
3386 *
dynamic_cast<octave::internal_fcn_handle *
> (fh2.
get_rep ()));
3389 *
dynamic_cast<octave::simple_fcn_handle *
> (fh2.
get_rep ()));
3392 *
dynamic_cast<octave::scoped_fcn_handle *
> (fh2.
get_rep ()));
3395 *
dynamic_cast<octave::nested_fcn_handle *
> (fh2.
get_rep ()));
3397 return is_equal_to (*
dynamic_cast<octave::class_simple_fcn_handle *
> (fh1.
get_rep ()),
3398 *
dynamic_cast<octave::class_simple_fcn_handle *
> (fh2.
get_rep ()));
3401 *
dynamic_cast<octave::anonymous_fcn_handle *
> (fh2.
get_rep ()));
3408 DEFUN (functions, args, ,
3459 if (args.length () != 1)
3463 0).xfcn_handle_value (
"functions: FCN_HANDLE argument must be a function handle object");
3468 DEFUN (func2str, args, ,
3476 if (args.length () != 1)
3480 0).xfcn_handle_value (
"func2str: FCN_HANDLE argument must be a function handle object");
3483 error (
"func2str: FCN_HANDLE must be a valid function handle");
3487 std::string fh_nm = fh->
fcn_name ();
3491 std::ostringstream buf;
3495 retval = buf.str ();
3525 int nargin = args.length ();
3527 if (nargin < 1 || nargin > 2)
3531 = args(0).xstring_value (
"str2func: FCN_NAME must be a string");
3534 error (
"str2func: invalid function name");
3551 octave_value afh = interp.eval_string (nm,
true, parse_status);
3553 if (parse_status == 0)
3560 "str2func: second argument ignored");
3602 DEFUN (is_function_handle, args, ,
3609 if (args.length () != 1)
3612 return ovl (args(0).is_function_handle ());
void swap_bytes< 4 >(void *ptr)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
octave_value make_weak_anonymous_handle(void) const
anonymous_fcn_handle(const anonymous_fcn_handle &)=default
anonymous_fcn_handle * clone(void) const
octave_value workspace(void) const
friend bool is_equal_to(const anonymous_fcn_handle &fh1, const anonymous_fcn_handle &fh2)
std::shared_ptr< stack_frame > m_stack_context
std::shared_ptr< stack_frame > stack_context(void) const
octave_value_list call(int nargout, const octave_value_list &args)
anonymous_fcn_handle(const std::string &name="")
~anonymous_fcn_handle(void)=default
bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
void print_raw(std::ostream &, bool pr_as_read_syntax, int current_print_indent_level) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool load_ascii(std::istream &is)
bool save_ascii(std::ostream &os)
octave_scalar_map info(void)
std::string type(void) const
bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
bool parse(const std::string &fcn_text)
octave_user_function * user_function_value(bool=false)
base_anonymous_fcn_handle(const octave_value &fcn, const stack_frame::local_vars_map &local_vars)
virtual octave_value workspace(void) const =0
octave_value fcn_val(void)
bool save_binary(std::ostream &os, bool save_as_floats)
stack_frame::local_vars_map m_local_vars
octave_function * function_value(bool=false)
static const std::string anonymous
base_anonymous_fcn_handle(const std::string &name="")
bool is_anonymous(void) const
bool print_as_scalar(void) const
base_anonymous_fcn_handle(const base_anonymous_fcn_handle &)=default
~base_anonymous_fcn_handle(void)=default
virtual bool save_binary(std::ostream &os, bool save_as_floats)
virtual bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
virtual octave_value make_weak_anonymous_handle(void) const
void unimplemented(const char *op, const char *fmt) const
std::string fcn_name(void) const
virtual bool save_ascii(std::ostream &os)
virtual std::string type(void) const =0
void warn_save(const char *file_type) const
virtual bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
virtual octave_value make_weak_nested_handle(void) const
virtual bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
virtual octave_value_list call(int nargout, const octave_value_list &args)=0
void warn_load(const char *file_type) const
virtual bool is_nested(void) const
virtual bool load_ascii(std::istream &is)
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
std::string file(void) const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
virtual void print_raw(std::ostream &, bool, int) const
std::size_t length(void) const
void print_raw(std::ostream &, bool pr_as_read_syntax, int current_print_indent_level) const
octave_scalar_map info(void)
bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
base_nested_fcn_handle(const std::string &name="", const std::string &file="", const std::string &="")
bool save_binary(std::ostream &os, bool save_as_floats)
octave_user_function * user_function_value(bool=false)
octave_function * function_value(bool=false)
std::string type(void) const
bool is_nested(void) const
bool save_ascii(std::ostream &os)
bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
base_nested_fcn_handle(const octave_value &fcn, const std::string &name)
virtual octave_value workspace(void) const =0
bool load_ascii(std::istream &is)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_value fcn_val(void)
octave_value_list call(int nargout, const octave_value_list &args)
octave_function * function_value(bool=false)
std::string type(void) const
friend bool is_equal_to(const class_simple_fcn_handle &fh1, const class_simple_fcn_handle &fh2)
bool is_class_simple(void) const
octave_user_function * user_function_value(bool=false)
bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
std::string dispatch_class(void) const
~class_simple_fcn_handle(void)=default
std::string m_dispatch_class
bool save_binary(std::ostream &os, bool save_as_floats)
class_simple_fcn_handle * clone(void) const
class_simple_fcn_handle(const std::string &name, const std::string &file, const std::string &)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
class_simple_fcn_handle(const class_simple_fcn_handle &)=default
void print_raw(std::ostream &, bool pr_as_read_syntax, int current_print_indent_level) const
octave_scalar_map info(void)
bool save_ascii(std::ostream &os)
bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
octave_value fcn_val(void)
bool load_ascii(std::istream &is)
Vector representing the dimensions (size) of an Array.
octave_value_list call(int nargout, const octave_value_list &args)
octave_user_function * user_function_value(bool=false)
octave_function * function_value(bool=false)
~internal_fcn_handle(void)=default
internal_fcn_handle(const octave_value &fcn)
bool is_internal(void) const
internal_fcn_handle(const internal_fcn_handle &)=default
octave_scalar_map info(void)
octave_value fcn_val(void)
internal_fcn_handle * clone(void) const
friend bool is_equal_to(const internal_fcn_handle &fh1, const internal_fcn_handle &fh2)
std::string type(void) const
octave_value varval(const std::string &name) const
tree_evaluator & get_evaluator(void)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
symbol_table & get_symbol_table(void)
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
~invalid_fcn_handle(void)=default
octave_value_list call(int nargout, const octave_value_list &args)
std::string type(void) const
invalid_fcn_handle(const invalid_fcn_handle &)=default
invalid_fcn_handle * clone(void) const
friend bool is_equal_to(const nested_fcn_handle &fh1, const nested_fcn_handle &fh2)
nested_fcn_handle(const std::string &name="", const std::string &file="", const std::string &octaveroot="")
nested_fcn_handle(const octave_value &fcn, const std::string &name, const std::shared_ptr< stack_frame > &stack_context)
bool is_nested(const std::shared_ptr< stack_frame > &frame) const
octave_value_list call(int nargout, const octave_value_list &args)
octave_value workspace(void) const
std::shared_ptr< stack_frame > stack_context(void) const
std::shared_ptr< stack_frame > m_stack_context
octave_value make_weak_nested_handle(void) const
nested_fcn_handle(const nested_fcn_handle &)=default
~nested_fcn_handle(void)=default
nested_fcn_handle * clone(void) const
int current_print_indent_level(void) const
OCTINTERP_API void newline(std::ostream &os) const
OCTINTERP_API void warn_load(const char *type) const
bool load_ascii(std::istream &is)
Array< std::string > cellstr_value(void) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
bool iscellstr(void) const
static const std::string anonymous
std::string fcn_name(void) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_scalar_map info(void)
bool is_simple(void) const
std::shared_ptr< octave::base_fcn_handle > m_rep
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
bool is_internal(void) const
bool load_ascii(std::istream &is)
bool is_class_simple(void) const
octave::base_fcn_handle * get_rep(void) const
octave_value fcn_val(void)
bool is_anonymous(void) const
dim_vector dims(void) const
bool is_scoped(void) const
bool save_binary(std::ostream &os, bool save_as_floats)
bool save_ascii(std::ostream &os)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool is_nested(void) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
void print(std::ostream &os, bool pr_as_read_syntax=false)
std::string dispatch_class(void) const
virtual std::string fcn_file_name(void) const
bool is_class_method(const std::string &cname="") const
void assign(const std::string &k, const octave_value &val)
std::string fcn_file_name(void) const
octave::symbol_scope scope(void)
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_value find_subfunction(const std::string &subfuns) const
octave_idx_type length(void) const
octave_value_list & prepend(const octave_value &val)
bool is_function(void) const
bool is_classdef_object(void) const
bool is_package(void) const
OCTINTERP_API octave_function * function_value(bool silent=false) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
bool is_cs_list(void) const
bool is_copy_of(const octave_value &val) const
bool save_binary(std::ostream &os, bool save_as_floats)
bool is_defined(void) const
bool save_ascii(std::ostream &os)
Cell cell_value(void) const
bool is_classdef_meta(void) const
OCTINTERP_API octave_user_function * user_function_value(bool silent=false) const
OCTINTERP_API octave_fcn_handle * fcn_handle_value(bool silent=false) const
bool is_undefined(void) const
friend bool is_equal_to(const scoped_fcn_handle &fh1, const scoped_fcn_handle &fh2)
void print_raw(std::ostream &, bool pr_as_read_syntax, int current_print_indent_level) const
bool save_binary(std::ostream &os, bool save_as_floats)
scoped_fcn_handle(const scoped_fcn_handle &)=default
octave_function * function_value(bool=false)
~scoped_fcn_handle(void)=default
bool load_ascii(std::istream &is)
octave_value_list call(int nargout, const octave_value_list &args)
bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
octave_user_function * user_function_value(bool=false)
octave_value fcn_val(void)
std::string type(void) const
bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
octave_scalar_map info(void)
scoped_fcn_handle(const std::string &name="", const std::string &file="", const std::string &="")
scoped_fcn_handle * clone(void) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool is_scoped(void) const
bool save_ascii(std::ostream &os)
std::list< std::string > m_parentage
friend bool is_equal_to(const simple_fcn_handle &fh1, const simple_fcn_handle &fh2)
std::string type(void) const
octave_function * function_value(bool)
bool is_simple(void) const
octave_user_function * user_function_value(bool)
simple_fcn_handle(const std::string &name="", const std::string &file="", const std::string &="")
simple_fcn_handle(const octave_value &fcn, const std::string &name)
void print_raw(std::ostream &os, bool pr_as_read_syntax, int current_print_indent_level) const
bool save_binary(std::ostream &os, bool save_as_floats)
bool save_hdf5(octave_hdf5_id loc_hid, const char *name, bool save_as_floats)
simple_fcn_handle * clone(void) const
octave_value fcn_val(void)
bool save_ascii(std::ostream &os)
bool load_binary(std::istream &is, bool swap, mach_info::float_format fmt)
bool load_hdf5(octave_hdf5_id &group_hid, octave_hdf5_id &space_hid, octave_hdf5_id &type_hid)
simple_fcn_handle(const simple_fcn_handle &)=default
octave_value_list call(int nargout, const octave_value_list &args)
bool load_ascii(std::istream &is)
octave_scalar_map info(void)
~simple_fcn_handle(void)=default
std::map< std::string, octave_value > local_vars_map
void cache_name(const std::string &name)
octave_value find_private_function(const std::string &dir_name, const std::string &name)
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
octave_value find_user_function(const std::string &name)
void set_dispatch_class(const std::string &class_name)
void pop_stack_frame(void)
void push_dummy_scope(const std::string &name)
octave_value make_fcn_handle(const std::string &nm)
void push_stack_frame(const symbol_scope &scope)
void accept(tree_walker &tw)
void print_fcn_handle_body(tree_expression *)
bool is_expression(void) const
tree_expression * expression(void)
weak_anonymous_fcn_handle(const anonymous_fcn_handle &afh)
bool is_weak_anonymous(void) const
weak_anonymous_fcn_handle * clone(void) const
std::weak_ptr< stack_frame > m_stack_context
octave_value workspace(void) const
octave_value_list call(int nargout, const octave_value_list &args)
friend bool is_equal_to(const weak_anonymous_fcn_handle &fh1, const weak_anonymous_fcn_handle &fh2)
~weak_anonymous_fcn_handle(void)=default
weak_anonymous_fcn_handle(const weak_anonymous_fcn_handle &)=default
weak_nested_fcn_handle(const nested_fcn_handle &nfh)
std::weak_ptr< stack_frame > m_stack_context
octave_value workspace(void) const
bool is_weak_nested(void) const
friend bool is_equal_to(const weak_nested_fcn_handle &fh1, const weak_nested_fcn_handle &fh2)
weak_nested_fcn_handle(const weak_nested_fcn_handle &)=default
~weak_nested_fcn_handle(void)=default
weak_nested_fcn_handle * clone(void) const
octave_value_list call(int nargout, const octave_value_list &args)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5E_DEFAULT
const octave_hdf5_id octave_H5S_ALL
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string octave_exec_home(void)
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
void panic_unless(bool cond)
#define panic_impossible()
std::string dirname(const std::string &path)
interpreter & __get_interpreter__(void)
symbol_table & __get_symbol_table__(void)
tree_evaluator & __get_evaluator__(void)
F77_RET_T const F77_DBLE const F77_DBLE * f
std::string read_until_newline(std::istream &is, bool keep_newline)
void skip_preceeding_newline(std::istream &is)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count, const bool do_name_validation)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
static void err_invalid_fcn_handle(const std::string &name)
bool is_equal_to(const anonymous_fcn_handle &fh1, const anonymous_fcn_handle &fh2)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
static std::string dir_sep_chars