[GIT] ppl/ppl(pip): For readability, separate the input operation from input stream status check.

Module: ppl/ppl Branch: pip Commit: 29201d2a5893bbe17744777de36e9a106ed8ea95 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=29201d2a5893b...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Thu Feb 10 18:48:11 2011 +0100
For readability, separate the input operation from input stream status check.
---
demos/ppl_pips/ppl_pips.cc | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/demos/ppl_pips/ppl_pips.cc b/demos/ppl_pips/ppl_pips.cc index faec685..51cdbac 100644 --- a/demos/ppl_pips/ppl_pips.cc +++ b/demos/ppl_pips/ppl_pips.cc @@ -437,19 +437,25 @@ protected: if (!expect(in, '[')) return false; std::string s; - if (getline(in, s, ']').bad()) + getline(in, s, ']'); + if (in.fail()) return false; std::istringstream iss(s); PPL::dimension_type start_index = row_index * row_size; PPL::dimension_type k = start_index; - for (PPL::dimension_type i = 0; i < cst_col; ++i) - if (!(iss >> tab[k++])) + for (PPL::dimension_type i = 0; i < cst_col; ++i, ++k) { + iss >> tab[k]; + if (iss.fail()) return false; - if (!(iss >> tab[start_index + row_size - 1])) + } + iss >> tab[start_index + row_size - 1]; + if (iss.fail()) return false; - for (PPL::dimension_type i = cst_col + 1; i < row_size; ++i) - if (!(iss >> tab[k++])) + for (PPL::dimension_type i = cst_col + 1; i < row_size; ++i, ++k) { + iss >> tab[k]; + if (iss.fail()) return false; + } return true; }
participants (1)
-
Enea Zaffanella