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

Enea Zaffanella zaffanella at cs.unipr.it
Thu Feb 10 19:22:45 CET 2011


Module: ppl/ppl
Branch: pip
Commit: 29201d2a5893bbe17744777de36e9a106ed8ea95
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=29201d2a5893bbe17744777de36e9a106ed8ea95

Author: Enea Zaffanella <zaffanella at 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;
   }
 




More information about the PPL-devel mailing list