Use GLM coding convensions

master
Christophe Riccio ago%!(EXTRA string=9 years)
parent e913a9c68b
commit a6b3632257
  1. 695
      glm/gtx/io.inl

@ -38,306 +38,309 @@
namespace glm{ namespace glm{
namespace io namespace io
{ {
template <typename CTy> template <typename CTy>
/* explicit */ GLM_FUNC_QUALIFIER GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(size_t a)
format_punct<CTy>::format_punct(size_t a) : std::locale::facet(a)
: std::locale::facet(a), , formatted(true)
formatted (true), , precision(3)
precision (3), , width(1 + 4 + 1 + precision)
width (1 + 4 + 1 + precision), , separator(',')
separator (','), , delim_left('[')
delim_left ('['), , delim_right(']')
delim_right (']'), , space(' ')
space (' '), , newline('\n')
newline ('\n'), , order(column_major)
order (column_major) {}
{}
template <typename CTy>
template <typename CTy> GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(format_punct const& a)
/* explicit */ GLM_FUNC_QUALIFIER : std::locale::facet(0)
format_punct<CTy>::format_punct(format_punct const& a) , formatted(a.formatted)
: std::locale::facet(0), , precision(a.precision)
formatted (a.formatted), , width(a.width)
precision (a.precision), , separator(a.separator)
width (a.width), , delim_left(a.delim_left)
separator (a.separator), , delim_right(a.delim_right)
delim_left (a.delim_left), , space(a.space)
delim_right (a.delim_right), , newline(a.newline)
space (a.space), , order(a.order)
newline (a.newline), {}
order (a.order)
{} template <typename CTy> std::locale::id format_punct<CTy>::id;
template <typename CTy> std::locale::id format_punct<CTy>::id; template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::basic_state_saver(std::basic_ios<CTy, CTr>& a)
template <typename CTy, typename CTr> : state_(a)
/* explicit */ GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::basic_state_saver(std::basic_ios<CTy,CTr>& a) , flags_(a.flags())
: state_ (a), , precision_(a.precision())
flags_ (a.flags()), , width_(a.width())
precision_(a.precision()), , fill_(a.fill())
width_ (a.width()), , locale_(a.getloc())
fill_ (a.fill()), {}
locale_ (a.getloc())
{} template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::~basic_state_saver()
template <typename CTy, typename CTr> {
GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::~basic_state_saver() state_.imbue(locale_);
{ state_.fill(fill_);
state_.imbue(locale_); state_.width(width_);
state_.fill(fill_); state_.precision(precision_);
state_.width(width_); state_.flags(flags_);
state_.precision(precision_); }
state_.flags(flags_);
} template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_format_saver<CTy, CTr>::basic_format_saver(std::basic_ios<CTy, CTr>& a)
template <typename CTy, typename CTr> : bss_(a)
/* explicit */ GLM_FUNC_QUALIFIER basic_format_saver<CTy,CTr>::basic_format_saver(std::basic_ios<CTy,CTr>& a) {
: bss_(a) a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
{ }
a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
} template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER
template <typename CTy, typename CTr> basic_format_saver<CTy, CTr>::~basic_format_saver()
GLM_FUNC_QUALIFIER {}
basic_format_saver<CTy,CTr>::~basic_format_saver()
{} GLM_FUNC_QUALIFIER precision::precision(unsigned a)
: value(a)
/* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a) {}
: value(a)
{} GLM_FUNC_QUALIFIER width::width(unsigned a)
: value(a)
/* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a) {}
: value(a)
{} template <typename CTy>
GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
template <typename CTy> : value()
/* explicit */ GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c) {
: value() value[0] = a;
{ value[1] = b;
value[0] = a; value[2] = c;
value[1] = b; }
value[2] = c;
} GLM_FUNC_QUALIFIER order::order(order_type a)
: value(a)
/* explicit */ GLM_FUNC_QUALIFIER order::order(order_type a) {}
: value(a)
{} template <typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
template <typename FTy, typename CTy, typename CTr> {
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy,CTr>& ios) if(!std::has_facet<FTy>(ios.getloc()))
{ ios.imbue(std::locale(ios.getloc(), new FTy));
if (!std::has_facet<FTy>(ios.getloc())) {
ios.imbue(std::locale(ios.getloc(), new FTy)); return std::use_facet<FTy>(ios.getloc());
} }
return std::use_facet<FTy>(ios.getloc()); template <typename CTy, typename CTr>
} GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& formatted(std::basic_ios<CTy, CTr>& ios)
{
template <typename CTy, typename CTr> const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>& ios) return ios;
{ }
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
template <typename CTy, typename CTr>
return ios; GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& unformatted(std::basic_ios<CTy, CTr>& ios)
} {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
template <typename CTy, typename CTr> return ios;
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& unformatted(std::basic_ios<CTy,CTr>& ios) }
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false; template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
return ios; {
} const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
return os;
template <typename CTy, typename CTr> }
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
{ template <typename CTy, typename CTr>
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value; GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
{
return os; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
} return os;
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a) template <typename CTy, typename CTr>
{ GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a)
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value; {
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)));
return os;
} fmt.delim_left = a.value[0];
fmt.delim_right = a.value[1];
template <typename CTy, typename CTr> fmt.separator = a.value[2];
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a)
{ return os;
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os))); }
fmt.delim_left = a.value[0]; template <typename CTy, typename CTr>
fmt.delim_right = a.value[1]; GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a)
fmt.separator = a.value[2]; {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os; return os;
} }
} // namespace io
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a) namespace detail
{ {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value; template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
return os; print_vector_on(std::basic_ostream<CTy, CTr>& os, V<T,P> const& a)
} {
} // namespace io typename std::basic_ostream<CTy, CTr>::sentry const cerberus(os);
namespace detail { if(cerberus)
{
template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P> io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
print_vector_on(std::basic_ostream<CTy,CTr>& os, V<T,P> const& a) length_t const& components(type<V, T, P>::components);
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os); if(fmt.formatted)
{
if(cerberus) io::basic_state_saver<CTy> const bss(os);
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os)); os << std::fixed << std::right << std::setprecision(fmt.precision) << std::setfill(fmt.space) << fmt.delim_left;
length_t const& components(type<V, T, P>::components); for(length_t i(0); i < components; ++i)
{
if(fmt.formatted) os << std::setw(fmt.width) << a[i];
{ if(components-1 != i)
io::basic_state_saver<CTy> const bss(os); os << fmt.separator;
}
os << std::fixed
<< std::right os << fmt.delim_right;
<< std::setprecision(fmt.precision) }
<< std::setfill(fmt.space) else
<< fmt.delim_left; {
for(length_t i(0); i < components; ++i)
for (length_t i(0); i < components; ++i) { {
os << std::setw(fmt.width) << a[i]; os << a[i];
if (components-1 != i) { os << fmt.separator; } if(components-1 != i)
} os << fmt.space;
}
os << fmt.delim_right; }
} }
else
{ return os;
for (length_t i(0); i < components; ++i) { }
os << a[i]; }//namespace detail
if (components-1 != i) { os << fmt.space; }
}
}
}
return os;
}
}
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
{ {
return detail::print_vector_on(os, a); return detail::print_vector_on(os, a);
} }
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec1<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec1<T,P> const& a)
{ {
return detail::print_vector_on(os, a); return detail::print_vector_on(os, a);
} }
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a)
{ {
return detail::print_vector_on(os, a); return detail::print_vector_on(os, a);
} }
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a)
{ {
return detail::print_vector_on(os, a); return detail::print_vector_on(os, a);
} }
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a)
{ {
return detail::print_vector_on(os, a); return detail::print_vector_on(os, a);
} }
namespace detail { namespace detail
{
template <typename CTy, typename CTr, template <typename, precision> class M, typename T, precision P> template <typename CTy, typename CTr, template <typename, precision> class M, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
print_matrix_on(std::basic_ostream<CTy,CTr>& os, M<T,P> const& a) print_matrix_on(std::basic_ostream<CTy, CTr>& os, M<T,P> const& a)
{ {
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os); typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus) if(cerberus)
{ {
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os)); io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
length_t const& cols(type<M, T, P>::cols); length_t const& cols(type<M, T, P>::cols);
length_t const& rows(type<M, T, P>::rows); length_t const& rows(type<M, T, P>::rows);
if(fmt.formatted) { if(fmt.formatted)
os << fmt.newline {
<< fmt.delim_left; os << fmt.newline << fmt.delim_left;
switch (fmt.order) { switch(fmt.order)
case io::column_major: {
{ case io::column_major:
for (length_t i(0); i < rows; ++i) { {
if (0 != i) { os << fmt.space; } for(length_t i(0); i < rows; ++i)
{
os << row(a, i); if (0 != i)
os << fmt.space;
if (rows-1 != i) { os << fmt.newline; }
} os << row(a, i);
}
break; if(rows-1 != i)
os << fmt.newline;
case io::row_major: }
{ }
for (length_t i(0); i < cols; ++i) { break;
if (0 != i) { os << fmt.space; }
case io::row_major:
os << column(a, i); {
for(length_t i(0); i < cols; ++i)
if (cols-1 != i) { os << fmt.newline; } {
} if(0 != i)
} os << fmt.space;
break;
} os << column(a, i);
os << fmt.delim_right; if(cols-1 != i)
} else { os << fmt.newline;
switch (fmt.order) { }
case io::column_major: }
{ break;
for (length_t i(0); i < cols; ++i) { }
os << column(a, i);
os << fmt.delim_right;
if (cols-1 != i) { os << fmt.space; } }
} else
} {
break; switch (fmt.order)
{
case io::row_major: case io::column_major:
{ {
for (length_t i(0); i < rows; ++i) { for(length_t i(0); i < cols; ++i)
os << row(a, i); {
os << column(a, i);
if (rows-1 != i) { os << fmt.space; }
} if(cols - 1 != i)
} os << fmt.space;
break; }
} }
} break;
}
case io::row_major:
return os; {
} for (length_t i(0); i < rows; ++i)
{
} os << row(a, i);
if (rows-1 != i)
os << fmt.space;
}
}
break;
}
}
}
return os;
}
}//namespace detail
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& a) GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& a)
@ -393,74 +396,76 @@ namespace io
return detail::print_matrix_on(os, a); return detail::print_matrix_on(os, a);
} }
namespace detail { namespace detail
{
template <typename CTy, typename CTr, template <typename, precision> class M, typename T, precision P> template <typename CTy, typename CTr, template <typename, precision> class M, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
print_matrix_pair_on(std::basic_ostream<CTy,CTr>& os, std::pair<M<T,P> const, M<T,P> const> const& a) print_matrix_pair_on(std::basic_ostream<CTy, CTr>& os, std::pair<M<T, P> const, M<T, P> const> const& a)
{ {
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os); typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus) if(cerberus)
{ {
io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os)); io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
M<T,P> const& ml(a.first); M<T,P> const& ml(a.first);
M<T,P> const& mr(a.second); M<T,P> const& mr(a.second);
length_t const& cols(type<M, T, P>::cols); length_t const& cols(type<M, T, P>::cols);
length_t const& rows(type<M, T, P>::rows); length_t const& rows(type<M, T, P>::rows);
if(fmt.formatted) { if(fmt.formatted)
os << fmt.newline {
<< fmt.delim_left; os << fmt.newline << fmt.delim_left;
switch (fmt.order) { switch(fmt.order)
case io::column_major: {
{ case io::column_major:
for (length_t i(0); i < rows; ++i) { {
if (0 != i) { os << fmt.space; } for(length_t i(0); i < rows; ++i)
{
os << row(ml, i) if(0 != i)
<< ((rows-1 != i) ? fmt.space : fmt.delim_right) os << fmt.space;
<< fmt.space
<< ((0 != i) ? fmt.space : fmt.delim_left) os << row(ml, i) << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, i);
<< row(mr, i);
if(rows-1 != i)
if (rows-1 != i) { os << fmt.newline; } os << fmt.newline;
} }
} }
break; break;
case io::row_major:
case io::row_major: {
{ for(length_t i(0); i < cols; ++i)
for (length_t i(0); i < cols; ++i) { {
if (0 != i) { os << fmt.space; } if(0 != i)
os << fmt.space;
os << column(ml, i)
<< ((cols-1 != i) ? fmt.space : fmt.delim_right) os << column(ml, i) << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, i);
<< fmt.space
<< ((0 != i) ? fmt.space : fmt.delim_left) if(cols-1 != i)
<< column(mr, i); os << fmt.newline;
}
if (cols-1 != i) { os << fmt.newline; } }
} break;
} }
break;
} os << fmt.delim_right;
}
os << fmt.delim_right; else
} else { {
os << ml << fmt.space << mr; os << ml << fmt.space << mr;
} }
} }
return os; return os;
} }
} }//namespace detail
template <typename CTy, typename CTr, typename T, precision P> template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr> & os, GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(
std::pair<tmat4x4<T,P> const, tmat4x4<T,P> const> const& a) std::basic_ostream<CTy, CTr> & os,
std::pair<tmat4x4<T, P> const,
tmat4x4<T, P> const> const& a)
{ {
return detail::print_matrix_pair_on(os, a); return detail::print_matrix_pair_on(os, a);
} }
}//namespace glm }//namespace glm

Loading…
Cancel
Save