Mercurial > octave
comparison libinterp/octave-value/ov-str-mat.cc @ 31138:b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
* ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base.h, ov-bool-mat.cc,
ov-bool-mat.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-cx-mat.cc,
ov-cx-mat.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-mat.cc,
ov-flt-re-mat.h, ov-intx.h, ov-re-mat.cc, ov-re-mat.h, ov-str-mat.cc,
ov-str-mat.h:
use "m_" prefix for member variables in class octave_base_matrix.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 10 Jul 2022 18:26:24 -0700 |
parents | 83f9f8bda883 |
children | aac27ad79be6 |
comparison
equal
deleted
inserted
replaced
31137:6308ce73bdca | 31138:b3ca7f891750 |
---|---|
103 try | 103 try |
104 { | 104 { |
105 switch (len) | 105 switch (len) |
106 { | 106 { |
107 case 0: | 107 case 0: |
108 retval = octave_value (matrix, type); | 108 retval = octave_value (m_matrix, type); |
109 break; | 109 break; |
110 | 110 |
111 case 1: | 111 case 1: |
112 { | 112 { |
113 octave::idx_vector i = idx (0).index_vector (); | 113 octave::idx_vector i = idx (0).index_vector (); |
114 | 114 |
115 retval = octave_value (charNDArray (matrix.index (i, resize_ok)), | 115 retval = octave_value (charNDArray (m_matrix.index (i, resize_ok)), |
116 type); | 116 type); |
117 } | 117 } |
118 break; | 118 break; |
119 | 119 |
120 case 2: | 120 case 2: |
121 { | 121 { |
122 octave::idx_vector i = idx (0).index_vector (); | 122 octave::idx_vector i = idx (0).index_vector (); |
123 k = 1; | 123 k = 1; |
124 octave::idx_vector j = idx (1).index_vector (); | 124 octave::idx_vector j = idx (1).index_vector (); |
125 | 125 |
126 retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), | 126 retval = octave_value (charNDArray (m_matrix.index (i, j, resize_ok)), |
127 type); | 127 type); |
128 } | 128 } |
129 break; | 129 break; |
130 | 130 |
131 default: | 131 default: |
133 Array<octave::idx_vector> idx_vec (dim_vector (len, 1)); | 133 Array<octave::idx_vector> idx_vec (dim_vector (len, 1)); |
134 | 134 |
135 for (k = 0; k < len; k++) | 135 for (k = 0; k < len; k++) |
136 idx_vec(k) = idx(k).index_vector (); | 136 idx_vec(k) = idx(k).index_vector (); |
137 | 137 |
138 retval = octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), type); | 138 retval = octave_value (charNDArray (m_matrix.index (idx_vec, resize_ok)), type); |
139 } | 139 } |
140 break; | 140 break; |
141 } | 141 } |
142 } | 142 } |
143 catch (octave::index_exception& ie) | 143 catch (octave::index_exception& ie) |
151 } | 151 } |
152 | 152 |
153 octave_value | 153 octave_value |
154 octave_char_matrix_str::resize (const dim_vector& dv, bool fill) const | 154 octave_char_matrix_str::resize (const dim_vector& dv, bool fill) const |
155 { | 155 { |
156 charNDArray retval (matrix); | 156 charNDArray retval (m_matrix); |
157 if (fill) | 157 if (fill) |
158 retval.resize (dv, 0); | 158 retval.resize (dv, 0); |
159 else | 159 else |
160 retval.resize (dv); | 160 retval.resize (dv); |
161 return octave_value (retval, is_sq_string () ? '\'' : '"'); | 161 return octave_value (retval, is_sq_string () ? '\'' : '"'); |
209 string_vector | 209 string_vector |
210 octave_char_matrix_str::string_vector_value (bool) const | 210 octave_char_matrix_str::string_vector_value (bool) const |
211 { | 211 { |
212 string_vector retval; | 212 string_vector retval; |
213 | 213 |
214 if (matrix.ndims () != 2) | 214 if (m_matrix.ndims () != 2) |
215 error ("invalid conversion of charNDArray to string_vector"); | 215 error ("invalid conversion of charNDArray to string_vector"); |
216 | 216 |
217 charMatrix chm (matrix); | 217 charMatrix chm (m_matrix); |
218 | 218 |
219 octave_idx_type n = chm.rows (); | 219 octave_idx_type n = chm.rows (); |
220 | 220 |
221 retval.resize (n); | 221 retval.resize (n); |
222 | 222 |
227 } | 227 } |
228 | 228 |
229 std::string | 229 std::string |
230 octave_char_matrix_str::string_value (bool) const | 230 octave_char_matrix_str::string_value (bool) const |
231 { | 231 { |
232 if (matrix.ndims () != 2) | 232 if (m_matrix.ndims () != 2) |
233 error ("invalid conversion of charNDArray to string"); | 233 error ("invalid conversion of charNDArray to string"); |
234 | 234 |
235 charMatrix chm (matrix); | 235 charMatrix chm (m_matrix); |
236 | 236 |
237 if (chm.rows () > 1) | 237 if (chm.rows () > 1) |
238 warning_with_id ("Octave:charmat-truncated", | 238 warning_with_id ("Octave:charmat-truncated", |
239 "multi-row character matrix converted to a string, only the first row is used"); | 239 "multi-row character matrix converted to a string, only the first row is used"); |
240 | 240 |
254 Array<std::string> | 254 Array<std::string> |
255 octave_char_matrix_str::cellstr_value (void) const | 255 octave_char_matrix_str::cellstr_value (void) const |
256 { | 256 { |
257 Array<std::string> retval; | 257 Array<std::string> retval; |
258 | 258 |
259 if (matrix.ndims () != 2) | 259 if (m_matrix.ndims () != 2) |
260 error ("cellstr: cannot convert multidimensional arrays"); | 260 error ("cellstr: cannot convert multidimensional arrays"); |
261 | 261 |
262 const charMatrix chm (matrix); | 262 const charMatrix chm (m_matrix); |
263 octave_idx_type nr = chm.rows (); | 263 octave_idx_type nr = chm.rows (); |
264 retval.clear (nr, 1); | 264 retval.clear (nr, 1); |
265 for (octave_idx_type i = 0; i < nr; i++) | 265 for (octave_idx_type i = 0; i < nr; i++) |
266 retval.xelem (i) = chm.row_as_string (i); | 266 retval.xelem (i) = chm.row_as_string (i); |
267 | 267 |
270 | 270 |
271 void | 271 void |
272 octave_char_matrix_str::print_raw (std::ostream& os, | 272 octave_char_matrix_str::print_raw (std::ostream& os, |
273 bool pr_as_read_syntax) const | 273 bool pr_as_read_syntax) const |
274 { | 274 { |
275 octave_print_internal (os, matrix, pr_as_read_syntax, | 275 octave_print_internal (os, m_matrix, pr_as_read_syntax, |
276 current_print_indent_level (), true); | 276 current_print_indent_level (), true); |
277 } | 277 } |
278 | 278 |
279 void | 279 void |
280 octave_char_matrix_str::short_disp (std::ostream& os) const | 280 octave_char_matrix_str::short_disp (std::ostream& os) const |
281 { | 281 { |
282 if (matrix.ndims () == 2 && numel () > 0) | 282 if (m_matrix.ndims () == 2 && numel () > 0) |
283 { | 283 { |
284 charMatrix chm (matrix); | 284 charMatrix chm (m_matrix); |
285 std::string tmp = chm.row_as_string (0); | 285 std::string tmp = chm.row_as_string (0); |
286 | 286 |
287 // FIXME: should this be configurable? | 287 // FIXME: should this be configurable? |
288 std::size_t max_len = 100; | 288 std::size_t max_len = 100; |
289 | 289 |
310 else if (is_zero_by_zero ()) | 310 else if (is_zero_by_zero ()) |
311 return ""; | 311 return ""; |
312 } | 312 } |
313 | 313 |
314 std::string tname = type_name (); | 314 std::string tname = type_name (); |
315 dim_vector dv = matrix.dims (); | 315 dim_vector dv = m_matrix.dims (); |
316 std::string dimstr = dv.str (); | 316 std::string dimstr = dv.str (); |
317 return "[" + dimstr + " " + tname + "]"; | 317 return "[" + dimstr + " " + tname + "]"; |
318 } | 318 } |
319 | 319 |
320 bool | 320 bool |
386 error ("load: failed to read dimensions"); | 386 error ("load: failed to read dimensions"); |
387 | 387 |
388 charNDArray tmp(dv); | 388 charNDArray tmp(dv); |
389 | 389 |
390 if (tmp.isempty ()) | 390 if (tmp.isempty ()) |
391 matrix = tmp; | 391 m_matrix = tmp; |
392 else | 392 else |
393 { | 393 { |
394 char *ftmp = tmp.fortran_vec (); | 394 char *ftmp = tmp.fortran_vec (); |
395 | 395 |
396 octave::skip_preceeding_newline (is); | 396 octave::skip_preceeding_newline (is); |
397 | 397 |
398 if (! is.read (ftmp, dv.numel ()) || ! is) | 398 if (! is.read (ftmp, dv.numel ()) || ! is) |
399 error ("load: failed to load string constant"); | 399 error ("load: failed to load string constant"); |
400 | 400 |
401 matrix = tmp; | 401 m_matrix = tmp; |
402 } | 402 } |
403 } | 403 } |
404 else if (kw == "elements") | 404 else if (kw == "elements") |
405 { | 405 { |
406 int elements = val; | 406 int elements = val; |
435 } | 435 } |
436 | 436 |
437 chm.insert (tmp, i, 0); | 437 chm.insert (tmp, i, 0); |
438 } | 438 } |
439 | 439 |
440 matrix = chm; | 440 m_matrix = chm; |
441 } | 441 } |
442 else if (kw == "length") | 442 else if (kw == "length") |
443 { | 443 { |
444 int len = val; | 444 int len = val; |
445 | 445 |
457 error ("load: failed to load string constant"); | 457 error ("load: failed to load string constant"); |
458 | 458 |
459 if (! is) | 459 if (! is) |
460 error ("load: failed to load string constant"); | 460 error ("load: failed to load string constant"); |
461 | 461 |
462 matrix = tmp; | 462 m_matrix = tmp; |
463 } | 463 } |
464 } | 464 } |
465 else | 465 else |
466 panic_impossible (); | 466 panic_impossible (); |
467 | 467 |
533 is.read (tmp, dv.numel ()); | 533 is.read (tmp, dv.numel ()); |
534 | 534 |
535 if (! is) | 535 if (! is) |
536 return false; | 536 return false; |
537 | 537 |
538 matrix = m; | 538 m_matrix = m; |
539 } | 539 } |
540 else | 540 else |
541 { | 541 { |
542 charMatrix chm (elements, 0); | 542 charMatrix chm (elements, 0); |
543 int max_len = 0; | 543 int max_len = 0; |
557 max_len = len; | 557 max_len = len; |
558 chm.resize (elements, max_len, 0); | 558 chm.resize (elements, max_len, 0); |
559 } | 559 } |
560 chm.insert (btmp, i, 0); | 560 chm.insert (btmp, i, 0); |
561 } | 561 } |
562 matrix = chm; | 562 m_matrix = chm; |
563 } | 563 } |
564 return true; | 564 return true; |
565 } | 565 } |
566 | 566 |
567 bool | 567 bool |
634 #if defined (HAVE_HDF5) | 634 #if defined (HAVE_HDF5) |
635 | 635 |
636 dim_vector dv; | 636 dim_vector dv; |
637 int empty = load_hdf5_empty (loc_id, name, dv); | 637 int empty = load_hdf5_empty (loc_id, name, dv); |
638 if (empty > 0) | 638 if (empty > 0) |
639 matrix.resize (dv); | 639 m_matrix.resize (dv); |
640 if (empty) | 640 if (empty) |
641 return (empty > 0); | 641 return (empty > 0); |
642 | 642 |
643 #if defined (HAVE_HDF5_18) | 643 #if defined (HAVE_HDF5_18) |
644 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT); | 644 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT); |
683 char *str = m.fortran_vec (); | 683 char *str = m.fortran_vec (); |
684 if (H5Dread (data_hid, H5T_NATIVE_CHAR, octave_H5S_ALL, octave_H5S_ALL, | 684 if (H5Dread (data_hid, H5T_NATIVE_CHAR, octave_H5S_ALL, octave_H5S_ALL, |
685 octave_H5P_DEFAULT, str) >= 0) | 685 octave_H5P_DEFAULT, str) >= 0) |
686 { | 686 { |
687 retval = true; | 687 retval = true; |
688 matrix = m; | 688 m_matrix = m; |
689 } | 689 } |
690 | 690 |
691 H5Tclose (type_hid); | 691 H5Tclose (type_hid); |
692 H5Sclose (space_hid); | 692 H5Sclose (space_hid); |
693 H5Dclose (data_hid); | 693 H5Dclose (data_hid); |
721 H5Sclose (space_hid); | 721 H5Sclose (space_hid); |
722 H5Dclose (data_hid); | 722 H5Dclose (data_hid); |
723 return false; | 723 return false; |
724 } | 724 } |
725 | 725 |
726 matrix = charMatrix (s); | 726 m_matrix = charMatrix (s); |
727 | 727 |
728 H5Tclose (st_id); | 728 H5Tclose (st_id); |
729 H5Tclose (type_hid); | 729 H5Tclose (type_hid); |
730 H5Sclose (space_hid); | 730 H5Sclose (space_hid); |
731 H5Dclose (data_hid); | 731 H5Dclose (data_hid); |
772 for (hsize_t i = 0; i < elements; ++i) | 772 for (hsize_t i = 0; i < elements; ++i) |
773 { | 773 { |
774 chm.insert (s + i*(slen+1), i, 0); | 774 chm.insert (s + i*(slen+1), i, 0); |
775 } | 775 } |
776 | 776 |
777 matrix = chm; | 777 m_matrix = chm; |
778 | 778 |
779 H5Tclose (st_id); | 779 H5Tclose (st_id); |
780 H5Tclose (type_hid); | 780 H5Tclose (type_hid); |
781 H5Sclose (space_hid); | 781 H5Sclose (space_hid); |
782 H5Dclose (data_hid); | 782 H5Dclose (data_hid); |