Skip to content

Commit

Permalink
reset and compressed util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dimateos committed Jan 26, 2024
1 parent 916bc04 commit f871bd1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions glm/gtx/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ namespace glm
template<typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& unformatted(std::basic_ios<CTy,CTr>&);

template<typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& reset(std::basic_ios<CTy,CTr>&);
template<typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& compressed(std::basic_ios<CTy,CTr>&);

template<typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
template<typename CTy, typename CTr>
Expand Down
39 changes: 39 additions & 0 deletions glm/gtx/io.inl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace io
template<typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
{
// Destruction handled by locale (0 passed as default argument in the constructor)
if(!std::has_facet<FTy>(ios.getloc()))
ios.imbue(std::locale(ios.getloc(), new FTy));

Expand All @@ -136,6 +137,44 @@ namespace io
return ios;
}

template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& reset(std::basic_ios<CTy, CTr>& ios)
{
// could leverage on the default constructor, but requires additional memory allocation
//ios.imbue(std::locale(ios.getloc(), new format_punct<CTy>));
//return ios;

format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(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<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& compressed(std::basic_ios<CTy, CTr>& ios)
{
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)));

fmt.formatted = true;
fmt.width = 0;
//fmt.space = ' ';
fmt.newline = ',';
fmt.firstline = '\0';

return ios;
}

template<typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
{
Expand Down

0 comments on commit f871bd1

Please sign in to comment.