Mercurial > hg > octave-lyh
comparison libinterp/interp-core/ls-mat5.cc @ 16871:5e30b1c950b8
Replace uses of Octave_map with octave_map or octave_scalar_map.
* libinterp/dldfcn/__init_fltk__.cc(handle): Replace Octave_map
with octave_scalar_map.
* libinterp/dldfcn/__magick_read__.cc(jpg_settings, write_image,
F__magick_finfo__): Replace Octave_map with octave_map.
* libinterp/interp-core/ls-mat5.cc(read_mat5_binary_element): Replace
occurrences of Octave_map with octave_map or octave_scalar_map.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 30 Jun 2013 09:09:49 -0700 |
parents | dddbb5dcbf6e |
children |
comparison
equal
deleted
inserted
replaced
16870:fc3845c63458 | 16871:5e30b1c950b8 |
---|---|
875 = read_mat5_binary_element (is, filename, swap, global, tc2); | 875 = read_mat5_binary_element (is, filename, swap, global, tc2); |
876 | 876 |
877 if (! is || error_state) | 877 if (! is || error_state) |
878 goto data_read_error; | 878 goto data_read_error; |
879 | 879 |
880 // Octave can handle both "/" and "\" as a directry seperator | 880 // Octave can handle both "/" and "\" as a directory seperator |
881 // and so can ignore the seperator field of m0. I think the | 881 // and so can ignore the separator field of m0. I think the |
882 // sentinel field is also save to ignore. | 882 // sentinel field is also save to ignore. |
883 Octave_map m0 = tc2.map_value (); | 883 octave_scalar_map m0 = tc2.scalar_map_value (); |
884 Octave_map m1 = m0.contents ("function_handle")(0).map_value (); | 884 octave_scalar_map m1 = m0.contents ("function_handle").scalar_map_value (); |
885 std::string ftype = m1.contents ("type")(0).string_value (); | 885 std::string ftype = m1.contents ("type").string_value (); |
886 std::string fname = m1.contents ("function")(0).string_value (); | 886 std::string fname = m1.contents ("function").string_value (); |
887 std::string fpath = m1.contents ("file")(0).string_value (); | 887 std::string fpath = m1.contents ("file").string_value (); |
888 | 888 |
889 if (ftype == "simple" || ftype == "scopedfunction") | 889 if (ftype == "simple" || ftype == "scopedfunction") |
890 { | 890 { |
891 if (fpath.length () == 0) | 891 if (fpath.length () == 0) |
892 // We have a builtin function | 892 // We have a builtin function |
893 tc = make_fcn_handle (fname); | 893 tc = make_fcn_handle (fname); |
894 else | 894 else |
895 { | 895 { |
896 std::string mroot = | 896 std::string mroot = |
897 m0.contents ("matlabroot")(0).string_value (); | 897 m0.contents ("matlabroot").string_value (); |
898 | 898 |
899 if ((fpath.length () >= mroot.length ()) && | 899 if ((fpath.length () >= mroot.length ()) && |
900 fpath.substr (0, mroot.length ()) == mroot && | 900 fpath.substr (0, mroot.length ()) == mroot && |
901 OCTAVE_EXEC_PREFIX != mroot) | 901 OCTAVE_EXEC_PREFIX != mroot) |
902 { | 902 { |
929 tc = octave_value (new octave_fcn_handle (tmp, fname)); | 929 tc = octave_value (new octave_fcn_handle (tmp, fname)); |
930 } | 930 } |
931 } | 931 } |
932 else | 932 else |
933 { | 933 { |
934 // Next just search for it anywhere in the | 934 // Next just search for it anywhere in the system path |
935 // system path | |
936 string_vector names(3); | 935 string_vector names(3); |
937 names(0) = fname + ".oct"; | 936 names(0) = fname + ".oct"; |
938 names(1) = fname + ".mex"; | 937 names(1) = fname + ".mex"; |
939 names(2) = fname + ".m"; | 938 names(2) = fname + ".m"; |
940 | 939 |
994 warning ("load: can't load nested function"); | 993 warning ("load: can't load nested function"); |
995 goto skip_ahead; | 994 goto skip_ahead; |
996 } | 995 } |
997 else if (ftype == "anonymous") | 996 else if (ftype == "anonymous") |
998 { | 997 { |
999 Octave_map m2 = m1.contents ("workspace")(0).map_value (); | 998 octave_scalar_map m2 = m1.contents ("workspace").scalar_map_value (); |
1000 uint32NDArray MCOS = m2.contents ("MCOS")(0).uint32_array_value (); | 999 uint32NDArray MCOS = m2.contents ("MCOS").uint32_array_value (); |
1001 octave_idx_type off = static_cast<octave_idx_type>(MCOS(4).double_value ()); | 1000 octave_idx_type off = static_cast<octave_idx_type>(MCOS(4).double_value ()); |
1002 m2 = subsys_ov.map_value (); | 1001 m2 = subsys_ov.scalar_map_value (); |
1003 m2 = m2.contents ("MCOS")(0).map_value (); | 1002 m2 = m2.contents ("MCOS").scalar_map_value (); |
1004 tc2 = m2.contents ("MCOS")(0).cell_value ()(1 + off).cell_value ()(1); | 1003 tc2 = m2.contents ("MCOS").cell_value ()(1 + off).cell_value ()(1); |
1005 m2 = tc2.map_value (); | 1004 m2 = tc2.scalar_map_value (); |
1006 | 1005 |
1007 unwind_protect_safe frame; | 1006 unwind_protect_safe frame; |
1008 | 1007 |
1009 // Set up temporary scope to use for evaluating the text | 1008 // Set up temporary scope to use for evaluating the text |
1010 // that defines the anonymous function. | 1009 // that defines the anonymous function. |
1019 | 1018 |
1020 if (m2.nfields () > 0) | 1019 if (m2.nfields () > 0) |
1021 { | 1020 { |
1022 octave_value tmp; | 1021 octave_value tmp; |
1023 | 1022 |
1024 for (Octave_map::iterator p0 = m2.begin () ; | 1023 for (octave_map::iterator p0 = m2.begin () ; |
1025 p0 != m2.end (); p0++) | 1024 p0 != m2.end (); p0++) |
1026 { | 1025 { |
1027 std::string key = m2.key (p0); | 1026 std::string key = m2.key (p0); |
1028 octave_value val = m2.contents (p0)(0); | 1027 octave_value val = m2.contents (p0); |
1029 | 1028 |
1030 symbol_table::assign (key, val, local_scope, 0); | 1029 symbol_table::assign (key, val, local_scope, 0); |
1031 } | 1030 } |
1032 } | 1031 } |
1033 | 1032 |
1064 } | 1063 } |
1065 break; | 1064 break; |
1066 | 1065 |
1067 case MAT_FILE_WORKSPACE_CLASS: | 1066 case MAT_FILE_WORKSPACE_CLASS: |
1068 { | 1067 { |
1069 Octave_map m (dim_vector (1, 1)); | 1068 octave_map m (dim_vector (1, 1)); |
1070 int n_fields = 2; | 1069 int n_fields = 2; |
1071 string_vector field (n_fields); | 1070 string_vector field (n_fields); |
1072 | 1071 |
1073 for (int i = 0; i < n_fields; i++) | 1072 for (int i = 0; i < n_fields; i++) |
1074 { | 1073 { |
1075 int32_t fn_type; | 1074 int32_t fn_type; |
1076 int32_t fn_len; | 1075 int32_t fn_len; |
1077 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) || | 1076 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
1078 !INT8(fn_type)) | 1077 || !INT8(fn_type)) |
1079 { | 1078 { |
1080 error ("load: invalid field name subelement"); | 1079 error ("load: invalid field name subelement"); |
1081 goto data_read_error; | 1080 goto data_read_error; |
1082 } | 1081 } |
1083 | 1082 |
1162 } | 1161 } |
1163 } | 1162 } |
1164 // Fall-through | 1163 // Fall-through |
1165 case MAT_FILE_STRUCT_CLASS: | 1164 case MAT_FILE_STRUCT_CLASS: |
1166 { | 1165 { |
1167 Octave_map m (dims); | 1166 octave_map m (dims); |
1168 int32_t fn_type; | 1167 int32_t fn_type; |
1169 int32_t fn_len; | 1168 int32_t fn_len; |
1170 int32_t field_name_length; | 1169 int32_t field_name_length; |
1171 | 1170 |
1172 // field name length subelement -- actually the maximum length | 1171 // field name length subelement -- actually the maximum length |
1173 // of a field name. The Matlab docs promise this will always | 1172 // of a field name. The Matlab docs promise this will always |
1174 // be 32. We read and use the actual value, on the theory | 1173 // be 32. We read and use the actual value, on the theory |
1175 // that eventually someone will recognize that's a waste of | 1174 // that eventually someone will recognize that's a waste of space. |
1176 // space. | 1175 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
1177 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) || | 1176 || fn_type != miINT32) |
1178 fn_type != miINT32) | |
1179 { | 1177 { |
1180 error ("load: invalid field name length subelement"); | 1178 error ("load: invalid field name length subelement"); |
1181 goto data_read_error; | 1179 goto data_read_error; |
1182 } | 1180 } |
1183 | 1181 |
1187 if (swap) | 1185 if (swap) |
1188 swap_bytes<4> (&field_name_length); | 1186 swap_bytes<4> (&field_name_length); |
1189 | 1187 |
1190 // field name subelement. The length of this subelement tells | 1188 // field name subelement. The length of this subelement tells |
1191 // us how many fields there are. | 1189 // us how many fields there are. |
1192 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) || | 1190 if (read_mat5_tag (is, swap, fn_type, fn_len, is_small_data_element) |
1193 !INT8(fn_type)) | 1191 || !INT8(fn_type)) |
1194 { | 1192 { |
1195 error ("load: invalid field name subelement"); | 1193 error ("load: invalid field name subelement"); |
1196 goto data_read_error; | 1194 goto data_read_error; |
1197 } | 1195 } |
1198 | 1196 |
2235 } | 2233 } |
2236 } | 2234 } |
2237 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) | 2235 else if (tc.is_map () || tc.is_inline_function () || tc.is_object ()) |
2238 { | 2236 { |
2239 int fieldcnt = 0; | 2237 int fieldcnt = 0; |
2240 const Octave_map m = tc.map_value (); | 2238 const octave_map m = tc.map_value (); |
2241 octave_idx_type nel = m.numel (); | 2239 octave_idx_type nel = m.numel (); |
2242 | 2240 |
2243 if (tc.is_inline_function ()) | 2241 if (tc.is_inline_function ()) |
2244 // length of "inline" is 6 | 2242 // length of "inline" is 6 |
2245 ret += 8 + PAD (6 > max_namelen ? max_namelen : 6); | 2243 ret += 8 + PAD (6 > max_namelen ? max_namelen : 6); |
2248 size_t classlen = tc.class_name (). length (); | 2246 size_t classlen = tc.class_name (). length (); |
2249 | 2247 |
2250 ret += 8 + PAD (classlen > max_namelen ? max_namelen : classlen); | 2248 ret += 8 + PAD (classlen > max_namelen ? max_namelen : classlen); |
2251 } | 2249 } |
2252 | 2250 |
2253 for (Octave_map::const_iterator i = m.begin (); i != m.end (); i++) | 2251 for (octave_map::const_iterator i = m.begin (); i != m.end (); i++) |
2254 fieldcnt++; | 2252 fieldcnt++; |
2255 | 2253 |
2256 ret += 16 + fieldcnt * (max_namelen + 1); | 2254 ret += 16 + fieldcnt * (max_namelen + 1); |
2257 | 2255 |
2258 | 2256 |
2259 for (octave_idx_type j = 0; j < nel; j++) | 2257 for (octave_idx_type j = 0; j < nel; j++) |
2260 { | 2258 { |
2261 | 2259 |
2262 for (Octave_map::const_iterator i = m.begin (); i != m.end (); i++) | 2260 for (octave_map::const_iterator i = m.begin (); i != m.end (); i++) |
2263 { | 2261 { |
2264 const Cell elts = m.contents (i); | 2262 const Cell elts = m.contents (i); |
2265 | 2263 |
2266 ret += 8 + save_mat5_element_length (elts(j), "", | 2264 ret += 8 + save_mat5_element_length (elts(j), "", |
2267 save_as_floats, mat7_format); | 2265 save_as_floats, mat7_format); |
2665 memset (paddedname, 0, paddedlength); | 2663 memset (paddedname, 0, paddedlength); |
2666 strncpy (paddedname, classname.c_str (), namelen); | 2664 strncpy (paddedname, classname.c_str (), namelen); |
2667 os.write (paddedname, paddedlength); | 2665 os.write (paddedname, paddedlength); |
2668 } | 2666 } |
2669 | 2667 |
2670 Octave_map m; | 2668 octave_map m; |
2671 | 2669 |
2672 if (tc.is_object () && | 2670 if (tc.is_object () && |
2673 load_path::find_method (tc.class_name (), "saveobj") != std::string ()) | 2671 load_path::find_method (tc.class_name (), "saveobj") != std::string ()) |
2674 { | 2672 { |
2675 octave_value_list tmp = feval ("saveobj", tc, 1); | 2673 octave_value_list tmp = feval ("saveobj", tc, 1); |