From e5901113750895dcf67d8075f484fbfbac349b1d Mon Sep 17 00:00:00 2001 From: jan p springer Date: Fri, 1 May 2015 13:42:56 +0100 Subject: [PATCH 1/6] added: 'operator<<(std::pair, tmat4x4>)' routed to 'operator<<(std::pair const, tmat4x4 const>)' to avoid specifier removal by 'std::make_pair<>' and follow-up type-deduction problems; see [http://stackoverflow.com/questions/29985791/] --- glm/gtx/io.hpp | 8 +++++++- glm/gtx/io.inl | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index b3842bbd..d112805d 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -214,12 +214,18 @@ namespace glm template GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x4 const&); - template + template GLM_FUNC_DECL std::basic_ostream & operator<<( std::basic_ostream &, std::pair const, tmat4x4 const> const &); + template + GLM_FUNC_DECL std::basic_ostream & operator<<( + std::basic_ostream &, + std::pair, + tmat4x4> const &); + /// @} }//namespace glm diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 5af266dd..9355b919 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -605,7 +605,7 @@ namespace io return os; } - + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<( std::basic_ostream & os, @@ -645,4 +645,13 @@ namespace io return os; } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<( + std::basic_ostream & os, + std::pair, tmat4x4> const& a) + { + return operator<<(os, static_cast const, tmat4x4 const> const&>(a)); + } + }//namespace glm From 264f19257785d9d16fcf86f49dc3f12aa79ecd27 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Thu, 29 Oct 2015 14:42:10 +0000 Subject: [PATCH 2/6] added: pattern for local build directories --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f4aa2549..ec55f089 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,7 @@ Makefile # Misc. *.log + +# local build(s) +build* + From 2547d1424084f36efe77e969235b5cbf0e7dfe01 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Thu, 29 Oct 2015 17:56:08 +0000 Subject: [PATCH 3/6] fixed: ostream operators --- glm/gtx/io.hpp | 18 +- glm/gtx/io.inl | 858 +++++++++++++++++--------------------------- test/gtx/gtx_io.cpp | 24 +- 3 files changed, 347 insertions(+), 553 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 95b4d24e..68ec9208 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -30,6 +30,7 @@ /// @author Jan P Springer (regnirpsj@gmail.com) /// /// @see core (dependence) +/// @see gtc_matrix_access (dependence) /// @see gtc_quaternion (dependence) /// /// @defgroup gtx_io GLM_GTX_io @@ -41,7 +42,10 @@ /// based on howard hinnant's std::chrono io proposal /// [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html] /// -/// needs to be included to use these functionalities. +/// needs to be included to use these functionalities. +/// +/// GLM_META_PROG_HELPERS must be defined before including this and any other +/// glm header file. /////////////////////////////////////////////////////////////////////////////////// #pragma once @@ -215,16 +219,8 @@ namespace glm GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x4 const&); template - GLM_FUNC_DECL std::basic_ostream & operator<<( - std::basic_ostream &, - std::pair const, - tmat4x4 const> const &); - - template - GLM_FUNC_DECL std::basic_ostream & operator<<( - std::basic_ostream &, - std::pair, - tmat4x4 > const &); + GLM_FUNC_DECL std::basic_ostream & operator<<(std::basic_ostream &, + std::pair const, tmat4x4 const> const &); /// @} }//namespace glm diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index f447faa0..407214ee 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -30,627 +30,433 @@ /// @author Jan P Springer (regnirpsj@gmail.com) /////////////////////////////////////////////////////////////////////////////////////////////////// -#include // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw -#include // std::basic_ostream<> +#include // std::fixed, std::setfill<>, std::setprecision, std::right, std::setw +#include // std::basic_ostream<> +#include "../gtc/matrix_access.hpp" // glm::col, glm::row + +#if !defined(GLM_META_PROG_HELPERS) +# pragma error("Please define 'GLM_META_PROG_HELPERS' before using GLM_GTX_io") +#endif namespace glm{ -namespace io -{ - template - /* explicit */ GLM_FUNC_QUALIFIER - format_punct::format_punct(size_t a) - : std::locale::facet(a), - formatted (true), - precision (3), - width (1 + 4 + 1 + precision), - separator (','), - delim_left ('['), - delim_right (']'), - space (' '), - newline ('\n'), - order (row_major) - {} + namespace io + { + template + /* explicit */ GLM_FUNC_QUALIFIER + format_punct::format_punct(size_t a) + : std::locale::facet(a), + formatted (true), + precision (3), + width (1 + 4 + 1 + precision), + separator (','), + delim_left ('['), + delim_right (']'), + space (' '), + newline ('\n'), + order (column_major) + {} - template - /* explicit */ GLM_FUNC_QUALIFIER - format_punct::format_punct(format_punct const& a) - : std::locale::facet(0), - formatted (a.formatted), - precision (a.precision), - width (a.width), - separator (a.separator), - delim_left (a.delim_left), - delim_right (a.delim_right), - space (a.space), - newline (a.newline), - order (a.order) - {} + template + /* explicit */ GLM_FUNC_QUALIFIER + format_punct::format_punct(format_punct const& a) + : std::locale::facet(0), + formatted (a.formatted), + precision (a.precision), + width (a.width), + separator (a.separator), + delim_left (a.delim_left), + delim_right (a.delim_right), + space (a.space), + newline (a.newline), + order (a.order) + {} - template std::locale::id format_punct::id; + template std::locale::id format_punct::id; - template - /* explicit */ GLM_FUNC_QUALIFIER basic_state_saver::basic_state_saver(std::basic_ios& a) - : state_ (a), - flags_ (a.flags()), - precision_(a.precision()), - width_ (a.width()), - fill_ (a.fill()), - locale_ (a.getloc()) - {} + template + /* explicit */ GLM_FUNC_QUALIFIER basic_state_saver::basic_state_saver(std::basic_ios& a) + : state_ (a), + flags_ (a.flags()), + precision_(a.precision()), + width_ (a.width()), + fill_ (a.fill()), + locale_ (a.getloc()) + {} - template - GLM_FUNC_QUALIFIER basic_state_saver::~basic_state_saver() - { - state_.imbue(locale_); - state_.fill(fill_); - state_.width(width_); - state_.precision(precision_); - state_.flags(flags_); - } + template + GLM_FUNC_QUALIFIER basic_state_saver::~basic_state_saver() + { + state_.imbue(locale_); + state_.fill(fill_); + state_.width(width_); + state_.precision(precision_); + state_.flags(flags_); + } - template - /* explicit */ GLM_FUNC_QUALIFIER basic_format_saver::basic_format_saver(std::basic_ios& a) - : bss_(a) - { - a.imbue(std::locale(a.getloc(), new format_punct(get_facet >(a)))); - } + template + /* explicit */ GLM_FUNC_QUALIFIER basic_format_saver::basic_format_saver(std::basic_ios& a) + : bss_(a) + { + a.imbue(std::locale(a.getloc(), new format_punct(get_facet >(a)))); + } - template - GLM_FUNC_QUALIFIER - basic_format_saver::~basic_format_saver() - {} + template + GLM_FUNC_QUALIFIER + basic_format_saver::~basic_format_saver() + {} - /* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a) - : value(a) - {} + /* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a) + : value(a) + {} - /* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a) - : value(a) - {} + /* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a) + : value(a) + {} - template - /* explicit */ GLM_FUNC_QUALIFIER delimeter::delimeter(CTy a, CTy b, CTy c) - : value() - { - value[0] = a; - value[1] = b; - value[2] = c; - } + template + /* explicit */ GLM_FUNC_QUALIFIER delimeter::delimeter(CTy a, CTy b, CTy c) + : value() + { + value[0] = a; + value[1] = b; + value[2] = c; + } - /* explicit */ GLM_FUNC_QUALIFIER - order::order(order_type a) - : value(a) - {} + /* explicit */ GLM_FUNC_QUALIFIER order::order(order_type a) + : value(a) + {} - template - GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios& ios) - { - if (!std::has_facet(ios.getloc())) { - ios.imbue(std::locale(ios.getloc(), new FTy)); - } + template + GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios& ios) + { + if (!std::has_facet(ios.getloc())) { + ios.imbue(std::locale(ios.getloc(), new FTy)); + } - return std::use_facet(ios.getloc()); - } + return std::use_facet(ios.getloc()); + } - template - GLM_FUNC_QUALIFIER std::basic_ios& formatted(std::basic_ios& ios) - { - const_cast&>(get_facet >(ios)).formatted = true; + template + GLM_FUNC_QUALIFIER std::basic_ios& formatted(std::basic_ios& ios) + { + const_cast&>(get_facet >(ios)).formatted = true; - return ios; - } + return ios; + } - template - GLM_FUNC_QUALIFIER std::basic_ios& unformatted(std::basic_ios& ios) - { - const_cast&>(get_facet >(ios)).formatted = false; + template + GLM_FUNC_QUALIFIER std::basic_ios& unformatted(std::basic_ios& ios) + { + const_cast&>(get_facet >(ios)).formatted = false; - return ios; - } + return ios; + } - template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, precision const& a) - { - const_cast&>(get_facet >(os)).precision = a.value; + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, precision const& a) + { + const_cast&>(get_facet >(os)).precision = a.value; - return os; - } + return os; + } - template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, width const& a) - { - const_cast&>(get_facet >(os)).width = a.value; + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, width const& a) + { + const_cast&>(get_facet >(os)).width = a.value; - return os; - } + return os; + } - template - std::basic_ostream& operator<<(std::basic_ostream& os, delimeter const& a) - { - format_punct & fmt(const_cast&>(get_facet >(os))); + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, delimeter const& a) + { + format_punct & fmt(const_cast&>(get_facet >(os))); - fmt.delim_left = a.value[0]; - fmt.delim_right = a.value[1]; - fmt.separator = a.value[2]; + fmt.delim_left = a.value[0]; + fmt.delim_right = a.value[1]; + fmt.separator = a.value[2]; - return os; - } + return os; + } - template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, order const& a) - { - const_cast&>(get_facet >(os)).order = a.value; + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, order const& a) + { + const_cast&>(get_facet >(os)).order = a.value; - return os; - } -} // namespace io + return os; + } + } // namespace io + + namespace detail { + + template class V, typename T, precision P> + GLM_FUNC_QUALIFIER std::basic_ostream& + print_vector_on(std::basic_ostream& os, V const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) + { + io::basic_state_saver const bss(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left; + + for (unsigned i(0); i < V::components; ++i) { + os << std::setw(fmt.width) << a[i]; + + if (V::components-1 != i) { os << fmt.separator; } + } + + os << fmt.delim_right; + } + else + { + for (unsigned i(0); i < V::components; ++i) { + os << a[i]; + + if (V::components-1 != i) { os << fmt.space; } + } + } + } + + return os; + } + + } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tquat const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - - if(fmt.formatted) - { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.w << fmt.separator - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z - << fmt.delim_right; - } - else - { - os << a.w << fmt.space << a.x << fmt.space << a.y << fmt.space << a.z; - } - } - - return os; + return detail::print_vector_on(os, a); } template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec1 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - - if(fmt.formatted) - { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x - << fmt.delim_right; - } - else - { - os << a.x; - } - } - - return os; - } + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec1 const& a) + { + return detail::print_vector_on(os, a); + } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec2 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - - if(fmt.formatted) - { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y - << fmt.delim_right; - } - else - { - os << a.x << fmt.space << a.y; - } - } - - return os; + return detail::print_vector_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec3 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - - if(fmt.formatted) - { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z - << fmt.delim_right; - } - else - { - os << a.x << fmt.space << a.y << fmt.space << a.z; - } - } - - return os; + return detail::print_vector_on(os, a); } - + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec4 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - - if(fmt.formatted) - { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z << fmt.separator - << std::setw(fmt.width) << a.w - << fmt.delim_right; - } - else - { - os << a.x << fmt.space << a.y << fmt.space << a.z << fmt.space << a.w; - } - } - - return os; + return detail::print_vector_on(os, a); } + namespace detail { + + template class M, typename T, precision P> + GLM_FUNC_QUALIFIER std::basic_ostream& + print_matrix_on(std::basic_ostream& os, M const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) { + os << fmt.newline + << fmt.delim_left; + + switch (fmt.order) { + case io::column_major: + { + for (unsigned i(0); i < M::rows; ++i) { + if (0 != i) { os << fmt.space; } + + os << row(a, i); + + if (M::rows-1 != i) { os << fmt.newline; } + } + } + break; + + case io::row_major: + { + for (unsigned i(0); i < M::cols; ++i) { + if (0 != i) { os << fmt.space; } + + os << column(a, i); + + if (M::cols-1 != i) { os << fmt.newline; } + } + } + break; + } + + os << fmt.delim_right; + } else { + switch (fmt.order) { + case io::column_major: + { + for (unsigned i(0); i < M::cols; ++i) { + os << column(a, i); + + if (M::cols-1 != i) { os << fmt.space; } + } + } + break; + + case io::row_major: + { + for (unsigned i(0); i < M::rows; ++i) { + os << row(a, i); + + if (M::rows-1 != i) { os << fmt.space; } + } + } + break; + } + } + } + + return os; + } + + } + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x2 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat2x2 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x3 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat3x2 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x4 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat4x2 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat3x2 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat2x3 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat3x3 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat3x3 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat3x4 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat4x3 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if (fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x2 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat2x4 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if (fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x3 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat3x4 m(a); - - if(io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; + return detail::print_matrix_on(os, a); } template GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x4 const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat4x4 m(a); - - if (io::row_major == fmt.order) - m = transpose(a); - - if(fmt.formatted) - { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } - else - { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; + return detail::print_matrix_on(os, a); } + + namespace detail { + + template class M, typename T, precision P> + GLM_FUNC_QUALIFIER std::basic_ostream& + print_matrix_pair_on(std::basic_ostream& os, std::pair const, M const> const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + M const& ml(a.first); + M const& mr(a.second); + + if(fmt.formatted) { + os << fmt.newline + << fmt.delim_left; + + switch (fmt.order) { + case io::column_major: + { + for (unsigned i(0); i < M::rows; ++i) { + if (0 != i) { os << fmt.space; } + + os << row(ml, i) + << ((M::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; } + } + } + break; + + case io::row_major: + { + for (unsigned i(0); i < M::cols; ++i) { + if (0 != i) { os << fmt.space; } + + os << column(ml, i) + << ((M::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; } + } + } + break; + } + + os << fmt.delim_right; + } else { + os << ml << fmt.space << mr; + } + } + + return os; + } + } template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<( - std::basic_ostream & os, - std::pair const, tmat4x4 const> const& a) + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream & os, + std::pair const, tmat4x4 const> const& a) { - typename std::basic_ostream::sentry const cerberus(os); - - if(cerberus) - { - io::format_punct const & fmt(io::get_facet >(os)); - tmat4x4 ml(a.first); - tmat4x4 mr(a.second); - - if(io::row_major == fmt.order) - { - ml = transpose(a.first); - mr = transpose(a.second); - } - - if(fmt.formatted) - { - CTy const & l(fmt.delim_left); - CTy const & r(fmt.delim_right); - CTy const & s(fmt.space); - - os << fmt.newline - << l << ml[0] << s << s << l << mr[0] << fmt.newline - << s << ml[1] << s << s << s << mr[1] << fmt.newline - << s << ml[2] << s << s << s << mr[2] << fmt.newline - << s << ml[3] << r << s << s << mr[3] << r; - } - else - { - os << ml << fmt.space << mr; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& operator<<( - std::basic_ostream & os, - std::pair, tmat4x4 > const& a) - { - return operator<<(os, static_cast const, tmat4x4 const> const&>(a)); + return detail::print_matrix_pair_on(os, a); } }//namespace glm diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index d70089f1..17e354cf 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -29,6 +29,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#define GLM_META_PROG_HELPERS #include #include #include @@ -128,7 +129,7 @@ int test_io_vec(OS& os) } template -int test_io_mat(OS& os) +int test_io_mat(OS& os, glm::io::order_type otype) { os << '\n' << typeid(OS).name() << '\n'; @@ -145,21 +146,10 @@ int test_io_mat(OS& os) glm::tvec4 const v4_3(28, 29, 30, 31); glm::tvec4 const v4_4(32, 33, 34, 35); -#if 0 - os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x2(v2_1, v2_2) << '\n' - << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x3(v3_1, v3_2) << '\n' - << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x4(v4_1, v4_2) << '\n' - << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::tmat3x2(v2_1, v2_2, v2_3) << '\n' - << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::tmat3x3(v3_1, v3_2, v3_3) << '\n' - << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat3x4(v4_1, v4_2, v4_3) << '\n' - << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::tmat4x2(v2_1, v2_2, v2_3, v2_4) << '\n' - << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' - << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; -#endif - glm::io::basic_format_saver const iofs(os); os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << glm::io::order(otype) << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x2(v2_1, v2_2) << '\n' << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x3(v3_1, v3_2) << '\n' << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x4(v4_1, v4_2) << '\n' @@ -171,7 +161,7 @@ int test_io_mat(OS& os) << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; os << glm::io::unformatted - << glm::io::order(glm::io::column_major) + << glm::io::order(otype) << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x2(v2_1, v2_2) << '\n' << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x3(v3_1, v3_2) << '\n' << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::tmat2x4(v4_1, v4_2) << '\n' @@ -203,8 +193,10 @@ int main() Error += test_io_vec(std::cout); Error += test_io_vec(std::wcout); - Error += test_io_mat(std::cout); - Error += test_io_mat(std::wcout); + Error += test_io_mat(std::cout, glm::io::column_major); + Error += test_io_mat(std::wcout, glm::io::column_major); + Error += test_io_mat(std::cout, glm::io::row_major); + Error += test_io_mat(std::wcout, glm::io::row_major); return Error; } From b52156991ef92e8b168b1992748d0bfc36b47934 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Mar 2016 13:13:21 +0000 Subject: [PATCH 4/6] 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; From a5a69566b93b6d8a71c747edf3fa157ad32b8246 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Mar 2016 16:36:34 +0000 Subject: [PATCH 5/6] update: date stamps --- glm/gtx/io.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 68ec9208..96632b2d 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////// /// OpenGL Mathematics (glm.g-truc.net) /// -/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/// Copyright (c) 2005 - 2016 G-Truc Creation (www.g-truc.net) /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights @@ -26,7 +26,7 @@ /// /// @ref gtx_io /// @file glm/gtx/io.hpp -/// @date 2013-11-22 / 2014-11-25 +/// @date 2013-11-22 / 2016-03-14 /// @author Jan P Springer (regnirpsj@gmail.com) /// /// @see core (dependence) @@ -43,9 +43,6 @@ /// [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html] /// /// needs to be included to use these functionalities. -/// -/// GLM_META_PROG_HELPERS must be defined before including this and any other -/// glm header file. /////////////////////////////////////////////////////////////////////////////////// #pragma once From 25d6c8e341d746df51b41554dc2e6fd7203b277e Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Mar 2016 16:37:30 +0000 Subject: [PATCH 6/6] update: date stamps + GLM_META_PROG_HELPERS pre-requiste --- glm/gtx/io.inl | 11 +++-------- test/gtx/gtx_io.cpp | 7 +++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index c250f27f..8eee0d9a 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////// /// OpenGL Mathematics (glm.g-truc.net) /// -/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/// Copyright (c) 2005 - 2016 G-Truc Creation (www.g-truc.net) /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights @@ -26,20 +26,15 @@ /// /// @ref gtx_io /// @file glm/gtx/io.inl -/// @date 2013-11-22 / 2014-11-25 +/// @date 2013-11-22 / 2016-03-14 /// @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") -#endif - namespace glm{ namespace io { diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index 17e354cf..c9edf9cf 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////// /// OpenGL Mathematics (glm.g-truc.net) /// -/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net) +/// Copyright (c) 2005 - 2016 G-Truc Creation (www.g-truc.net) /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights @@ -25,11 +25,10 @@ /// THE SOFTWARE. /// /// @file test/gtx/gtx_io.cpp -/// @date 2013-11-22 / 2014-11-25 -/// @author Christophe Riccio +/// @date 2013-11-22 / 2016-03-14 +/// @author Jan P Springer (regnirpsj@gmail.com) /////////////////////////////////////////////////////////////////////////////////// -#define GLM_META_PROG_HELPERS #include #include #include