diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index f30cd0fe2..ffeb453fe 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -64,12 +64,14 @@ namespace glm char_type separator; char_type delim_left; char_type delim_right; + char_type fill; char_type space; char_type newline; + char_type firstline; order_type order; - GLM_FUNC_DECL explicit format_punct(size_t a = 0); - GLM_FUNC_DECL explicit format_punct(format_punct const&); + GLM_FUNC_DISCARD_DECL explicit format_punct(size_t a = 0); + GLM_FUNC_DISCARD_DECL explicit format_punct(format_punct const&); }; template > @@ -77,8 +79,8 @@ namespace glm public: - GLM_FUNC_DECL explicit basic_state_saver(std::basic_ios&); - GLM_FUNC_DECL ~basic_state_saver(); + GLM_FUNC_DISCARD_DECL explicit basic_state_saver(std::basic_ios&); + GLM_FUNC_DISCARD_DECL ~basic_state_saver(); private: @@ -106,8 +108,8 @@ namespace glm { public: - GLM_FUNC_DECL explicit basic_format_saver(std::basic_ios&); - GLM_FUNC_DECL ~basic_format_saver(); + GLM_FUNC_DISCARD_DECL explicit basic_format_saver(std::basic_ios&); + GLM_FUNC_DISCARD_DECL ~basic_format_saver(); private: @@ -123,14 +125,14 @@ namespace glm { unsigned value; - GLM_FUNC_DECL explicit precision(unsigned); + GLM_FUNC_DISCARD_DECL explicit precision(unsigned = 3); }; struct width { unsigned value; - GLM_FUNC_DECL explicit width(unsigned); + GLM_FUNC_DISCARD_DECL explicit width(unsigned = 8); }; template @@ -138,14 +140,21 @@ namespace glm { CTy value[3]; - GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); + GLM_FUNC_DISCARD_DECL explicit delimeter(CTy /* left */ = "[", CTy /* right */ = "]", CTy /* separator */ = ','); + }; + + template + struct filler + { + CTy value[4]; + GLM_FUNC_DISCARD_DECL explicit filler(CTy /* fill */ = ' ', CTy /* space */ = ' ', CTy /* newline */ = '\n', CTy /* firstline */ = '\n'); }; struct order { order_type value; - GLM_FUNC_DECL explicit order(order_type); + GLM_FUNC_DISCARD_DECL explicit order(order_type = column_major); }; // functions, inlined (inline) @@ -157,6 +166,11 @@ namespace glm template std::basic_ios& unformatted(std::basic_ios&); + template + std::basic_ios& reset(std::basic_ios&); + template + std::basic_ios& compressed(std::basic_ios&); + template std::basic_ostream& operator<<(std::basic_ostream&, precision const&); template @@ -164,40 +178,42 @@ namespace glm template std::basic_ostream& operator<<(std::basic_ostream&, delimeter const&); template + std::basic_ostream& operator<<(std::basic_ostream&, filler const&); + template std::basic_ostream& operator<<(std::basic_ostream&, order const&); }//namespace io template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, qua const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, qua const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<1, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<1, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<2, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<2, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<3, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<3, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<4, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, vec<4, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 2, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 2, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 3, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 3, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 4, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<2, 4, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 2, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 2, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 3, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 3, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 4, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<3, 4, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 2, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 2, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 3, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 3, T, Q> const&); template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 4, T, Q> const&); + GLM_FUNC_DISCARD_DECL std::basic_ostream& operator<<(std::basic_ostream&, mat<4, 4, T, Q> const&); - template - GLM_FUNC_DECL std::basic_ostream & operator<<(std::basic_ostream &, + template + GLM_FUNC_DISCARD_DECL std::basic_ostream & operator<<(std::basic_ostream &, std::pair const, mat<4, 4, T, Q> const> const&); /// @} diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index d4ef825eb..13ed2fc3b 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -21,12 +21,14 @@ namespace io : std::locale::facet(a) , formatted(true) , precision(3) - , width(1 + 4 + 1 + precision) + , width(4 + 1 + precision) , separator(',') , delim_left('[') , delim_right(']') + , fill(' ') , space(' ') , newline('\n') + , firstline('\n') , order(column_major) {} @@ -39,8 +41,10 @@ namespace io , separator(a.separator) , delim_left(a.delim_left) , delim_right(a.delim_right) + , fill(a.fill) , space(a.space) , newline(a.newline) + , firstline(a.firstline) , order(a.order) {} @@ -95,6 +99,16 @@ namespace io value[2] = c; } + template + GLM_FUNC_QUALIFIER filler::filler(CTy a, CTy b, CTy c, CTy d) + : value() + { + value[0] = a; + value[1] = b; + value[2] = c; + value[3] = d; + } + GLM_FUNC_QUALIFIER order::order(order_type a) : value(a) {} @@ -102,6 +116,7 @@ namespace io template GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios& ios) { + // Destruction handled by locale (0 passed as default argument in the constructor) if(!std::has_facet(ios.getloc())) ios.imbue(std::locale(ios.getloc(), new FTy)); @@ -122,6 +137,44 @@ namespace io return ios; } + template + GLM_FUNC_QUALIFIER std::basic_ios& reset(std::basic_ios& ios) + { + // could leverage on the default constructor, but requires additional memory allocation + //ios.imbue(std::locale(ios.getloc(), new format_punct)); + //return ios; + + format_punct & fmt(const_cast&>(get_facet >(ios))); + + fmt.formatted = true; + fmt.precision = 3; + fmt.width = 4 + 1 + fmt.precision; + fmt.separator = ','; + fmt.delim_left = '['; + fmt.delim_right = ']'; + fmt.fill = ' '; + fmt.space = ' '; + fmt.newline = '\n'; + fmt.firstline = '\n'; + fmt.order = column_major; + + return ios; + } + + template + GLM_FUNC_QUALIFIER std::basic_ios& compressed(std::basic_ios& ios) + { + format_punct & fmt(const_cast&>(get_facet >(ios))); + + fmt.formatted = true; + fmt.width = 0; + //fmt.space = ' '; + fmt.newline = ','; + fmt.firstline = '\0'; + + return ios; + } + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, precision const& a) { @@ -148,6 +201,19 @@ namespace io return os; } + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, filler const& a) + { + format_punct & fmt(const_cast&>(get_facet >(os))); + + fmt.fill = a.value[0]; + fmt.space = a.value[1]; + fmt.newline = a.value[2]; + fmt.firstline = a.value[3]; + + return os; + } + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, order const& a) { @@ -174,13 +240,13 @@ namespace detail { io::basic_state_saver const bss(os); - os << std::fixed << std::right << std::setprecision(static_cast(fmt.precision)) << std::setfill(fmt.space) << fmt.delim_left; + os << std::fixed << std::right << std::setprecision(static_cast(fmt.precision)) << std::setfill(fmt.fill) << fmt.delim_left; for(length_t i(0); i < components; ++i) { os << std::setw(static_cast(fmt.width)) << a[i]; if(components-1 != i) - os << fmt.separator; + os << fmt.separator << fmt.space; } os << fmt.delim_right; @@ -247,7 +313,8 @@ namespace detail if(fmt.formatted) { - os << fmt.newline << fmt.delim_left; + if (fmt.firstline != '\0') os << fmt.firstline; + os << fmt.delim_left; switch(fmt.order) { @@ -390,7 +457,8 @@ namespace detail if(fmt.formatted) { - os << fmt.newline << fmt.delim_left; + if (fmt.firstline != '\0') os << fmt.firstline; + os << fmt.delim_left; switch(fmt.order) {