From b52156991ef92e8b168b1992748d0bfc36b47934 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Mar 2016 13:13:21 +0000 Subject: [PATCH] fixed: glm::operator<< (using a copy of #491) --- glm/gtx/io.inl | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 407214ee..c250f27f 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -30,9 +30,11 @@ /// @author Jan P Springer (regnirpsj@gmail.com) /////////////////////////////////////////////////////////////////////////////////////////////////// -#include // std::fixed, std::setfill<>, std::setprecision, std::right, std::setw +#include // std::fixed, std::setfill<>, std::setprecision, std::right, + // std::setw #include // std::basic_ostream<> #include "../gtc/matrix_access.hpp" // glm::col, glm::row +#include "../gtx/type_trait.hpp" // glm::type<> #if !defined(GLM_META_PROG_HELPERS) # pragma error("Please define 'GLM_META_PROG_HELPERS' before using GLM_GTX_io") @@ -201,6 +203,8 @@ namespace glm{ { io::format_punct const & fmt(io::get_facet >(os)); + length_t const& components(type::components); + if(fmt.formatted) { io::basic_state_saver const bss(os); @@ -211,20 +215,20 @@ namespace glm{ << std::setfill(fmt.space) << fmt.delim_left; - for (unsigned i(0); i < V::components; ++i) { + for (unsigned i(0); i < components; ++i) { os << std::setw(fmt.width) << a[i]; - if (V::components-1 != i) { os << fmt.separator; } + if (components-1 != i) { os << fmt.separator; } } os << fmt.delim_right; } else { - for (unsigned i(0); i < V::components; ++i) { + for (unsigned i(0); i < components; ++i) { os << a[i]; - if (V::components-1 != i) { os << fmt.space; } + if (components-1 != i) { os << fmt.space; } } } } @@ -276,6 +280,9 @@ namespace glm{ { io::format_punct const & fmt(io::get_facet >(os)); + length_t const& cols(type::cols); + length_t const& rows(type::rows); + if(fmt.formatted) { os << fmt.newline << fmt.delim_left; @@ -283,24 +290,24 @@ namespace glm{ switch (fmt.order) { case io::column_major: { - for (unsigned i(0); i < M::rows; ++i) { + for (unsigned i(0); i < rows; ++i) { if (0 != i) { os << fmt.space; } os << row(a, i); - if (M::rows-1 != i) { os << fmt.newline; } + if (rows-1 != i) { os << fmt.newline; } } } break; case io::row_major: { - for (unsigned i(0); i < M::cols; ++i) { + for (unsigned i(0); i < cols; ++i) { if (0 != i) { os << fmt.space; } os << column(a, i); - if (M::cols-1 != i) { os << fmt.newline; } + if (cols-1 != i) { os << fmt.newline; } } } break; @@ -311,20 +318,20 @@ namespace glm{ switch (fmt.order) { case io::column_major: { - for (unsigned i(0); i < M::cols; ++i) { + for (unsigned i(0); i < cols; ++i) { os << column(a, i); - if (M::cols-1 != i) { os << fmt.space; } + if (cols-1 != i) { os << fmt.space; } } } break; case io::row_major: { - for (unsigned i(0); i < M::rows; ++i) { + for (unsigned i(0); i < rows; ++i) { os << row(a, i); - if (M::rows-1 != i) { os << fmt.space; } + if (rows-1 != i) { os << fmt.space; } } } break; @@ -401,9 +408,11 @@ namespace glm{ if(cerberus) { - io::format_punct const & fmt(io::get_facet >(os)); - M const& ml(a.first); - M const& mr(a.second); + io::format_punct const& fmt(io::get_facet >(os)); + M const& ml(a.first); + M const& mr(a.second); + length_t const& cols(type::cols); + length_t const& rows(type::rows); if(fmt.formatted) { os << fmt.newline @@ -412,32 +421,32 @@ namespace glm{ switch (fmt.order) { case io::column_major: { - for (unsigned i(0); i < M::rows; ++i) { + for (unsigned i(0); i < rows; ++i) { if (0 != i) { os << fmt.space; } os << row(ml, i) - << ((M::rows-1 != i) ? fmt.space : fmt.delim_right) + << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, i); - if (M::rows-1 != i) { os << fmt.newline; } + if (rows-1 != i) { os << fmt.newline; } } } break; case io::row_major: { - for (unsigned i(0); i < M::cols; ++i) { + for (unsigned i(0); i < cols; ++i) { if (0 != i) { os << fmt.space; } os << column(ml, i) - << ((M::cols-1 != i) ? fmt.space : fmt.delim_right) + << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, i); - if (M::cols-1 != i) { os << fmt.newline; } + if (cols-1 != i) { os << fmt.newline; } } } break;