comparison src/ov-fcn-handle.cc @ 4989:19b73a80e1d9

[project @ 2004-09-11 13:31:43 by jwe]
author jwe
date Sat, 11 Sep 2004 13:31:43 +0000
parents 352d228d409b
children 21b4124e31af
comparison
equal deleted inserted replaced
4988:352d228d409b 4989:19b73a80e1d9
99 99
100 bool 100 bool
101 octave_fcn_handle::save_ascii (std::ostream& os, bool&, bool) 101 octave_fcn_handle::save_ascii (std::ostream& os, bool&, bool)
102 { 102 {
103 os << nm << "\n"; 103 os << nm << "\n";
104
104 if (nm == "@<anonymous>") 105 if (nm == "@<anonymous>")
105 { 106 {
106 OSSTREAM buf; 107 print_raw (os, true);
107 print_raw (buf, true); 108 os << "\n";
108 os << OSSTREAM_STR (buf) << "\n" << OSSTREAM_ENDS;
109 OSSTREAM_FREEZE (buf);
110 } 109 }
111 110
112 return true; 111 return true;
113 } 112 }
114 113
115 bool 114 bool
116 octave_fcn_handle::load_ascii (std::istream& is) 115 octave_fcn_handle::load_ascii (std::istream& is)
117 { 116 {
118 is >> nm; 117 is >> nm;
118
119 if (nm == "@<anonymous>") 119 if (nm == "@<anonymous>")
120 { 120 {
121 char c; 121 char c;
122 OSSTREAM buf; 122 OSSTREAM buf;
123 123
124 // Skip preceeding newline(s) 124 // Skip preceeding newline(s).
125 while (is.get (c) && c == '\n'); 125 while (is.get (c) && c == '\n')
126 /* do nothing */;
126 127
127 if (is) 128 if (is)
128 { 129 {
129 buf << c; 130 buf << c;
130 131
131 // Get a line of text whitespace characters included, leaving 132 // Get a line of text whitespace characters included, leaving
132 // newline in the stream 133 // newline in the stream.
134
133 while (is.peek () != '\n') 135 while (is.peek () != '\n')
134 { 136 {
135 is.get (c); 137 is.get (c);
136 if (! is) 138 if (! is)
137 break; 139 break;
140 } 142 }
141 143
142 buf << OSSTREAM_ENDS; 144 buf << OSSTREAM_ENDS;
143 145
144 int parse_status; 146 int parse_status;
145 octave_value anon_fcn_handle = eval_string (OSSTREAM_C_STR (buf), 147 octave_value anon_fcn_handle = eval_string (OSSTREAM_STR (buf),
146 true, parse_status); 148 true, parse_status);
147 OSSTREAM_FREEZE (buf); 149 OSSTREAM_FREEZE (buf);
148 150
149 fcn = anon_fcn_handle.fcn_handle_value () -> fcn; 151 if (parse_status == 0)
152 {
153 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value ();
154 if (fh)
155 fcn = fh->fcn;
156 else
157 return false;
158 }
159 else
160 return false;
150 } 161 }
151 else 162 else
152 { 163 {
153 fcn = lookup_function (nm); 164 fcn = lookup_function (nm);
154 if (! fcn.is_function ()) 165 if (! fcn.is_function ())
205 is.read (ctmp2, tmp); 216 is.read (ctmp2, tmp);
206 217
207 int parse_status; 218 int parse_status;
208 octave_value anon_fcn_handle = eval_string (ctmp2, true, parse_status); 219 octave_value anon_fcn_handle = eval_string (ctmp2, true, parse_status);
209 220
210 fcn = anon_fcn_handle.fcn_handle_value () -> fcn; 221 if (parse_status == 0)
222 {
223 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value ();
224 if (fh)
225 fcn = fh->fcn;
226 else
227 return false;
228 }
229 else
230 return false;
211 } 231 }
212 else 232 else
213 { 233 {
214 fcn = lookup_function (nm); 234 fcn = lookup_function (nm);
215 if (! fcn.is_function ()) 235 if (! fcn.is_function ())
250 return false; 270 return false;
251 } 271 }
252 272
253 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); 273 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT);
254 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, 274 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
255 H5P_DEFAULT, (void*) nm.c_str ()) < 0) 275 H5P_DEFAULT,
276 static_cast<void*> (nm.c_str ())) < 0)
256 { 277 {
257 H5Sclose (space_hid); 278 H5Sclose (space_hid);
258 H5Tclose (type_hid); 279 H5Tclose (type_hid);
259 H5Gclose (group_hid); 280 H5Gclose (group_hid);
260 return false; 281 return false;
277 } 298 }
278 299
279 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, 300 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
280 H5P_DEFAULT); 301 H5P_DEFAULT);
281 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, 302 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL,
282 H5P_DEFAULT, (void*) stmp.c_str ()) < 0) 303 H5P_DEFAULT,
304 static_cast<void*> (stmp.c_str ())) < 0)
283 { 305 {
284 H5Sclose (space_hid); 306 H5Sclose (space_hid);
285 H5Tclose (type_hid); 307 H5Tclose (type_hid);
286 H5Gclose (group_hid); 308 H5Gclose (group_hid);
287 return false; 309 return false;
428 H5Tclose (st_id); 450 H5Tclose (st_id);
429 451
430 int parse_status; 452 int parse_status;
431 octave_value anon_fcn_handle = eval_string (fcn_tmp, true, parse_status); 453 octave_value anon_fcn_handle = eval_string (fcn_tmp, true, parse_status);
432 454
433 fcn = anon_fcn_handle.fcn_handle_value () -> fcn; 455 if (parse_status == 0)
456 {
457 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value ();
458 if (fh)
459 fcn = fh->fcn;
460 else
461 return false;
462 }
463 else
464 return false;
434 } 465 }
435 else 466 else
436 { 467 {
437 fcn = lookup_function (nm); 468 fcn = lookup_function (nm);
438 if (! fcn.is_function ()) 469 if (! fcn.is_function ())
457 488
458 if (nm == "@<anonymous>") 489 if (nm == "@<anonymous>")
459 { 490 {
460 tree_print_code tpc (os); 491 tree_print_code tpc (os);
461 492
462 // FCN is const becuase this member function is, so we can't 493 // FCN is const because this member function is, so we can't
463 // use it to call user_function_value, so we make a copy first. 494 // use it to call user_function_value, so we make a copy first.
464 495
465 octave_value ftmp = fcn; 496 octave_value ftmp = fcn;
466 497
467 octave_user_function *f = ftmp.user_function_value (); 498 octave_user_function *f = ftmp.user_function_value ();