Mercurial > hg > octave-nkf
comparison src/ov-str-mat.cc @ 5099:f7e39f977fe8
[project @ 2004-12-24 19:06:01 by jwe]
author | jwe |
---|---|
date | Fri, 24 Dec 2004 19:06:01 +0000 |
parents | 55f5b61d74b7 |
children | e35b034d3523 |
comparison
equal
deleted
inserted
replaced
5098:ab4e64f92526 | 5099:f7e39f977fe8 |
---|---|
292 } | 292 } |
293 | 293 |
294 bool | 294 bool |
295 octave_char_matrix_str::load_ascii (std::istream& is) | 295 octave_char_matrix_str::load_ascii (std::istream& is) |
296 { | 296 { |
297 int mdims = 0; | |
298 bool success = true; | 297 bool success = true; |
299 std::streampos pos = is.tellg (); | 298 |
300 | 299 string_vector keywords(3); |
301 if (extract_keyword (is, "ndims", mdims, true)) | 300 |
302 { | 301 keywords[0] = "ndims"; |
303 if (mdims >= 0) | 302 keywords[1] = "elements"; |
304 { | 303 keywords[2] = "length"; |
305 dim_vector dv; | 304 |
306 dv.resize (mdims); | 305 std::string kw; |
307 | 306 int val = 0; |
308 for (int i = 0; i < mdims; i++) | 307 |
309 is >> dv(i); | 308 if (extract_keyword (is, keywords, kw, val, true)) |
310 | 309 { |
311 charNDArray tmp(dv); | 310 if (kw == "ndims") |
312 char *ftmp = tmp.fortran_vec (); | 311 { |
313 | 312 int mdims = val; |
314 // Skip the return line | 313 |
315 if (! is.read (ftmp, 1)) | 314 if (mdims >= 0) |
316 return false; | 315 { |
317 | 316 dim_vector dv; |
318 if (! is.read (ftmp, dv.numel ()) || !is) | 317 dv.resize (mdims); |
319 { | 318 |
320 error ("load: failed to load string constant"); | 319 for (int i = 0; i < mdims; i++) |
320 is >> dv(i); | |
321 | |
322 charNDArray tmp(dv); | |
323 char *ftmp = tmp.fortran_vec (); | |
324 | |
325 // Skip the return line | |
326 if (! is.read (ftmp, 1)) | |
327 return false; | |
328 | |
329 if (! is.read (ftmp, dv.numel ()) || !is) | |
330 { | |
331 error ("load: failed to load string constant"); | |
332 success = false; | |
333 } | |
334 else | |
335 matrix = tmp; | |
336 } | |
337 else | |
338 { | |
339 error ("load: failed to extract matrix size"); | |
321 success = false; | 340 success = false; |
322 } | 341 } |
323 else | 342 } |
324 matrix = tmp; | 343 else if (kw == "elements") |
325 } | 344 { |
326 else | 345 int elements = val; |
327 { | |
328 error ("load: failed to extract matrix size"); | |
329 success = false; | |
330 } | |
331 } | |
332 else | |
333 { | |
334 int elements; | |
335 | |
336 // re-read the same line again | |
337 is.clear (); | |
338 is.seekg (pos); | |
339 | |
340 if (extract_keyword (is, "elements", elements, true)) | |
341 { | |
342 | 346 |
343 if (elements >= 0) | 347 if (elements >= 0) |
344 { | 348 { |
345 // XXX FIXME XXX -- need to be able to get max length | 349 // XXX FIXME XXX -- need to be able to get max length |
346 // before doing anything. | 350 // before doing anything. |
380 } | 384 } |
381 } | 385 } |
382 | 386 |
383 if (! error_state) | 387 if (! error_state) |
384 matrix = chm; | 388 matrix = chm; |
385 | |
386 } | 389 } |
387 else | 390 else |
388 { | 391 { |
389 error ("load: failed to extract number of string elements"); | 392 error ("load: failed to extract number of string elements"); |
390 success = false; | 393 success = false; |
391 } | 394 } |
392 } | 395 } |
393 else | 396 else if (kw == "length") |
394 { | 397 { |
395 // re-read the same line again | 398 int len = val; |
396 is.clear (); | |
397 is.seekg (pos); | |
398 | |
399 int len; | |
400 | 399 |
401 if (extract_keyword (is, "length", len) && len >= 0) | 400 if (len >= 0) |
402 { | 401 { |
403 // This is cruft for backward compatiability, | 402 // This is cruft for backward compatiability, |
404 // but relatively harmless. | 403 // but relatively harmless. |
405 | 404 |
406 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); | 405 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); |
418 else | 417 else |
419 error ("load: failed to load string constant"); | 418 error ("load: failed to load string constant"); |
420 } | 419 } |
421 } | 420 } |
422 } | 421 } |
422 else | |
423 panic_impossible (); | |
424 } | |
425 else | |
426 { | |
427 error ("load: failed to extract number of rows and columns"); | |
428 success = false; | |
423 } | 429 } |
424 | 430 |
425 return success; | 431 return success; |
426 } | 432 } |
427 | 433 |