Use GLM coding convensions

This commit is contained in:
Christophe Riccio 2016-04-30 14:59:56 +02:00
parent e913a9c68b
commit a6b3632257

View File

@ -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>
/* explicit */ GLM_FUNC_QUALIFIER GLM_FUNC_QUALIFIER format_punct<CTy>::format_punct(format_punct const& a)
format_punct<CTy>::format_punct(format_punct const& a) : std::locale::facet(0)
: std::locale::facet(0), , formatted(a.formatted)
formatted (a.formatted), , precision(a.precision)
precision (a.precision), , width(a.width)
width (a.width), , separator(a.separator)
separator (a.separator), , delim_left(a.delim_left)
delim_left (a.delim_left), , delim_right(a.delim_right)
delim_right (a.delim_right), , space(a.space)
space (a.space), , newline(a.newline)
newline (a.newline), , order(a.order)
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> template <typename CTy, typename CTr>
/* explicit */ GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::basic_state_saver(std::basic_ios<CTy,CTr>& a) GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::basic_state_saver(std::basic_ios<CTy, CTr>& a)
: state_ (a), : state_(a)
flags_ (a.flags()), , flags_(a.flags())
precision_(a.precision()), , precision_(a.precision())
width_ (a.width()), , width_(a.width())
fill_ (a.fill()), , fill_(a.fill())
locale_ (a.getloc()) , locale_(a.getloc())
{} {}
template <typename CTy, typename CTr> template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::~basic_state_saver() GLM_FUNC_QUALIFIER basic_state_saver<CTy, CTr>::~basic_state_saver()
{ {
state_.imbue(locale_); state_.imbue(locale_);
state_.fill(fill_); state_.fill(fill_);
state_.width(width_); state_.width(width_);
state_.precision(precision_); state_.precision(precision_);
state_.flags(flags_); state_.flags(flags_);
} }
template <typename CTy, typename CTr> template <typename CTy, typename CTr>
/* explicit */ GLM_FUNC_QUALIFIER basic_format_saver<CTy,CTr>::basic_format_saver(std::basic_ios<CTy,CTr>& a) GLM_FUNC_QUALIFIER basic_format_saver<CTy, CTr>::basic_format_saver(std::basic_ios<CTy, CTr>& a)
: bss_(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> template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER GLM_FUNC_QUALIFIER
basic_format_saver<CTy,CTr>::~basic_format_saver() basic_format_saver<CTy, CTr>::~basic_format_saver()
{} {}
/* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a) GLM_FUNC_QUALIFIER precision::precision(unsigned a)
: value(a) : value(a)
{} {}
/* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a) GLM_FUNC_QUALIFIER width::width(unsigned a)
: value(a) : value(a)
{} {}
template <typename CTy> template <typename CTy>
/* explicit */ GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c) GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
: value() : value()
{ {
value[0] = a; value[0] = a;
value[1] = b; value[1] = b;
value[2] = c; value[2] = c;
} }
/* explicit */ GLM_FUNC_QUALIFIER order::order(order_type a) GLM_FUNC_QUALIFIER order::order(order_type a)
: value(a) : value(a)
{} {}
template <typename FTy, typename CTy, typename CTr> template <typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy,CTr>& ios) GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy, CTr>& ios)
{ {
if (!std::has_facet<FTy>(ios.getloc())) { if(!std::has_facet<FTy>(ios.getloc()))
ios.imbue(std::locale(ios.getloc(), new FTy)); 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> template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>& ios) GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& formatted(std::basic_ios<CTy, CTr>& ios)
{ {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
return ios;
}
return ios; template <typename CTy, typename CTr>
} 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;
return ios;
}
template <typename CTy, typename CTr> template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& unformatted(std::basic_ios<CTy,CTr>& ios) GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
{ {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
return os;
}
return ios; template <typename CTy, typename CTr>
} GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
return os;
}
template <typename CTy, typename CTr> template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a) 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)).precision = 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];
fmt.separator = a.value[2];
template <typename CTy, typename CTr> return os;
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a) }
{
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, order const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os;
}
} // namespace io
template <typename CTy, typename CTr> namespace detail
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a) {
{ template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P>
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<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)
{
typename std::basic_ostream<CTy, CTr>::sentry const cerberus(os);
fmt.delim_left = a.value[0]; if(cerberus)
fmt.delim_right = a.value[1]; {
fmt.separator = a.value[2]; io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
return os; length_t const& components(type<V, T, P>::components);
}
template <typename CTy, typename CTr> if(fmt.formatted)
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a) {
{ io::basic_state_saver<CTy> const bss(os);
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os; os << std::fixed << std::right << std::setprecision(fmt.precision) << std::setfill(fmt.space) << fmt.delim_left;
}
} // namespace io
namespace detail { for(length_t i(0); i < components; ++i)
{
os << std::setw(fmt.width) << a[i];
if(components-1 != i)
os << fmt.separator;
}
template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P> os << fmt.delim_right;
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& }
print_vector_on(std::basic_ostream<CTy,CTr>& os, V<T,P> const& a) else
{ {
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os); for(length_t i(0); i < components; ++i)
{
os << a[i];
if(cerberus) if(components-1 != i)
{ os << fmt.space;
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os)); }
}
}
length_t const& components(type<V, T, P>::components); return os;
}
if(fmt.formatted) }//namespace detail
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< fmt.delim_left;
for (length_t i(0); i < components; ++i) {
os << std::setw(fmt.width) << a[i];
if (components-1 != i) { os << fmt.separator; }
}
os << fmt.delim_right;
}
else
{
for (length_t i(0); i < components; ++i) {
os << a[i];
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>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
print_matrix_on(std::basic_ostream<CTy, CTr>& os, M<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
template <typename CTy, typename CTr, template <typename, precision> class M, typename T, precision P> if(cerberus)
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& {
print_matrix_on(std::basic_ostream<CTy,CTr>& os, M<T,P> const& a) io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus) length_t const& cols(type<M, T, P>::cols);
{ length_t const& rows(type<M, T, P>::rows);
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
length_t const& cols(type<M, T, P>::cols); if(fmt.formatted)
length_t const& rows(type<M, T, P>::rows); {
os << fmt.newline << fmt.delim_left;
if(fmt.formatted) {
os << fmt.newline
<< fmt.delim_left;
switch (fmt.order) {
case io::column_major:
{
for (length_t i(0); i < rows; ++i) {
if (0 != i) { os << fmt.space; }
os << row(a, i); switch(fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < rows; ++i)
{
if (0 != i)
os << fmt.space;
if (rows-1 != i) { os << fmt.newline; } os << row(a, i);
}
}
break;
case io::row_major: if(rows-1 != i)
{ os << fmt.newline;
for (length_t i(0); i < cols; ++i) { }
if (0 != i) { os << fmt.space; } }
break;
os << column(a, i);
if (cols-1 != i) { os << fmt.newline; } case io::row_major:
} {
} for(length_t i(0); i < cols; ++i)
break; {
} if(0 != i)
os << fmt.space;
os << fmt.delim_right; os << column(a, i);
} else {
switch (fmt.order) {
case io::column_major:
{
for (length_t i(0); i < cols; ++i) {
os << column(a, i);
if (cols-1 != i) { os << fmt.space; } if(cols-1 != i)
} os << fmt.newline;
} }
break; }
break;
}
case io::row_major: os << fmt.delim_right;
{ }
for (length_t i(0); i < rows; ++i) { else
os << row(a, i); {
switch (fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < cols; ++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);
if(cerberus)
{
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& mr(a.second);
length_t const& cols(type<M, T, P>::cols);
length_t const& rows(type<M, T, P>::rows);
if(fmt.formatted) {
os << fmt.newline
<< fmt.delim_left;
switch (fmt.order) {
case io::column_major:
{
for (length_t i(0); i < rows; ++i) {
if (0 != i) { os << fmt.space; }
os << row(ml, i)
<< ((rows-1 != i) ? fmt.space : fmt.delim_right)
<< fmt.space
<< ((0 != i) ? fmt.space : fmt.delim_left)
<< row(mr, i);
if (rows-1 != i) { os << fmt.newline; }
}
}
break;
case io::row_major:
{
for (length_t i(0); i < cols; ++i) {
if (0 != i) { os << fmt.space; }
os << column(ml, i)
<< ((cols-1 != i) ? fmt.space : fmt.delim_right)
<< fmt.space
<< ((0 != i) ? fmt.space : fmt.delim_left)
<< column(mr, i);
if (cols-1 != i) { os << fmt.newline; }
}
}
break;
}
os << fmt.delim_right;
} else {
os << ml << fmt.space << mr;
}
}
return os;
}
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(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); typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
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& mr(a.second);
length_t const& cols(type<M, T, P>::cols);
length_t const& rows(type<M, T, P>::rows);
if(fmt.formatted)
{
os << fmt.newline << fmt.delim_left;
switch(fmt.order)
{
case io::column_major:
{
for(length_t i(0); i < rows; ++i)
{
if(0 != i)
os << fmt.space;
os << row(ml, i) << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, i);
if(rows-1 != i)
os << fmt.newline;
}
}
break;
case io::row_major:
{
for(length_t i(0); i < cols; ++i)
{
if(0 != i)
os << fmt.space;
os << column(ml, i) << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, i);
if(cols-1 != i)
os << fmt.newline;
}
}
break;
}
os << fmt.delim_right;
}
else
{
os << ml << fmt.space << mr;
}
}
return os;
}
}//namespace detail
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(
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);
} }
}//namespace glm }//namespace glm