Mercurial > hg > octave-nkf
comparison src/ov-str-mat.cc @ 5760:8d7162924bd3
[project @ 2006-04-14 04:01:37 by jwe]
author | jwe |
---|---|
date | Fri, 14 Apr 2006 04:01:40 +0000 |
parents | ce79d238f142 |
children | ace8d8d26933 |
comparison
equal
deleted
inserted
replaced
5759:ce79d238f142 | 5760:8d7162924bd3 |
---|---|
285 charNDArray tmp = char_array_value (); | 285 charNDArray tmp = char_array_value (); |
286 os << "# ndims: " << d.length () << "\n"; | 286 os << "# ndims: " << d.length () << "\n"; |
287 for (int i=0; i < d.length (); i++) | 287 for (int i=0; i < d.length (); i++) |
288 os << " " << d (i); | 288 os << " " << d (i); |
289 os << "\n"; | 289 os << "\n"; |
290 os.write (X_CAST (char *, tmp.fortran_vec ()), d.numel ()); | 290 os.write (tmp.fortran_vec (), d.numel ()); |
291 os << "\n"; | 291 os << "\n"; |
292 } | 292 } |
293 else | 293 else |
294 { | 294 { |
295 // Keep this case, rather than use generic code above for | 295 // Keep this case, rather than use generic code above for |
303 os << "# length: " << len << "\n"; | 303 os << "# length: " << len << "\n"; |
304 std::string tstr = chm.row_as_string (i, false, true); | 304 std::string tstr = chm.row_as_string (i, false, true); |
305 const char *tmp = tstr.data (); | 305 const char *tmp = tstr.data (); |
306 if (tstr.length () > len) | 306 if (tstr.length () > len) |
307 panic_impossible (); | 307 panic_impossible (); |
308 os.write (X_CAST (char *, tmp), len); | 308 os.write (tmp, len); |
309 os << "\n"; | 309 os << "\n"; |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 return true; | 313 return true; |
379 if (extract_keyword (is, "length", len) && len >= 0) | 379 if (extract_keyword (is, "length", len) && len >= 0) |
380 { | 380 { |
381 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); | 381 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); |
382 | 382 |
383 if (len > 0 && ! | 383 if (len > 0 && ! |
384 is.read (X_CAST (char *, tmp), len)) | 384 is.read (tmp, len)) |
385 { | 385 { |
386 error ("load: failed to load string constant"); | 386 error ("load: failed to load string constant"); |
387 success = false; | 387 success = false; |
388 break; | 388 break; |
389 } | 389 } |
424 // This is cruft for backward compatiability, | 424 // This is cruft for backward compatiability, |
425 // but relatively harmless. | 425 // but relatively harmless. |
426 | 426 |
427 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); | 427 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); |
428 | 428 |
429 if (len > 0 && ! is.read (X_CAST (char *, tmp), len)) | 429 if (len > 0 && ! is.read (tmp, len)) |
430 { | 430 { |
431 error ("load: failed to load string constant"); | 431 error ("load: failed to load string constant"); |
432 } | 432 } |
433 else | 433 else |
434 { | 434 { |
461 if (d.length() < 1) | 461 if (d.length() < 1) |
462 return false; | 462 return false; |
463 | 463 |
464 // Use negative value for ndims to differentiate with old format!! | 464 // Use negative value for ndims to differentiate with old format!! |
465 FOUR_BYTE_INT tmp = - d.length(); | 465 FOUR_BYTE_INT tmp = - d.length(); |
466 os.write (X_CAST (char *, &tmp), 4); | 466 os.write (reinterpret_cast<char *> (&tmp), 4); |
467 for (int i=0; i < d.length (); i++) | 467 for (int i=0; i < d.length (); i++) |
468 { | 468 { |
469 tmp = d(i); | 469 tmp = d(i); |
470 os.write (X_CAST (char *, &tmp), 4); | 470 os.write (reinterpret_cast<char *> (&tmp), 4); |
471 } | 471 } |
472 | 472 |
473 charNDArray m = char_array_value (); | 473 charNDArray m = char_array_value (); |
474 os.write (m.fortran_vec (), d.numel ()); | 474 os.write (m.fortran_vec (), d.numel ()); |
475 return true; | 475 return true; |
478 bool | 478 bool |
479 octave_char_matrix_str::load_binary (std::istream& is, bool swap, | 479 octave_char_matrix_str::load_binary (std::istream& is, bool swap, |
480 oct_mach_info::float_format /* fmt */) | 480 oct_mach_info::float_format /* fmt */) |
481 { | 481 { |
482 FOUR_BYTE_INT elements; | 482 FOUR_BYTE_INT elements; |
483 if (! is.read (X_CAST (char *, &elements), 4)) | 483 if (! is.read (reinterpret_cast<char *> (&elements), 4)) |
484 return false; | 484 return false; |
485 if (swap) | 485 if (swap) |
486 swap_bytes<4> (&elements); | 486 swap_bytes<4> (&elements); |
487 | 487 |
488 if (elements < 0) | 488 if (elements < 0) |
492 dim_vector dv; | 492 dim_vector dv; |
493 dv.resize (mdims); | 493 dv.resize (mdims); |
494 | 494 |
495 for (int i = 0; i < mdims; i++) | 495 for (int i = 0; i < mdims; i++) |
496 { | 496 { |
497 if (! is.read (X_CAST (char *, &di), 4)) | 497 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
498 return false; | 498 return false; |
499 if (swap) | 499 if (swap) |
500 swap_bytes<4> (&di); | 500 swap_bytes<4> (&di); |
501 dv(i) = di; | 501 dv(i) = di; |
502 } | 502 } |
526 charMatrix chm (elements, 0); | 526 charMatrix chm (elements, 0); |
527 int max_len = 0; | 527 int max_len = 0; |
528 for (int i = 0; i < elements; i++) | 528 for (int i = 0; i < elements; i++) |
529 { | 529 { |
530 FOUR_BYTE_INT len; | 530 FOUR_BYTE_INT len; |
531 if (! is.read (X_CAST (char *, &len), 4)) | 531 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
532 return false; | 532 return false; |
533 if (swap) | 533 if (swap) |
534 swap_bytes<4> (&len); | 534 swap_bytes<4> (&len); |
535 OCTAVE_LOCAL_BUFFER (char, btmp, len+1); | 535 OCTAVE_LOCAL_BUFFER (char, btmp, len+1); |
536 if (! is.read (X_CAST (char *, btmp), len)) | 536 if (! is.read (reinterpret_cast<char *> (btmp), len)) |
537 return false; | 537 return false; |
538 if (len > max_len) | 538 if (len > max_len) |
539 { | 539 { |
540 max_len = len; | 540 max_len = len; |
541 chm.resize (elements, max_len, 0); | 541 chm.resize (elements, max_len, 0); |
678 OCTAVE_LOCAL_BUFFER (char, s, slen); | 678 OCTAVE_LOCAL_BUFFER (char, s, slen); |
679 // create datatype for (null-terminated) string | 679 // create datatype for (null-terminated) string |
680 // to read into: | 680 // to read into: |
681 hid_t st_id = H5Tcopy (H5T_C_S1); | 681 hid_t st_id = H5Tcopy (H5T_C_S1); |
682 H5Tset_size (st_id, slen); | 682 H5Tset_size (st_id, slen); |
683 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, | 683 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) |
684 H5P_DEFAULT, (void *) s) < 0) | |
685 { | 684 { |
686 H5Tclose (st_id); | 685 H5Tclose (st_id); |
687 H5Tclose (type_hid); | 686 H5Tclose (type_hid); |
688 H5Sclose (space_hid); | 687 H5Sclose (space_hid); |
689 H5Dclose (data_hid); | 688 H5Dclose (data_hid); |
723 // create datatype for (null-terminated) string | 722 // create datatype for (null-terminated) string |
724 // to read into: | 723 // to read into: |
725 hid_t st_id = H5Tcopy (H5T_C_S1); | 724 hid_t st_id = H5Tcopy (H5T_C_S1); |
726 H5Tset_size (st_id, slen); | 725 H5Tset_size (st_id, slen); |
727 | 726 |
728 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, | 727 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) |
729 H5P_DEFAULT, (void *) s) < 0) | |
730 { | 728 { |
731 H5Tclose (st_id); | 729 H5Tclose (st_id); |
732 H5Tclose (type_hid); | 730 H5Tclose (type_hid); |
733 H5Sclose (space_hid); | 731 H5Sclose (space_hid); |
734 H5Dclose (data_hid); | 732 H5Dclose (data_hid); |