From 623cdaa55274168f96ee5413aa039f3b935080c6 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Tue, 17 Dec 2013 22:37:34 +0000 Subject: [PATCH 1/7] reimplemented io support for basic types --- glm/gtx/io.hpp | 118 +++++++---- glm/gtx/io.inl | 468 ++++++++++++++++++++++++++++---------------- test/gtx/gtx_io.cpp | 52 +++-- 3 files changed, 429 insertions(+), 209 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index d3bcb3db..71ae187d 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -33,6 +33,10 @@ /// /// @brief std::[w]ostream support for glm types /// +/// std::[w]ostream support for glm types + precision/width/etc. manipulators +/// 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. /////////////////////////////////////////////////////////////////////////////////// @@ -47,8 +51,11 @@ # pragma message("GLM: GLM_GTX_io extension included") #endif -#include // std::basic_ostream<> (fwd) -#include // std::pair<> +#include // basic_ios_all_saver<> (fwd) +#include // boost::noncopyable +#include // std::basic_ostream<> (fwd) +#include // std::locale, std::locale::facet, std::locale::id +#include // std::pair<> namespace glm { @@ -58,60 +65,103 @@ namespace glm namespace io { - class precision_guard { + enum class order_type { column_major, row_major, }; + + template + class format_punct : public std::locale::facet { - public: + typedef CTy char_type; - GLM_FUNC_DECL explicit precision_guard(); - GLM_FUNC_DECL ~precision_guard(); - - private: + public: - unsigned precision_; - unsigned value_width_; + static std::locale::id id; + + bool formatted; + unsigned precision; + unsigned width; + char_type separator; + char_type delim_left; + char_type delim_right; + char_type space; + char_type newline; + order_type order; + + explicit format_punct(size_t a = 0); + explicit format_punct(format_punct const&); }; - enum class order_t { column_major, row_major, }; - - class format_guard { + template > + class basic_format_saver : private boost::noncopyable { public: - GLM_FUNC_DECL explicit format_guard(); - GLM_FUNC_DECL ~format_guard(); - + explicit basic_format_saver(std::basic_ios&); + ~basic_format_saver(); + private: - order_t order_; - char cr_; + boost::io::basic_ios_all_saver const ias_; }; - // decimal places (dflt: 3) - GLM_FUNC_DECL unsigned& precision(); + typedef basic_format_saver format_saver; + typedef basic_format_saver wformat_saver; + + struct formatted { /* empty */ }; + struct unformatted { /* empty */ }; + + struct precision { - // sign + value + '.' + decimals (dflt: 1 + 4 + 1 + precision()) - GLM_FUNC_DECL unsigned& value_width(); + unsigned value; + + explicit precision(unsigned); + + }; - // matrix output order (dflt: row_major) - GLM_FUNC_DECL order_t& order(); + struct width { - // carriage/return char (dflt: '\n') - GLM_FUNC_DECL char& cr(); + unsigned value; + + explicit width(unsigned); + + }; - // matrix output order -> column_major - GLM_FUNC_DECL std::ios_base& column_major(std::ios_base&); + template + struct delimeter { - // matrix output order -> row_major - GLM_FUNC_DECL std::ios_base& row_major (std::ios_base&); + CTy value[3]; + + explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); + + }; - // carriage/return char -> '\n' - GLM_FUNC_DECL std::ios_base& formatted (std::ios_base&); + struct order { - // carriage/return char -> ' ' - GLM_FUNC_DECL std::ios_base& unformatted (std::ios_base&); + order_type value; + + explicit order(order_type); + + }; + + // functions, inlined (inline) + template + FTy const& get_facet(std::basic_ios&); + + template + std::basic_ostream& operator<<(std::basic_ostream&, formatted const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, unformatted const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, precision const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, width const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, delimeter const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, order const&); + }//namespace io namespace detail diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index e588c480..c102f10a 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -2,12 +2,12 @@ // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2013-11-22 -// Updated : 2013-11-22 +// Updated : 2013-12-17 // Licence : This source is under MIT License // File : glm/gtx/inl.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -// #include // boost::io::ios_all_saver +#include // boost::io::ios_all_saver #include // std::setfill<>, std::fixed, std::setprecision, std::right, // std::setw #include // std::basic_ostream<> @@ -17,91 +17,143 @@ namespace glm namespace io { + template /* explicit */ GLM_FUNC_QUALIFIER - precision_guard::precision_guard() - : precision_ (precision()), - value_width_(value_width()) + 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 (order_type::row_major) {} - GLM_FUNC_QUALIFIER - precision_guard::~precision_guard() + 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 + /* explicit */ GLM_FUNC_QUALIFIER + basic_format_saver::basic_format_saver(std::basic_ios& a) + : boost::noncopyable(), + ias_ (a) { - value_width() = value_width_; - precision() = precision_; + a.imbue(std::locale(a.getloc(), new format_punct(get_facet>(a)))); + } + + template + GLM_FUNC_QUALIFIER + basic_format_saver::~basic_format_saver() + {} + + /* explicit */ GLM_FUNC_QUALIFIER + precision::precision(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; } /* explicit */ GLM_FUNC_QUALIFIER - format_guard::format_guard() - : order_(order()), - cr_ (cr()) + order::order(order_type a) + : value(a) {} - - GLM_FUNC_QUALIFIER - format_guard::~format_guard() - { - cr() = cr_; - order() = order_; - } - - GLM_FUNC_QUALIFIER unsigned& - precision() - { - static unsigned p(3); - - return p; - } - GLM_FUNC_QUALIFIER unsigned& - value_width() + template + GLM_FUNC_QUALIFIER FTy const& + get_facet(std::basic_ios& ios) { - static unsigned p(9); + if (!std::has_facet(ios.getloc())) { + ios.imbue(std::locale(ios.getloc(), new FTy)); + } - return p; + return std::use_facet(ios.getloc()); } - - GLM_FUNC_QUALIFIER order_t& - order() - { - static order_t p(order_t::row_major); - return p; - } - - GLM_FUNC_QUALIFIER char& - cr() + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, formatted const&) { - static char p('\n'); return p; + const_cast&>(get_facet>(os)).formatted = true; + + return os; } - - GLM_FUNC_QUALIFIER std::ios_base& - column_major(std::ios_base& os) + + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, unformatted const&) { - order() = order_t::column_major; - + const_cast&>(get_facet>(os)).formatted = false; + return os; } - GLM_FUNC_QUALIFIER std::ios_base& - row_major(std::ios_base& os) + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, precision const& a) { - order() = order_t::row_major; + const_cast&>(get_facet>(os)).precision = a.value; + + 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; + + return os; + } + + template + 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]; return os; } - GLM_FUNC_QUALIFIER std::ios_base& - formatted(std::ios_base& os) + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, order const& a) { - cr() = '\n'; - - return os; - } - - GLM_FUNC_QUALIFIER std::ios_base& - unformatted(std::ios_base& os) - { - cr() = ' '; - + const_cast&>(get_facet>(os)).order = a.value; + return os; } @@ -109,8 +161,6 @@ namespace glm namespace detail { - // functions, inlined (inline) - template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tquat const& a) @@ -118,17 +168,26 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - // boost::io::ios_all_saver const ias(os); - - os << std::fixed << std::setprecision(io::precision()) - << '[' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.w << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.z - << ']'; - } + io::format_punct const& fmt(io::get_facet>(os)); + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; } @@ -139,13 +198,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - // boost::io::ios_all_saver const ias(os); - - os << std::fixed << std::setprecision(io::precision()) - << '[' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y - << ']'; + io::format_punct const& fmt(io::get_facet>(os)); + + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; @@ -158,19 +226,28 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - // boost::io::ios_all_saver const ias(os); - - os << std::fixed << std::setprecision(io::precision()) - << '[' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.z - << ']'; - } + io::format_punct const& fmt(io::get_facet>(os)); + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; } - + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec4 const& a) @@ -178,17 +255,26 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - // boost::io::ios_all_saver const ias(os); - - os << std::fixed << std::setprecision(io::precision()) - << '[' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.z << ',' - << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.w - << ']'; - } + io::format_punct const& fmt(io::get_facet>(os)); + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; } @@ -199,15 +285,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + + 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; @@ -220,16 +311,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -242,17 +338,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -265,15 +366,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + 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; @@ -286,16 +392,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -308,17 +419,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -331,15 +447,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + 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; @@ -352,16 +473,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -374,17 +500,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -398,19 +529,28 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x4 ml(a.first); - tmat4x4 mr(a.second); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x4 ml(a.first); + tmat4x4 mr(a.second); - if (io::order_t::row_major == io::order()) { + if (io::order_type::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 << io::cr() - << '[' << ml[0] << " [" << mr[0] << io::cr() - << ' ' << ml[1] << " " << mr[1] << io::cr() - << ' ' << ml[2] << " " << mr[2] << io::cr() - << ' ' << ml[3] << "] " << mr[3] << ']'; + 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; diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index 86792bc9..1f23a4f2 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -34,6 +34,32 @@ namespace { } // namespace { +template +int test_io_quat(OS& os) +{ + os << '\n' + << typeid(OS).name() + << '\n'; + + glm::detail::tquat const q(1, 0, 0, 0); + + { + glm::io::basic_format_saver const iofs(os); + + os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + } + + { + glm::io::basic_format_saver const iofs(os); + + os << glm::io::unformatted() + << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + } + + return 0; +} + template int test_io_vec(OS& os) { @@ -49,12 +75,10 @@ int test_io_vec(OS& os) << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; - glm::io::precision_guard const iopg; + glm::io::basic_format_saver const iofs(os); - glm::io::precision() = 2; - glm::io::value_width() = 1 + 2 + 1 + glm::io::precision(); - - os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' + os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; @@ -93,12 +117,10 @@ int test_io_mat(OS& os) << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; #endif - glm::io::precision_guard const iopg; + glm::io::basic_format_saver const iofs(os); - glm::io::precision() = 2; - glm::io::value_width() = 1 + 2 + 1 + glm::io::precision(); - - os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' + os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4(v4_1, v4_2) << '\n' << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2(v2_1, v2_2, v2_3) << '\n' @@ -108,7 +130,8 @@ int test_io_mat(OS& os) << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; - os << glm::io::column_major + os << glm::io::unformatted() + << glm::io::order(glm::io::order_type::column_major) << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4(v4_1, v4_2) << '\n' @@ -126,6 +149,13 @@ int main() { int Error(0); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_vec(std::cout); Error += test_io_vec(std::wcout); Error += test_io_vec(std::cout); From 0e3cebf23a48c0ddb3763d9d7eedaf4cfef664d8 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Wed, 18 Dec 2013 10:34:06 +0000 Subject: [PATCH 2/7] removed boost dependencies --- glm/gtx/io.hpp | 46 +++++++++++++++++++++++++++++++++++++-------- glm/gtx/io.inl | 41 +++++++++++++++++++++++++++++----------- test/gtx/gtx_io.cpp | 43 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 103 insertions(+), 27 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 71ae187d..f1b8dd53 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -26,7 +26,7 @@ /// @author Jan P Springer (regnirpsj@gmail.com) /// /// @see core (dependence) -/// @see gtx_quaternion (dependence) +/// @see gtc_quaternion (dependence) /// /// @defgroup gtx_io GLM_GTX_io /// @ingroup gtx @@ -51,11 +51,9 @@ # pragma message("GLM: GLM_GTX_io extension included") #endif -#include // basic_ios_all_saver<> (fwd) -#include // boost::noncopyable -#include // std::basic_ostream<> (fwd) -#include // std::locale, std::locale::facet, std::locale::id -#include // std::pair<> +#include // std::basic_ostream<> (fwd) +#include // std::locale, std::locale::facet, std::locale::id +#include // std::pair<> namespace glm { @@ -92,7 +90,37 @@ namespace glm }; template > - class basic_format_saver : private boost::noncopyable { + class basic_state_saver { + + public: + + explicit basic_state_saver(std::basic_ios&); + ~basic_state_saver(); + + private: + + typedef ::std::basic_ios state_type; + typedef typename state_type::char_type char_type; + typedef ::std::ios_base::fmtflags flags_type; + typedef ::std::streamsize streamsize_type; + typedef ::std::locale const locale_type; + + state_type& state_; + flags_type flags_; + streamsize_type precision_; + streamsize_type width_; + char_type fill_; + locale_type locale_; + + basic_state_saver& operator=(basic_state_saver const&); + + }; + + typedef basic_state_saver state_saver; + typedef basic_state_saver wstate_saver; + + template > + class basic_format_saver { public: @@ -101,7 +129,9 @@ namespace glm private: - boost::io::basic_ios_all_saver const ias_; + basic_state_saver const bss_; + + basic_format_saver& operator=(basic_format_saver const&); }; diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index c102f10a..7d3e88fc 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -2,15 +2,13 @@ // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2013-11-22 -// Updated : 2013-12-17 +// Updated : 2013-12-18 // Licence : This source is under MIT License // File : glm/gtx/inl.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -#include // boost::io::ios_all_saver -#include // std::setfill<>, std::fixed, std::setprecision, std::right, - // std::setw -#include // std::basic_ostream<> +#include // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw +#include // std::basic_ostream<> namespace glm { @@ -49,11 +47,32 @@ namespace glm 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 + 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) - : boost::noncopyable(), - ias_ (a) + : bss_(a) { a.imbue(std::locale(a.getloc(), new format_punct(get_facet>(a)))); } @@ -171,7 +190,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -201,7 +220,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -229,7 +248,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -258,7 +277,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index 1f23a4f2..e9ab76e7 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace { @@ -32,6 +33,32 @@ namespace { return os; } + template + std::basic_string + type_name(std::basic_ostream& os, T const&) + { + std::basic_ostringstream ostr; + + if (typeid(T) == typeid(glm::detail::tquat)) { ostr << "quat"; } + else if (typeid(T) == typeid(glm::detail::tvec2)) { ostr << "vec2"; } + else if (typeid(T) == typeid(glm::detail::tvec3)) { ostr << "vec3"; } + else if (typeid(T) == typeid(glm::detail::tvec4)) { ostr << "vec4"; } + else if (typeid(T) == typeid(glm::detail::tmat2x2)) { ostr << "mat2x2"; } + else if (typeid(T) == typeid(glm::detail::tmat2x3)) { ostr << "mat2x3"; } + else if (typeid(T) == typeid(glm::detail::tmat2x4)) { ostr << "mat2x4"; } + else if (typeid(T) == typeid(glm::detail::tmat3x2)) { ostr << "mat3x2"; } + else if (typeid(T) == typeid(glm::detail::tmat3x3)) { ostr << "mat3x3"; } + else if (typeid(T) == typeid(glm::detail::tmat3x4)) { ostr << "mat3x4"; } + else if (typeid(T) == typeid(glm::detail::tmat4x2)) { ostr << "mat4x2"; } + else if (typeid(T) == typeid(glm::detail::tmat4x3)) { ostr << "mat4x3"; } + else if (typeid(T) == typeid(glm::detail::tmat4x4)) { ostr << "mat4x4"; } + else { ostr << "unknown"; } + + ostr << '<' << typeid(U).name() << ',' << P << '>'; + + return ostr.str(); + } + } // namespace { template @@ -47,14 +74,14 @@ int test_io_quat(OS& os) glm::io::basic_format_saver const iofs(os); os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) - << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + << type_name(os, q) << ": " << q << '\n'; } { glm::io::basic_format_saver const iofs(os); os << glm::io::unformatted() - << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + << type_name(os, q) << ": " << q << '\n'; } return 0; @@ -71,16 +98,16 @@ int test_io_vec(OS& os) glm::detail::tvec3 const v3(2, 3, 4); glm::detail::tvec4 const v4(5, 6, 7, 8); - os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' - << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' - << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; + os << type_name(os, v2) << ": " << v2 << '\n' + << type_name(os, v3) << ": " << v3 << '\n' + << type_name(os, v4) << ": " << v4 << '\n'; glm::io::basic_format_saver const iofs(os); os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) - << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' - << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' - << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; + << type_name(os, v2) << ": " << v2 << '\n' + << type_name(os, v3) << ": " << v3 << '\n' + << type_name(os, v4) << ": " << v4 << '\n'; return 0; } From 39179ba1adde7f860826bc5e667f0f224758e5b3 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Thu, 26 Dec 2013 15:15:53 +0000 Subject: [PATCH 3/7] un/formatted() usage to un/formatted --- glm/gtx/io.hpp | 11 ++++------- glm/gtx/io.inl | 18 +++++++++--------- test/gtx/gtx_io.cpp | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index f1b8dd53..9e68cd39 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -138,9 +138,6 @@ namespace glm typedef basic_format_saver format_saver; typedef basic_format_saver wformat_saver; - struct formatted { /* empty */ }; - struct unformatted { /* empty */ }; - struct precision { unsigned value; @@ -178,11 +175,11 @@ namespace glm template FTy const& get_facet(std::basic_ios&); + template + std::basic_ios& formatted(std::basic_ios&); + template + std::basic_ios& unformattet(std::basic_ios&); - template - std::basic_ostream& operator<<(std::basic_ostream&, formatted const&); - template - std::basic_ostream& operator<<(std::basic_ostream&, unformatted const&); template std::basic_ostream& operator<<(std::basic_ostream&, precision const&); template diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 7d3e88fc..84fc29d9 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -119,21 +119,21 @@ namespace glm } template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, formatted const&) + GLM_FUNC_QUALIFIER std::basic_ios& + formatted(std::basic_ios& ios) { - const_cast&>(get_facet>(os)).formatted = true; + const_cast&>(get_facet>(ios)).formatted = true; - return os; + return ios; } - + template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, unformatted const&) + GLM_FUNC_QUALIFIER std::basic_ios& + unformatted(std::basic_ios& ios) { - const_cast&>(get_facet>(os)).formatted = false; + const_cast&>(get_facet>(ios)).formatted = false; - return os; + return ios; } template diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index e9ab76e7..8c479b5f 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -80,7 +80,7 @@ int test_io_quat(OS& os) { glm::io::basic_format_saver const iofs(os); - os << glm::io::unformatted() + os << glm::io::unformatted << type_name(os, q) << ": " << q << '\n'; } @@ -157,7 +157,7 @@ int test_io_mat(OS& os) << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; - os << glm::io::unformatted() + os << glm::io::unformatted << glm::io::order(glm::io::order_type::column_major) << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' From 478dc697ff9c46a034c9bc4143d6498ae63f98df Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:11:25 +0100 Subject: [PATCH 4/7] fixed: compile problems w/ non-existent header files --- glm/ext.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/ext.hpp b/glm/ext.hpp index 95121dc7..5ea95f2f 100644 --- a/glm/ext.hpp +++ b/glm/ext.hpp @@ -73,7 +73,7 @@ #include "./gtc/quaternion.hpp" #include "./gtc/random.hpp" #include "./gtc/reciprocal.hpp" -#include "./gtc/swizzle.hpp" +// #include "./gtc/swizzle.hpp" #include "./gtc/type_precision.hpp" #include "./gtc/type_ptr.hpp" #include "./gtc/ulp.hpp" @@ -81,7 +81,7 @@ #include "./gtx/associated_min_max.hpp" #include "./gtx/bit.hpp" #include "./gtx/closest_point.hpp" -#include "./gtx/color_cast.hpp" +// #include "./gtx/color_cast.hpp" #include "./gtx/color_space.hpp" #include "./gtx/color_space_YCoCg.hpp" #include "./gtx/compatibility.hpp" From ae691ce39ada6783f451869350425325836a6b2b Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:12:38 +0100 Subject: [PATCH 5/7] commented out already declred types (in glm/fwd.hpp) --- glm/gtc/type_precision.hpp | 164 ++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/glm/gtc/type_precision.hpp b/glm/gtc/type_precision.hpp index 5894bc58..bc4a1c91 100644 --- a/glm/gtc/type_precision.hpp +++ b/glm/gtc/type_precision.hpp @@ -255,70 +255,70 @@ namespace glm /// 8 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i8vec1; + // typedef detail::tvec1 i8vec1; /// 8 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i8vec2; + //typedef detail::tvec2 i8vec2; /// 8 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i8vec3; + //typedef detail::tvec3 i8vec3; /// 8 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i8vec4; + //typedef detail::tvec4 i8vec4; /// 16 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i16vec1; + //typedef detail::tvec1 i16vec1; /// 16 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i16vec2; + //typedef detail::tvec2 i16vec2; /// 16 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i16vec3; + //typedef detail::tvec3 i16vec3; /// 16 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i16vec4; + //typedef detail::tvec4 i16vec4; /// 32 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i32vec1; + //typedef detail::tvec1 i32vec1; /// 32 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i32vec2; + //typedef detail::tvec2 i32vec2; /// 32 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i32vec3; + //typedef detail::tvec3 i32vec3; /// 32 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i32vec4; + //typedef detail::tvec4 i32vec4; /// 64 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i64vec1; + //typedef detail::tvec1 i64vec1; /// 64 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i64vec2; + //typedef detail::tvec2 i64vec2; /// 64 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i64vec3; + //typedef detail::tvec3 i64vec3; /// 64 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i64vec4; + //typedef detail::tvec4 i64vec4; ///////////////////////////// @@ -520,70 +520,70 @@ namespace glm /// Default precision 8 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u8vec1; + //typedef detail::tvec1 u8vec1; /// Default precision 8 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u8vec2; + //typedef detail::tvec2 u8vec2; /// Default precision 8 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u8vec3; + //typedef detail::tvec3 u8vec3; /// Default precision 8 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u8vec4; + //typedef detail::tvec4 u8vec4; /// Default precision 16 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u16vec1; + //typedef detail::tvec1 u16vec1; /// Default precision 16 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u16vec2; + //typedef detail::tvec2 u16vec2; /// Default precision 16 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u16vec3; + //typedef detail::tvec3 u16vec3; /// Default precision 16 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u16vec4; + //typedef detail::tvec4 u16vec4; /// Default precision 32 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u32vec1; + //typedef detail::tvec1 u32vec1; /// Default precision 32 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u32vec2; + //typedef detail::tvec2 u32vec2; /// Default precision 32 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u32vec3; + //typedef detail::tvec3 u32vec3; /// Default precision 32 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u32vec4; + //typedef detail::tvec4 u32vec4; /// Default precision 64 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u64vec1; + //typedef detail::tvec1 u64vec1; /// Default precision 64 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u64vec2; + //typedef detail::tvec2 u64vec2; /// Default precision 64 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u64vec3; + //typedef detail::tvec3 u64vec3; /// Default precision 64 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u64vec4; + //typedef detail::tvec4 u64vec4; ////////////////////// @@ -618,53 +618,53 @@ namespace glm /// Single-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 fvec1; + //typedef detail::tvec1 fvec1; /// Single-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 fvec2; + //typedef detail::tvec2 fvec2; /// Single-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 fvec3; + //typedef detail::tvec3 fvec3; /// Single-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 fvec4; + //typedef detail::tvec4 fvec4; /// Single-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 f32vec1; + //typedef detail::tvec1 f32vec1; /// Single-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 f32vec2; + //typedef detail::tvec2 f32vec2; /// Single-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 f32vec3; + //typedef detail::tvec3 f32vec3; /// Single-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 f32vec4; + //typedef detail::tvec4 f32vec4; /// Double-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 f64vec1; + //typedef detail::tvec1 f64vec1; /// Double-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 f64vec2; + //typedef detail::tvec2 f64vec2; /// Double-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 f64vec3; + //typedef detail::tvec3 f64vec3; /// Double-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 f64vec4; + //typedef detail::tvec4 f64vec4; ////////////////////// @@ -676,15 +676,15 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 fmat2; + //typedef detail::tmat2x2 fmat2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 fmat3; + //typedef detail::tmat3x3 fmat3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 fmat4; + //typedef detail::tmat4x4 fmat4; /// Single-precision floating-point 1x1 matrix. @@ -693,39 +693,39 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 fmat2x2; + //typedef detail::tmat2x2 fmat2x2; /// Single-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 fmat2x3; + //typedef detail::tmat2x3 fmat2x3; /// Single-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 fmat2x4; + //typedef detail::tmat2x4 fmat2x4; /// Single-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 fmat3x2; + //typedef detail::tmat3x2 fmat3x2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 fmat3x3; + //typedef detail::tmat3x3 fmat3x3; /// Single-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 fmat3x4; + //typedef detail::tmat3x4 fmat3x4; /// Single-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 fmat4x2; + //typedef detail::tmat4x2 fmat4x2; /// Single-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 fmat4x3; + //typedef detail::tmat4x3 fmat4x3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 fmat4x4; + //typedef detail::tmat4x4 fmat4x4; /// Single-precision floating-point 1x1 matrix. @@ -734,15 +734,15 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f32mat2; + //typedef detail::tmat2x2 f32mat2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f32mat3; + //typedef detail::tmat3x3 f32mat3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f32mat4; + //typedef detail::tmat4x4 f32mat4; /// Single-precision floating-point 1x1 matrix. @@ -751,39 +751,39 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f32mat2x2; + //typedef detail::tmat2x2 f32mat2x2; /// Single-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 f32mat2x3; + //typedef detail::tmat2x3 f32mat2x3; /// Single-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 f32mat2x4; + //typedef detail::tmat2x4 f32mat2x4; /// Single-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 f32mat3x2; + //typedef detail::tmat3x2 f32mat3x2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f32mat3x3; + //typedef detail::tmat3x3 f32mat3x3; /// Single-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 f32mat3x4; + //typedef detail::tmat3x4 f32mat3x4; /// Single-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 f32mat4x2; + //typedef detail::tmat4x2 f32mat4x2; /// Single-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 f32mat4x3; + //typedef detail::tmat4x3 f32mat4x3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f32mat4x4; + //typedef detail::tmat4x4 f32mat4x4; /// Double-precision floating-point 1x1 matrix. @@ -792,15 +792,15 @@ namespace glm /// Double-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f64mat2; + //typedef detail::tmat2x2 f64mat2; /// Double-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f64mat3; + //typedef detail::tmat3x3 f64mat3; /// Double-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f64mat4; + //typedef detail::tmat4x4 f64mat4; /// Double-precision floating-point 1x1 matrix. @@ -809,39 +809,39 @@ namespace glm /// Double-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f64mat2x2; + //typedef detail::tmat2x2 f64mat2x2; /// Double-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 f64mat2x3; + //typedef detail::tmat2x3 f64mat2x3; /// Double-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 f64mat2x4; + //typedef detail::tmat2x4 f64mat2x4; /// Double-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 f64mat3x2; + //typedef detail::tmat3x2 f64mat3x2; /// Double-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f64mat3x3; + //typedef detail::tmat3x3 f64mat3x3; /// Double-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 f64mat3x4; + //typedef detail::tmat3x4 f64mat3x4; /// Double-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 f64mat4x2; + //typedef detail::tmat4x2 f64mat4x2; /// Double-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 f64mat4x3; + //typedef detail::tmat4x3 f64mat4x3; /// Double-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f64mat4x4; + //typedef detail::tmat4x4 f64mat4x4; ////////////////////////// @@ -849,11 +849,11 @@ namespace glm /// Single-precision floating-point quaternion. /// @see gtc_type_precision - typedef detail::tquat f32quat; + //typedef detail::tquat f32quat; /// Double-precision floating-point quaternion. /// @see gtc_type_precision - typedef detail::tquat f64quat; + //typedef detail::tquat f64quat; /// @} }//namespace glm From 37e586820080437a7e26441b2dd54398cc1d4d48 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:13:20 +0100 Subject: [PATCH 6/7] fixed: warning wrt. strict aliasing on gcc 4.8.2/clang3.3 --- glm/core/func_exponential.inl | 6 +++++- glm/core/func_integer.inl | 5 +++-- glm/core/func_packing.inl | 12 +++++++++--- glm/gtx/bit.inl | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/glm/core/func_exponential.inl b/glm/core/func_exponential.inl index 9c03129e..e8ff4cfe 100644 --- a/glm/core/func_exponential.inl +++ b/glm/core/func_exponential.inl @@ -179,7 +179,11 @@ namespace detail genType xhalf(tmp * genType(0.5f)); genUType i = *reinterpret_cast(const_cast(&v)); i = genUType(0x5f375a86) - (i >> genUType(1)); - tmp = *reinterpret_cast(&i); + // tmp = *reinterpret_cast(&i); + { + genType* ptr(reinterpret_cast(&i)); + tmp = *ptr; + } tmp = tmp * (genType(1.5f) - xhalf * tmp * tmp); return tmp; } diff --git a/glm/core/func_integer.inl b/glm/core/func_integer.inl index 370e7770..b18696bd 100644 --- a/glm/core/func_integer.inl +++ b/glm/core/func_integer.inl @@ -172,7 +172,8 @@ namespace glm uint64 Value64 = static_cast(x) * static_cast(y); msb = *(reinterpret_cast(&Value64) + 1); - lsb = reinterpret_cast(Value64); + //lsb = reinterpret_cast(Value64); + lsb = *(reinterpret_cast(Value64)); } template <> @@ -231,7 +232,7 @@ namespace glm int64 Value64 = static_cast(x) * static_cast(y); msb = *(reinterpret_cast(&Value64) + 1); - lsb = reinterpret_cast(Value64); + // lsb = reinterpret_cast(Value64); } template <> diff --git a/glm/core/func_packing.inl b/glm/core/func_packing.inl index 7e26b91c..47b84733 100644 --- a/glm/core/func_packing.inl +++ b/glm/core/func_packing.inl @@ -35,7 +35,9 @@ namespace glm GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v) { u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f)); - return reinterpret_cast(Topack); + // return reinterpret_cast(Topack); + uint* ptr(reinterpret_cast(&Topack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p) @@ -47,7 +49,9 @@ namespace glm GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v) { i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); - return reinterpret_cast(Topack); + // return reinterpret_cast(Topack); + uint* ptr(reinterpret_cast(&Topack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p) @@ -100,7 +104,9 @@ namespace glm detail::toFloat16(v.x), detail::toFloat16(v.y)); - return *reinterpret_cast(&Unpack); + //return *reinterpret_cast(&Unpack); + uint* ptr(reinterpret_cast(&Unpack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) diff --git a/glm/gtx/bit.inl b/glm/gtx/bit.inl index 53ac2954..571baf25 100644 --- a/glm/gtx/bit.inl +++ b/glm/gtx/bit.inl @@ -551,7 +551,7 @@ namespace glm assert(ToBit <= sizeof(genIUType) * std::size_t(8)); genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) + for(signed i = 0; i <= ToBit; ++i) Result |= (1 << i); return Result; } @@ -568,7 +568,7 @@ namespace glm assert(ToBit <= sizeof(genIUType) * std::size_t(8)); genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) + for(signed i = 0; i <= ToBit; ++i) Result &= ~(1 << i); return Result; } From 9ecc30c5dddd31b3cfdbcf667bbded186a5db2ef Mon Sep 17 00:00:00 2001 From: jan p springer Date: Tue, 15 Apr 2014 18:37:34 +0100 Subject: [PATCH 7/7] added: missing value_type typedef --- glm/gtc/quaternion.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index cc3c76ad..7ce9468c 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -56,6 +56,7 @@ namespace detail { enum ctor{null}; + typedef T value_type; typedef tvec4 bool_type; public: