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; }