77 : fcn (f), nm (n), has_overloads (false)
85 ::
error (
"handles to nested functions are not yet supported");
90 const std::list<octave_value_list>& idx,
98 const std::list<octave_value_list>& idx,
100 const std::list<octave_lvalue>* lvalue_list)
108 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
111 idx.size () == 1 ? lvalue_list : 0);
119 error (
"%s cannot be indexed with %c", tnm.c_str (), type[0]);
132 retval = retval(0).next_subsref (nargout, type, idx);
147 const std::list<octave_lvalue>* lvalue_list)
170 str_ov_map::iterator it =
overloads.find (dispatch_type);
176 std::list<std::string> plist
179 std::list<std::string>::const_iterator pit = plist.begin ();
181 while (pit != plist.end ())
183 std::string pname = *pit;
214 error (
"%s: no method for class %s",
215 nm.c_str (), dispatch_type.c_str ());
223 error (
"%s: no longer valid function handle",
nm.c_str ());
240 str_ov_map::const_iterator iter =
overloads.begin ();
241 str_ov_map::const_iterator hiter = h.
overloads.begin ();
242 for (; iter !=
overloads.end () && retval; iter++, hiter++)
243 retval = (iter->first == hiter->first)
244 && (iter->second.is_copy_of (hiter->second));
252 const std::string& fpath)
256 if (octaveroot.length () != 0
257 && fpath.length () >= octaveroot.length ()
258 && fpath.substr (0, octaveroot.length ()) == octaveroot
263 fpath.substr (octaveroot.length ());
270 std::string dir_name = str.substr (0, xpos);
283 error (
"function handle points to non-existent function");
301 std::string dir_name = str.substr (0, xpos);
313 error (
"function handle points to non-existent function");
320 if (fpath.length () > 0)
324 std::string dir_name = fpath.substr (0, xpos);
336 error (
"function handle points to non-existent function");
346 error (
"function handle points to non-existent function");
370 std::list<symbol_table::symbol_record>
vars
373 size_t varlen = vars.size ();
377 os <<
"# length: " << varlen <<
"\n";
379 for (std::list<symbol_table::symbol_record>::const_iterator
380 p = vars.begin (); p != vars.end (); p++)
394 os <<
"# path: " << fnm <<
"\n";
406 std::streampos pos = is.tellg ();
408 if (octaveroot.length () == 0)
415 if (fpath.length () == 0)
469 error (
"load: failed to load anonymous function handle");
489 if (parse_status == 0)
513 success =
set_fcn (octaveroot, fpath);
523 std::ostringstream nmbuf;
530 std::list<symbol_table::symbol_record>
vars
533 size_t varlen = vars.size ();
536 nmbuf <<
nm <<
" " << varlen;
540 std::string buf_str = nmbuf.str ();
541 int32_t tmp = buf_str.length ();
542 os.write (reinterpret_cast<char *> (&tmp), 4);
543 os.write (buf_str.c_str (), buf_str.length ());
545 std::ostringstream buf;
547 std::string stmp = buf.str ();
548 tmp = stmp.length ();
549 os.write (reinterpret_cast<char *> (&tmp), 4);
550 os.write (stmp.c_str (), stmp.length ());
554 for (std::list<symbol_table::symbol_record>::const_iterator
555 p = vars.begin (); p != vars.end (); p++)
558 "", 0, save_as_floats))
565 std::ostringstream nmbuf;
572 std::string buf_str = nmbuf.str ();
573 int32_t tmp = buf_str.length ();
574 os.write (reinterpret_cast<char *> (&tmp), 4);
575 os.write (buf_str.c_str (), buf_str.length ());
588 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
596 is.read (ctmp1, tmp);
598 nm = std::string (ctmp1);
609 if (
nm.length () > anl)
611 std::istringstream nm_is (
nm.substr (anl));
613 nm =
nm.substr (0, anl);
616 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
624 is.read (ctmp2, tmp);
654 error (
"load: failed to load anonymous function handle");
668 if (parse_status == 0)
690 std::string octaveroot;
693 if (
nm.find_first_of (
"\n") != std::string::npos)
695 size_t pos1 =
nm.find_first_of (
"\n");
696 size_t pos2 =
nm.find_first_of (
"\n", pos1 + 1);
697 octaveroot =
nm.substr (pos1 + 1, pos2 - pos1 - 1);
698 fpath =
nm.substr (pos2 + 1);
699 nm =
nm.substr (0, pos1);
702 success =
set_fcn (octaveroot, fpath);
708 #if defined (HAVE_HDF5)
715 hid_t group_hid = -1;
717 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
719 group_hid = H5Gcreate (loc_id, name, 0);
724 hid_t space_hid = -1, data_hid = -1, type_hid = -1;;
727 type_hid = H5Tcopy (H5T_C_S1);
728 H5Tset_size (type_hid,
nm.length () + 1);
731 H5Gclose (group_hid);
738 space_hid = H5Screate_simple (0 , hdims, 0);
742 H5Gclose (group_hid);
746 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
747 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
749 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid, H5P_DEFAULT);
751 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
752 H5P_DEFAULT,
nm.c_str ()) < 0)
754 H5Sclose (space_hid);
756 H5Gclose (group_hid);
763 std::ostringstream buf;
765 std::string stmp = buf.str ();
768 H5Tset_size (type_hid, stmp.length () + 1);
771 H5Sclose (space_hid);
772 H5Gclose (group_hid);
777 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
778 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
780 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
783 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
784 H5P_DEFAULT, stmp.c_str ()) < 0)
786 H5Sclose (space_hid);
788 H5Gclose (group_hid);
796 std::list<symbol_table::symbol_record>
vars
799 size_t varlen = vars.size ();
803 hid_t as_id = H5Screate (H5S_SCALAR);
808 hid_t a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
810 H5P_DEFAULT, H5P_DEFAULT);
813 hid_t a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
831 data_hid = H5Gcreate (group_hid,
"symbol table",
832 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
834 data_hid = H5Gcreate (group_hid,
"symbol table", 0);
838 H5Sclose (space_hid);
840 H5Gclose (group_hid);
844 for (std::list<symbol_table::symbol_record>::const_iterator
845 p = vars.begin (); p != vars.end (); p++)
848 "",
false, save_as_floats))
859 std::string fpath = f ? f->
fcn_file_name () : std::string ();
861 H5Sclose (space_hid);
863 hdims[1] = octaveroot.length ();
864 space_hid = H5Screate_simple (0 , hdims, 0);
868 H5Gclose (group_hid);
873 type_hid = H5Tcopy (H5T_C_S1);
874 H5Tset_size (type_hid, octaveroot.length () + 1);
876 hid_t a_id = H5Acreate (group_hid,
"OCTAVEROOT",
877 type_hid, space_hid, H5P_DEFAULT, H5P_DEFAULT);
879 hid_t a_id = H5Acreate (group_hid,
"OCTAVEROOT",
880 type_hid, space_hid, H5P_DEFAULT);
885 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0);
891 H5Sclose (space_hid);
893 H5Gclose (group_hid);
897 H5Sclose (space_hid);
899 hdims[1] = fpath.length ();
900 space_hid = H5Screate_simple (0 , hdims, 0);
904 H5Gclose (group_hid);
909 type_hid = H5Tcopy (H5T_C_S1);
910 H5Tset_size (type_hid, fpath.length () + 1);
913 a_id = H5Acreate (group_hid,
"FILE", type_hid, space_hid,
914 H5P_DEFAULT, H5P_DEFAULT);
916 a_id = H5Acreate (group_hid,
"FILE", type_hid, space_hid, H5P_DEFAULT);
921 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0);
929 H5Sclose (space_hid);
931 H5Gclose (group_hid);
941 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id;
946 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT);
948 group_hid = H5Gopen (loc_id, name);
954 data_hid = H5Dopen (group_hid,
"nm", H5P_DEFAULT);
956 data_hid = H5Dopen (group_hid,
"nm");
961 H5Gclose (group_hid);
965 type_hid = H5Dget_type (data_hid);
966 type_class_hid = H5Tget_class (type_hid);
968 if (type_class_hid != H5T_STRING)
972 H5Gclose (group_hid);
976 space_hid = H5Dget_space (data_hid);
977 rank = H5Sget_simple_extent_ndims (space_hid);
981 H5Sclose (space_hid);
984 H5Gclose (group_hid);
988 slen = H5Tget_size (type_hid);
991 H5Sclose (space_hid);
994 H5Gclose (group_hid);
1001 st_id = H5Tcopy (H5T_C_S1);
1002 H5Tset_size (st_id, slen);
1004 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0)
1007 H5Sclose (space_hid);
1008 H5Tclose (type_hid);
1009 H5Dclose (data_hid);
1010 H5Gclose (group_hid);
1014 H5Dclose (data_hid);
1020 data_hid = H5Dopen (group_hid,
"fcn", H5P_DEFAULT);
1022 data_hid = H5Dopen (group_hid,
"fcn");
1027 H5Sclose (space_hid);
1028 H5Tclose (type_hid);
1029 H5Gclose (group_hid);
1033 H5Tclose (type_hid);
1034 type_hid = H5Dget_type (data_hid);
1035 type_class_hid = H5Tget_class (type_hid);
1037 if (type_class_hid != H5T_STRING)
1039 H5Sclose (space_hid);
1040 H5Tclose (type_hid);
1041 H5Dclose (data_hid);
1042 H5Gclose (group_hid);
1046 H5Sclose (space_hid);
1047 space_hid = H5Dget_space (data_hid);
1048 rank = H5Sget_simple_extent_ndims (space_hid);
1052 H5Sclose (space_hid);
1053 H5Tclose (type_hid);
1054 H5Dclose (data_hid);
1055 H5Gclose (group_hid);
1059 slen = H5Tget_size (type_hid);
1062 H5Sclose (space_hid);
1063 H5Tclose (type_hid);
1064 H5Dclose (data_hid);
1065 H5Gclose (group_hid);
1072 st_id = H5Tcopy (H5T_C_S1);
1073 H5Tset_size (st_id, slen);
1075 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0)
1078 H5Sclose (space_hid);
1079 H5Tclose (type_hid);
1080 H5Dclose (data_hid);
1081 H5Gclose (group_hid);
1085 H5Dclose (data_hid);
1093 H5E_auto_t err_func;
1094 void *err_func_data;
1099 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data);
1100 H5Eset_auto (H5E_DEFAULT, 0, 0);
1102 H5Eget_auto (&err_func, &err_func_data);
1106 hid_t attr_id = H5Aopen_name (group_hid,
"SYMBOL_TABLE");
1118 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data);
1120 H5Eset_auto (err_func, err_func_data);
1136 if (len > 0 && success)
1138 hsize_t num_obj = 0;
1140 data_hid = H5Gopen (group_hid,
"symbol table", H5P_DEFAULT);
1142 data_hid = H5Gopen (group_hid,
"symbol table");
1144 H5Gget_num_objs (data_hid, &num_obj);
1145 H5Gclose (data_hid);
1147 if (num_obj != static_cast<hsize_t>(len))
1149 error (
"load: failed to load anonymous function handle");
1156 int current_item = 0;
1159 if (H5Giterate (group_hid,
"symbol table", ¤t_item,
1162 error (
"load: failed to load anonymous function handle");
1178 if (parse_status == 0)
1202 std::string octaveroot;
1209 H5E_auto_t err_func;
1210 void *err_func_data;
1215 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data);
1216 H5Eset_auto (H5E_DEFAULT, 0, 0);
1218 H5Eget_auto (&err_func, &err_func_data);
1222 hid_t attr_id = H5Aopen_name (group_hid,
"OCTAVEROOT");
1225 H5Tclose (type_hid);
1226 type_hid = H5Aget_type (attr_id);
1227 type_class_hid = H5Tget_class (type_hid);
1229 if (type_class_hid != H5T_STRING)
1233 slen = H5Tget_size (type_hid);
1234 st_id = H5Tcopy (H5T_C_S1);
1235 H5Tset_size (st_id, slen);
1238 if (H5Aread (attr_id, st_id, root_tmp) < 0)
1241 octaveroot = root_tmp;
1251 attr_id = H5Aopen_name (group_hid,
"FILE");
1254 H5Tclose (type_hid);
1255 type_hid = H5Aget_type (attr_id);
1256 type_class_hid = H5Tget_class (type_hid);
1258 if (type_class_hid != H5T_STRING)
1262 slen = H5Tget_size (type_hid);
1263 st_id = H5Tcopy (H5T_C_S1);
1264 H5Tset_size (st_id, slen);
1267 if (H5Aread (attr_id, st_id, path_tmp) < 0)
1281 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data);
1283 H5Eset_auto (err_func, err_func_data);
1286 success = (success ?
set_fcn (octaveroot, fpath) : success);
1289 H5Tclose (type_hid);
1290 H5Sclose (space_hid);
1291 H5Gclose (group_hid);
1398 bool printed =
false;
1445 std::string tnm = nm;
1447 size_t len = nm.
length ();
1449 if (len == 3 && nm ==
".**")
1486 else if (nm[1] ==
'=')
1508 else if (nm ==
"**")
1573 if (local_funcs && fptr
1584 bool any_match = fptr != 0 || classes.size () > 0;
1590 any_match = classes.size () > 0;
1598 for (std::list<std::string>::iterator iter = classes.begin ();
1599 iter != classes.end (); iter++)
1601 std::string class_name = *iter;
1604 bool is_builtin =
false;
1611 fh->
set_overload (static_cast<builtin_type_t> (i), fmeth);
1620 error (
"@%s: no function and no method found", tnm.c_str ());
1662 @deftypefn {Built-in Function} {} functions (@var{fcn_handle})\n\
1663 Return a struct containing information about the function handle\n\
1664 @var{fcn_handle}.\n\
1669 if (args.length () == 1)
1681 std::string fh_nm = fh->
fcn_name ();
1685 std::ostringstream buf;
1687 m.
setfield (
"function", buf.str ());
1697 m.
setfield (
"type",
"subfunction");
1699 parentage.
elem (0) = fh_nm;
1719 std::list<symbol_table::symbol_record>
vars
1722 size_t varlen = vars.size ();
1727 for (std::list<symbol_table::symbol_record>::const_iterator
1728 p = vars.begin (); p != vars.end (); p++)
1730 ws.
assign (p->name (), p->varval (0));
1747 error (
"functions: FCN_HANDLE is not a valid function handle object");
1750 error (
"functions: FCN_HANDLE argument must be a function handle object");
1760 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\
1761 Return a string containing the name of the function referenced by\n\
1762 the function handle @var{fcn_handle}.\n\
1767 if (args.length () == 1)
1773 std::string fh_nm = fh->
fcn_name ();
1777 std::ostringstream buf;
1781 retval = buf.str ();
1787 error (
"func2str: FCN_HANDLE must be a valid function handle");
1797 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\
1798 @deftypefnx {Built-in Function} {} str2func (@var{fcn_name}, \"global\")\n\
1799 Return a function handle constructed from the string @var{fcn_name}.\n\
1800 If the optional @qcode{\"global\"} argument is passed, locally visible\n\
1801 functions are ignored in the lookup.\n\
1805 int nargin = args.
length ();
1807 if (nargin == 1 || nargin == 2)
1809 std::string nm = args(0).string_value ();
1814 error (
"str2func: FCN_NAME must be a string");
1840 @deftypefn {Built-in Function} {} is_function_handle (@var{x})\n\
1841 Return true if @var{x} is a function handle.\n\
1842 @seealso{isa, typeinfo, class}\n\
1847 int nargin = args.
length ();
1872 const std::vector<int>& mask,
1875 arg_mask (mask), expected_nargin (exp_nargin)
1892 cmd_list = usr_fcn->
body ();
1896 body_expr = (cmd_list->
length () == 1
1908 std::list<tree_argument_list *> arg_lists = idx_expr->
arg_lists ();
1909 std::string type_tags = idx_expr->
type_tags ();
1911 if (type_tags.length () == 1 && type_tags[0] ==
'('
1914 assert (arg_lists.size () == 1);
1922 std::map<std::string, int> arginmap;
1928 it != param_list->
end (); ++it, ++npar)
1933 arginmap[id->
name ()] = npar;
1937 if (arg_list && arg_list->
length () > 0)
1940 int nargs = arg_list->
length ();
1948 it != arg_list->
end (); ++it, ++iarg)
1954 arg_mask[iarg] = -1;
1960 if (arginmap.find (elt_id->
name ()) != arginmap.end ())
1962 arg_mask[iarg] = arginmap[elt_id->
name ()];
1967 arg_mask[iarg] = -1;
1987 if (head_id->is_defined ())
1988 root_val = head_id->rvalue1 ();
1992 std::string head_name = head_id->name ();
2013 std::list<string_vector> arg_names = idx_expr->
arg_names ();
2014 assert (arg_names.size () == 1);
2040 const std::list<octave_lvalue>* lvalue_list)