Mercurial > octave
comparison libinterp/corefcn/oct-stream.cc @ 30120:14af343e4263
maint: Use "m_" prefix for member variables in class printf_value_cache.
* oct-stream.cc: Use "m_" prefix for member variables in class
printf_value_cache. Order member functions before member variables.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 06 Sep 2021 09:16:58 -0700 |
parents | fa45724a7fc8 |
children | bb7ac72c394e |
comparison
equal
deleted
inserted
replaced
30119:3161a1ee0045 | 30120:14af343e4263 |
---|---|
5408 public: | 5408 public: |
5409 | 5409 |
5410 enum state { ok, conversion_error }; | 5410 enum state { ok, conversion_error }; |
5411 | 5411 |
5412 printf_value_cache (const octave_value_list& args, const std::string& who) | 5412 printf_value_cache (const octave_value_list& args, const std::string& who) |
5413 : values (args), val_idx (0), elt_idx (0), | 5413 : m_values (args), m_val_idx (0), m_elt_idx (0), |
5414 n_vals (values.length ()), n_elts (0), have_data (false), | 5414 m_n_vals (m_values.length ()), m_n_elts (0), m_have_data (false), |
5415 curr_state (ok) | 5415 m_curr_state (ok) |
5416 { | 5416 { |
5417 for (octave_idx_type i = 0; i < values.length (); i++) | 5417 for (octave_idx_type i = 0; i < m_values.length (); i++) |
5418 { | 5418 { |
5419 octave_value val = values(i); | 5419 octave_value val = m_values(i); |
5420 | 5420 |
5421 if (val.isstruct () || val.iscell () || val.isobject ()) | 5421 if (val.isstruct () || val.iscell () || val.isobject ()) |
5422 err_wrong_type_arg (who, val); | 5422 err_wrong_type_arg (who, val); |
5423 } | 5423 } |
5424 } | 5424 } |
5438 // pointer. Value before conversion to int must be >= 0 and less | 5438 // pointer. Value before conversion to int must be >= 0 and less |
5439 // than std::numeric_limits<int>::max (). | 5439 // than std::numeric_limits<int>::max (). |
5440 | 5440 |
5441 int int_value (void); | 5441 int int_value (void); |
5442 | 5442 |
5443 operator bool () const { return (curr_state == ok); } | 5443 operator bool () const { return (m_curr_state == ok); } |
5444 | 5444 |
5445 bool exhausted (void) { return (val_idx >= n_vals); } | 5445 bool exhausted (void) { return (m_val_idx >= m_n_vals); } |
5446 | 5446 |
5447 private: | 5447 private: |
5448 | 5448 |
5449 const octave_value_list values; | |
5450 octave_idx_type val_idx; | |
5451 octave_idx_type elt_idx; | |
5452 octave_idx_type n_vals; | |
5453 octave_idx_type n_elts; | |
5454 bool have_data; | |
5455 octave_value curr_val; | |
5456 state curr_state; | |
5457 | |
5458 // Must create value cache with values! | 5449 // Must create value cache with values! |
5459 | |
5460 printf_value_cache (void); | 5450 printf_value_cache (void); |
5451 | |
5452 //-------- | |
5453 | |
5454 const octave_value_list m_values; | |
5455 octave_idx_type m_val_idx; | |
5456 octave_idx_type m_elt_idx; | |
5457 octave_idx_type m_n_vals; | |
5458 octave_idx_type m_n_elts; | |
5459 bool m_have_data; | |
5460 octave_value m_curr_val; | |
5461 state m_curr_state; | |
5461 }; | 5462 }; |
5462 | 5463 |
5463 octave_value | 5464 octave_value |
5464 printf_value_cache::get_next_value (char type) | 5465 printf_value_cache::get_next_value (char type) |
5465 { | 5466 { |
5466 octave_value retval; | 5467 octave_value retval; |
5467 | 5468 |
5468 if (exhausted ()) | 5469 if (exhausted ()) |
5469 curr_state = conversion_error; | 5470 m_curr_state = conversion_error; |
5470 | 5471 |
5471 while (! exhausted ()) | 5472 while (! exhausted ()) |
5472 { | 5473 { |
5473 if (! have_data) | 5474 if (! m_have_data) |
5474 { | 5475 { |
5475 curr_val = values (val_idx); | 5476 m_curr_val = m_values (m_val_idx); |
5476 | 5477 |
5477 elt_idx = 0; | 5478 m_elt_idx = 0; |
5478 n_elts = curr_val.numel (); | 5479 m_n_elts = m_curr_val.numel (); |
5479 have_data = true; | 5480 m_have_data = true; |
5480 } | 5481 } |
5481 | 5482 |
5482 if (elt_idx < n_elts) | 5483 if (m_elt_idx < m_n_elts) |
5483 { | 5484 { |
5484 if (type == 's') | 5485 if (type == 's') |
5485 { | 5486 { |
5486 if (curr_val.is_string ()) | 5487 if (m_curr_val.is_string ()) |
5487 { | 5488 { |
5488 dim_vector dv (1, curr_val.numel ()); | 5489 dim_vector dv (1, m_curr_val.numel ()); |
5489 octave_value tmp = curr_val.reshape (dv); | 5490 octave_value tmp = m_curr_val.reshape (dv); |
5490 | 5491 |
5491 std::string sval = tmp.string_value (); | 5492 std::string sval = tmp.string_value (); |
5492 | 5493 |
5493 retval = sval.substr (elt_idx); | 5494 retval = sval.substr (m_elt_idx); |
5494 | 5495 |
5495 // We've consumed the rest of the value. | 5496 // We've consumed the rest of the value. |
5496 elt_idx = n_elts; | 5497 m_elt_idx = m_n_elts; |
5497 } | 5498 } |
5498 else | 5499 else |
5499 { | 5500 { |
5500 // Convert to character string while values are | 5501 // Convert to character string while values are |
5501 // integers in the range [0 : char max] | 5502 // integers in the range [0 : char max] |
5502 const NDArray val = curr_val.array_value (); | 5503 const NDArray val = m_curr_val.array_value (); |
5503 | 5504 |
5504 octave_idx_type idx = elt_idx; | 5505 octave_idx_type idx = m_elt_idx; |
5505 | 5506 |
5506 for (; idx < n_elts; idx++) | 5507 for (; idx < m_n_elts; idx++) |
5507 { | 5508 { |
5508 double dval = val(idx); | 5509 double dval = val(idx); |
5509 | 5510 |
5510 if (math::x_nint (dval) != dval || dval < 0 || dval > 255) | 5511 if (math::x_nint (dval) != dval || dval < 0 || dval > 255) |
5511 break; | 5512 break; |
5512 } | 5513 } |
5513 | 5514 |
5514 octave_idx_type n = idx - elt_idx; | 5515 octave_idx_type n = idx - m_elt_idx; |
5515 | 5516 |
5516 if (n > 0) | 5517 if (n > 0) |
5517 { | 5518 { |
5518 std::string sval (n, '\0'); | 5519 std::string sval (n, '\0'); |
5519 | 5520 |
5520 for (octave_idx_type i = 0; i < n; i++) | 5521 for (octave_idx_type i = 0; i < n; i++) |
5521 sval[i] = val(elt_idx++); | 5522 sval[i] = val(m_elt_idx++); |
5522 | 5523 |
5523 retval = sval; | 5524 retval = sval; |
5524 } | 5525 } |
5525 else | 5526 else |
5526 retval = curr_val.fast_elem_extract (elt_idx++); | 5527 retval = m_curr_val.fast_elem_extract (m_elt_idx++); |
5527 } | 5528 } |
5528 } | 5529 } |
5529 else | 5530 else |
5530 { | 5531 { |
5531 retval = curr_val.fast_elem_extract (elt_idx++); | 5532 retval = m_curr_val.fast_elem_extract (m_elt_idx++); |
5532 | 5533 |
5533 if (type == 'c' && ! retval.is_string ()) | 5534 if (type == 'c' && ! retval.is_string ()) |
5534 { | 5535 { |
5535 double dval = retval.double_value (); | 5536 double dval = retval.double_value (); |
5536 | 5537 |
5537 if (math::x_nint (dval) == dval && dval >= 0 && dval < 256) | 5538 if (math::x_nint (dval) == dval && dval >= 0 && dval < 256) |
5538 retval = static_cast<char> (dval); | 5539 retval = static_cast<char> (dval); |
5539 } | 5540 } |
5540 } | 5541 } |
5541 | 5542 |
5542 if (elt_idx >= n_elts) | 5543 if (m_elt_idx >= m_n_elts) |
5543 { | 5544 { |
5544 elt_idx = 0; | 5545 m_elt_idx = 0; |
5545 val_idx++; | 5546 m_val_idx++; |
5546 have_data = false; | 5547 m_have_data = false; |
5547 } | 5548 } |
5548 | 5549 |
5549 break; | 5550 break; |
5550 } | 5551 } |
5551 else | 5552 else |
5552 { | 5553 { |
5553 val_idx++; | 5554 m_val_idx++; |
5554 have_data = false; | 5555 m_have_data = false; |
5555 | 5556 |
5556 if (n_elts == 0) | 5557 if (m_n_elts == 0) |
5557 { | 5558 { |
5558 if (elt_idx == 0) | 5559 if (m_elt_idx == 0) |
5559 { | 5560 { |
5560 if (type == 's' || type == 'c') | 5561 if (type == 's' || type == 'c') |
5561 retval = ""; | 5562 retval = ""; |
5562 else | 5563 else |
5563 retval = Matrix (); | 5564 retval = Matrix (); |
5564 | 5565 |
5565 break; | 5566 break; |
5566 } | 5567 } |
5567 | 5568 |
5568 if (exhausted ()) | 5569 if (exhausted ()) |
5569 curr_state = conversion_error; | 5570 m_curr_state = conversion_error; |
5570 } | 5571 } |
5571 } | 5572 } |
5572 } | 5573 } |
5573 | 5574 |
5574 return retval; | 5575 return retval; |
5582 double dval = val.double_value (true); | 5583 double dval = val.double_value (true); |
5583 | 5584 |
5584 if (dval < 0 || dval > std::numeric_limits<int>::max () | 5585 if (dval < 0 || dval > std::numeric_limits<int>::max () |
5585 || math::x_nint (dval) != dval) | 5586 || math::x_nint (dval) != dval) |
5586 { | 5587 { |
5587 curr_state = conversion_error; | 5588 m_curr_state = conversion_error; |
5588 return -1; | 5589 return -1; |
5589 } | 5590 } |
5590 | 5591 |
5591 return math::nint (dval); | 5592 return math::nint (dval); |
5592 } | 5593 } |