From 4fda9665334732a6e67d92a8b2c6a03402e74fa1 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 25 Jan 2024 16:14:40 +0100 Subject: [PATCH 1/9] modify facet filler --- glm/gtx/io.hpp | 10 ++++++++++ glm/gtx/io.inl | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index f30cd0fe2..40aa63c48 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -141,6 +141,14 @@ namespace glm GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); }; + template + struct filler + { + CTy value[2]; + + GLM_FUNC_DECL explicit filler(CTy /* Space */ = ' ', CTy /* Newline */ = '\n'); + }; + struct order { order_type value; @@ -164,6 +172,8 @@ 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 diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index d4ef825eb..dbe84325a 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -95,6 +95,14 @@ namespace io value[2] = c; } + template + GLM_FUNC_QUALIFIER filler::filler(CTy a, CTy b) + : value() + { + value[0] = a; + value[1] = b; + } + GLM_FUNC_QUALIFIER order::order(order_type a) : value(a) {} @@ -148,6 +156,17 @@ 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.space = a.value[0]; + fmt.newline = a.value[1]; + + return os; + } + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, order const& a) { From eed8cf5a2f53a5c283dddfda70934a5e25e16485 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 25 Jan 2024 16:16:07 +0100 Subject: [PATCH 2/9] default values for facet operator structs --- glm/gtx/io.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 40aa63c48..b11c2eea7 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -123,14 +123,14 @@ namespace glm { unsigned value; - GLM_FUNC_DECL explicit precision(unsigned); + GLM_FUNC_DECL explicit precision(unsigned = 3); }; struct width { unsigned value; - GLM_FUNC_DECL explicit width(unsigned); + GLM_FUNC_DECL explicit width(unsigned = 0); }; template @@ -138,7 +138,7 @@ namespace glm { CTy value[3]; - GLM_FUNC_DECL explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); + GLM_FUNC_DECL explicit delimeter(CTy /* left */ = "[", CTy /* right */ = "]", CTy /* separator */ = ','); }; template @@ -146,14 +146,14 @@ namespace glm { CTy value[2]; - GLM_FUNC_DECL explicit filler(CTy /* Space */ = ' ', CTy /* Newline */ = '\n'); + GLM_FUNC_DECL explicit filler(CTy /* space */ = ' ', CTy /* newline */ = '\n'); }; struct order { order_type value; - GLM_FUNC_DECL explicit order(order_type); + GLM_FUNC_DECL explicit order(order_type = column_major); }; // functions, inlined (inline) From 24123f3b06be4efffe9767ade80b6cc3886017bb Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 25 Jan 2024 16:18:03 +0100 Subject: [PATCH 3/9] print_matrix_on skip initial newline --- glm/gtx/io.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index dbe84325a..9989c0879 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -266,7 +266,7 @@ namespace detail if(fmt.formatted) { - os << fmt.newline << fmt.delim_left; + os << /*fmt.newline <<*/ fmt.delim_left; switch(fmt.order) { @@ -409,7 +409,7 @@ namespace detail if(fmt.formatted) { - os << fmt.newline << fmt.delim_left; + os << /*fmt.newline <<*/ fmt.delim_left; switch(fmt.order) { From 325f6b23567fcf690d1e3f711d1889ae5f91b620 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 25 Jan 2024 16:18:39 +0100 Subject: [PATCH 4/9] print_vector_on add space after separator --- glm/gtx/io.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 9989c0879..c81ba1fbf 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -199,7 +199,7 @@ namespace detail { 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; From dac18393fa803eeb1a4517882b4349e4ab025ea6 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 25 Jan 2024 16:58:20 +0100 Subject: [PATCH 5/9] reduce default width to compensate new space --- glm/gtx/io.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index c81ba1fbf..4717a1688 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -21,7 +21,7 @@ namespace io : std::locale::facet(a) , formatted(true) , precision(3) - , width(1 + 4 + 1 + precision) + , width(4 + 1 + precision) , separator(',') , delim_left('[') , delim_right(']') From 629ab262404af8181fc3ded59c4dda540de71e6c Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Fri, 26 Jan 2024 10:16:19 +0100 Subject: [PATCH 6/9] dedicated property for fill instead of reusing space --- glm/gtx/io.hpp | 5 +++-- glm/gtx/io.inl | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index b11c2eea7..d5f1e55d6 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -64,6 +64,7 @@ namespace glm char_type separator; char_type delim_left; char_type delim_right; + char_type fill; char_type space; char_type newline; order_type order; @@ -144,9 +145,9 @@ namespace glm template struct filler { - CTy value[2]; + CTy value[3]; - GLM_FUNC_DECL explicit filler(CTy /* space */ = ' ', CTy /* newline */ = '\n'); + GLM_FUNC_DECL explicit filler(CTy /* fill */ = ' ', CTy /* space */ = ' ', CTy /* newline */ = '\n'); }; struct order diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 4717a1688..b7586e694 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -25,6 +25,7 @@ namespace io , separator(',') , delim_left('[') , delim_right(']') + , fill(' ') , space(' ') , newline('\n') , order(column_major) @@ -39,6 +40,7 @@ namespace io , separator(a.separator) , delim_left(a.delim_left) , delim_right(a.delim_right) + , fill(a.fill) , space(a.space) , newline(a.newline) , order(a.order) @@ -96,11 +98,12 @@ namespace io } template - GLM_FUNC_QUALIFIER filler::filler(CTy a, CTy b) + GLM_FUNC_QUALIFIER filler::filler(CTy a, CTy b, CTy c) : value() { value[0] = a; value[1] = b; + value[2] = c; } GLM_FUNC_QUALIFIER order::order(order_type a) @@ -161,8 +164,9 @@ namespace io { format_punct & fmt(const_cast&>(get_facet >(os))); - fmt.space = a.value[0]; - fmt.newline = a.value[1]; + fmt.fill = a.value[0]; + fmt.space = a.value[1]; + fmt.newline = a.value[2]; return os; } @@ -193,7 +197,7 @@ 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) { From 916bc046800b755368a982dec262c4672f92b878 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Fri, 26 Jan 2024 13:28:17 +0100 Subject: [PATCH 7/9] added firstline dedicated property + default width set to 8 --- glm/gtx/io.hpp | 8 ++++---- glm/gtx/io.inl | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index d5f1e55d6..8f556ed28 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -67,6 +67,7 @@ namespace glm 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); @@ -131,7 +132,7 @@ namespace glm { unsigned value; - GLM_FUNC_DECL explicit width(unsigned = 0); + GLM_FUNC_DECL explicit width(unsigned = 8); }; template @@ -145,9 +146,8 @@ namespace glm template struct filler { - CTy value[3]; - - GLM_FUNC_DECL explicit filler(CTy /* fill */ = ' ', CTy /* space */ = ' ', CTy /* newline */ = '\n'); + CTy value[4]; + GLM_FUNC_DECL explicit filler(CTy /* fill */ = ' ', CTy /* space */ = ' ', CTy /* newline */ = '\n', CTy /* firstline */ = '\n'); }; struct order diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index b7586e694..51002ab6b 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -28,6 +28,7 @@ namespace io , fill(' ') , space(' ') , newline('\n') + , firstline('\n') , order(column_major) {} @@ -43,6 +44,7 @@ namespace io , fill(a.fill) , space(a.space) , newline(a.newline) + , firstline(a.firstline) , order(a.order) {} @@ -97,14 +99,15 @@ namespace io value[2] = c; } - template - GLM_FUNC_QUALIFIER filler::filler(CTy a, CTy b, CTy c) - : value() - { - value[0] = a; - value[1] = b; - 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) @@ -167,6 +170,7 @@ namespace io fmt.fill = a.value[0]; fmt.space = a.value[1]; fmt.newline = a.value[2]; + fmt.firstline = a.value[3]; return os; } @@ -270,7 +274,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) { @@ -413,7 +418,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) { From f871bd1928eb14fc51789f31645dc82b3fe22588 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Fri, 26 Jan 2024 15:02:47 +0100 Subject: [PATCH 8/9] reset and compressed util functions --- glm/gtx/io.hpp | 5 +++++ glm/gtx/io.inl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 8f556ed28..cee963b94 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -166,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 diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 51002ab6b..13ed2fc3b 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -116,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)); @@ -136,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) { From c9cf761f4d6216a5ae658a65b0009d1654547969 Mon Sep 17 00:00:00 2001 From: "diego.mateos" Date: Thu, 15 Feb 2024 10:14:56 +0100 Subject: [PATCH 9/9] Added C++17 [[nodiscard]] support #1252 Avoid merge conflicts --- glm/gtx/io.hpp | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index cee963b94..ffeb453fe 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -70,8 +70,8 @@ namespace glm 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 > @@ -79,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: @@ -108,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: @@ -125,14 +125,14 @@ namespace glm { unsigned value; - GLM_FUNC_DECL explicit precision(unsigned = 3); + GLM_FUNC_DISCARD_DECL explicit precision(unsigned = 3); }; struct width { unsigned value; - GLM_FUNC_DECL explicit width(unsigned = 8); + GLM_FUNC_DISCARD_DECL explicit width(unsigned = 8); }; template @@ -140,21 +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_DECL explicit filler(CTy /* fill */ = ' ', CTy /* space */ = ' ', CTy /* newline */ = '\n', CTy /* firstline */ = '\n'); + 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 = column_major); + GLM_FUNC_DISCARD_DECL explicit order(order_type = column_major); }; // functions, inlined (inline) @@ -184,36 +184,36 @@ namespace glm }//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&); /// @}