[GIT] ppl/ppl(master): Fixed and uniformed iomanip uses.

Module: ppl/ppl Branch: master Commit: 9cdc037cdf468b82a6d14217c6c1caad531b0bbd URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=9cdc037cdf468...
Author: Abramo Bagnara abramo.bagnara@gmail.com Date: Sun Feb 26 20:14:48 2012 +0100
Fixed and uniformed iomanip uses.
---
src/Checked_Number.templates.hh | 13 +++++++------ src/Interval.templates.hh | 2 +- src/Interval_Info.inlines.hh | 18 +++++++++--------- src/Row_Flags.cc | 24 ++++++++++-------------- 4 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/src/Checked_Number.templates.hh b/src/Checked_Number.templates.hh index d756717..5c6c596 100644 --- a/src/Checked_Number.templates.hh +++ b/src/Checked_Number.templates.hh @@ -39,12 +39,11 @@ ascii_dump(std::ostream& s, const T& t) { else { // An inexact data type (probably floating point): // first dump its hexadecimal representation ... - const std::ios_base::fmtflags old_flags = s.flags(); - s << std::hex; + const std::ios::fmtflags old_flags = s.setf(std::ios::hex, + std::ios::basefield); const unsigned char* p = reinterpret_cast<const unsigned char*>(&t); for (unsigned i = 0; i < sizeof(T); ++i) { - s << std::setw(2) << std::setfill('0'); - s << static_cast<unsigned>(p[i]); + s << std::setw(2) << std::setfill('0') << static_cast<unsigned>(p[i]); } s.flags(old_flags); // ... and then pretty print it for readability. @@ -55,9 +54,11 @@ ascii_dump(std::ostream& s, const T& t) { template <typename T> typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type ascii_load(std::istream& s, T& t) { - if (std::numeric_limits<T>::is_exact) + if (std::numeric_limits<T>::is_exact) { // An exact data type: input from pretty printed version is accurate. - return s >> t; + s >> t; + return !s.fail(); + } else { // An inexact data type (probably floating point): // first load its hexadecimal representation ... diff --git a/src/Interval.templates.hh b/src/Interval.templates.hh index 6e9dbc7..d785ac1 100644 --- a/src/Interval.templates.hh +++ b/src/Interval.templates.hh @@ -291,7 +291,7 @@ operator>>(std::istream& is, Interval<Boundary, Info>& x) { unexpected: is.unget(); fail: - is.setstate(std::ios_base::failbit); + is.setstate(std::ios::failbit); return is; }
diff --git a/src/Interval_Info.inlines.hh b/src/Interval_Info.inlines.hh index da03cc8..4453019 100644 --- a/src/Interval_Info.inlines.hh +++ b/src/Interval_Info.inlines.hh @@ -77,20 +77,20 @@ Interval_Info_Bitset<T, Policy>::m_swap(Interval_Info_Bitset<T, Policy>& y) { template <typename T, typename Policy> inline void Interval_Info_Bitset<T, Policy>::ascii_dump(std::ostream& s) const { - std::ios_base::fmtflags old = s.flags(); - s << std::hex << bitset; - s.flags(old); + const std::ios::fmtflags old_flags = s.setf(std::ios::hex, + std::ios::basefield); + s << bitset; + s.flags(old_flags); }
template <typename T, typename Policy> inline bool Interval_Info_Bitset<T, Policy>::ascii_load(std::istream& s) { - std::ios_base::fmtflags old = s.flags(); - s >> std::hex >> bitset; - if (!s) - return false; - s.flags(old); - return true; + const std::ios::fmtflags old_flags = s.setf(std::ios::hex, + std::ios::basefield); + s >> bitset; + s.flags(old_flags); + return !s.fail(); }
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS diff --git a/src/Row_Flags.cc b/src/Row_Flags.cc index 39a3c8c..60063a4 100644 --- a/src/Row_Flags.cc +++ b/src/Row_Flags.cc @@ -31,15 +31,12 @@ namespace PPL = Parma_Polyhedra_Library; void PPL::Row_Flags::ascii_dump(std::ostream& s) const { s << "0x"; - std::istream::fmtflags f = s.setf(std::istream::hex); + std::ios::fmtflags old_flags = s.setf(std::ios::hex, + std::ios::basefield); const std::streamsize new_sz = static_caststd::streamsize(2 * sizeof(Row_Flags::base_type)); - const std::streamsize old_sz = s.width(new_sz); - std::ostream::char_type ch = s.fill('0'); - s << bits; - s.fill(ch); - s.width(old_sz); - s.flags(f); + s << std::setw(new_sz) << setfill('0') << bits; + s.flags(old_flags); }
PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(Row_Flags) @@ -47,12 +44,11 @@ PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(Row_Flags) bool PPL::Row_Flags::ascii_load(std::istream& s) { std::string str; - std::streamsize sz = s.width(2); - if (!(s >> str) || str != "0x") + if (!(s >> std::setw(2) >> str) || str != "0x") return false; - s.width(sz); - std::istream::fmtflags f = s.setf(std::istream::hex); - bool r = s >> bits; - s.flags(f); - return r; + const std::ios::fmtflags old_flags = s.setf(std::ios::hex, + std::ios::basefield); + s >> bits; + s.flags(old_flags); + return !s.fail(); }
participants (1)
-
Abramo Bagnara