Index: boost/numeric/ublas/io.hpp =================================================================== --- boost/numeric/ublas/io.hpp (revision 58644) +++ boost/numeric/ublas/io.hpp (working copy) @@ -1,6 +1,6 @@ // -// Copyright (c) 2000-2002 -// Joerg Walter, Mathias Koch +// Copyright (c) 2000-2010 +// Joerg Walter, Mathias Koch, Michael Baars // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -13,103 +13,144 @@ #ifndef _BOOST_UBLAS_IO_ #define _BOOST_UBLAS_IO_ -// Only forward definition required to define stream operations #include #include #include +namespace boost +{ + namespace numeric + { + namespace ublas + { -namespace boost { namespace numeric { namespace ublas { + template + std::basic_ostream &operator << + (std::basic_ostream &os, const vector_expression &v) + { + typedef typename VE::size_type size_type; - template - // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. - std::basic_ostream &operator << (std::basic_ostream &os, - const vector_expression &v) { - typedef typename VE::size_type size_type; - size_type size = v ().size (); - std::basic_ostringstream > s; - s.flags (os.flags ()); - s.imbue (os.getloc ()); - s.precision (os.precision ()); - s << '[' << size << "]("; - if (size > 0) - s << v () (0); - for (size_type i = 1; i < size; ++ i) - s << ',' << v () (i); - s << ')'; - return os << s.str ().c_str (); - } + size_type size = v().size(); + + std::basic_ostringstream< E, T, std::allocator > s; - template - // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. - std::basic_istream &operator >> (std::basic_istream &is, - vector &v) { - typedef typename vector::size_type size_type; - E ch; + s.flags (os.flags()); + s.imbue (os.getloc()); + s.precision (os.precision()); + + s << '[' << size << "]("; + + if (size > 0) + { + s << v()(0); + } + + for (size_type i = 1; i < size; ++ i) + { + s << ',' << v()(i); + s << ')'; + } + + return os << s.str ().c_str (); + } + + template + std::basic_istream &operator >> + (std::basic_istream &is, vector &v) + { + typedef typename vector::size_type size_type; + + E ch; size_type size; - if (is >> ch && ch != '[') { - is.putback (ch); - is.setstate (std::ios_base::failbit); - } else if (is >> size >> ch && ch != ']') { - is.putback (ch); - is.setstate (std::ios_base::failbit); - } else if (! is.fail ()) { - vector s (size); - if (is >> ch && ch != '(') { + + if (is >> ch && ch != '[') + { + is.putback (ch); + is.setstate (std::ios_base::failbit); + } + else if (is >> size >> ch && ch != ']') + { + is.putback (ch); + is.setstate (std::ios_base::failbit); + } + else if (! is.fail ()) + { + vector s (size); + + if (is >> ch && ch != '(') + { + is.putback (ch); + is.setstate (std::ios_base::failbit); + } + else if (! is.fail ()) + { + for (size_type i = 0; i < size; i ++) + { + if (is >> s (i) >> ch && ch != ',') + { is.putback (ch); - is.setstate (std::ios_base::failbit); - } else if (! is.fail ()) { - for (size_type i = 0; i < size; i ++) { - if (is >> s (i) >> ch && ch != ',') { - is.putback (ch); - if (i < size - 1) - is.setstate (std::ios_base::failbit); - break; - } - } - if (is >> ch && ch != ')') { - is.putback (ch); - is.setstate (std::ios_base::failbit); - } + if (i < size - 1) is.setstate (std::ios_base::failbit); + break; + } } - if (! is.fail ()) - v.swap (s); + if (is >> ch && ch != ')') + { + is.putback (ch); + is.setstate (std::ios_base::failbit); + } + } + if (! is.fail()) v.swap (s); } + return is; - } + } - template - // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. - std::basic_ostream &operator << (std::basic_ostream &os, - const matrix_expression &m) { - typedef typename ME::size_type size_type; + template + std::basic_ostream &operator << + (std::basic_ostream &os, const matrix_expression &m) + { + typedef typename ME::size_type size_type; + size_type size1 = m ().size1 (); size_type size2 = m ().size2 (); + std::basic_ostringstream > s; s.flags (os.flags ()); s.imbue (os.getloc ()); s.precision (os.precision ()); - s << '[' << size1 << ',' << size2 << "]("; - if (size1 > 0) { - s << '(' ; - if (size2 > 0) - s << m () (0, 0); - for (size_type j = 1; j < size2; ++ j) - s << ',' << m () (0, j); - s << ')'; - } - for (size_type i = 1; i < size1; ++ i) { - s << ",(" ; - if (size2 > 0) - s << m () (i, 0); - for (size_type j = 1; j < size2; ++ j) - s << ',' << m () (i, j); - s << ')'; - } - s << ')'; - return os << s.str ().c_str (); - } + s << '[' << size1 << ',' << size2 << "]("; + + if (size1 > 0) + { + s << '(' ; + if (size2 > 0) s << m()(0, 0); + for (size_type j = 1; j < size2; ++ j) + { + s << ',' << m () (0, j); + } + s << ')'; + } + + for (size_type i = 1; i < size1; ++ i) + { + s << ",(" ; + if (size2 > 0) s << m () (i, 0); + for (size_type j = 1; j < size2; ++ j) + { + s << ',' << m () (i, j); + } + s << ')'; + } + + s << ')'; + + return os << s.str ().c_str (); + } + + // end of temporary modifications + + template // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. std::basic_istream &operator >> (std::basic_istream &is,