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

@ -39,45 +39,43 @@ 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>
@ -91,7 +89,7 @@ namespace io
} }
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))));
@ -102,16 +100,16 @@ namespace io
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;
@ -119,16 +117,15 @@ namespace io
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());
} }
@ -137,7 +134,6 @@ namespace io
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;
} }
@ -145,7 +141,6 @@ namespace io
GLM_FUNC_QUALIFIER std::basic_ios<CTy, CTr>& unformatted(std::basic_ios<CTy, CTr>& 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; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
return ios; return ios;
} }
@ -153,7 +148,6 @@ namespace io
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, precision const& a)
{ {
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
return os; return os;
} }
@ -161,7 +155,6 @@ namespace io
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a) 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; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
return os; return os;
} }
@ -181,13 +174,12 @@ namespace io
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a) 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; const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os; return os;
} }
} // namespace io } // namespace io
namespace detail { namespace detail
{
template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P> template <typename CTy, typename CTr, template <typename, precision> class V, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
print_vector_on(std::basic_ostream<CTy, CTr>& os, V<T,P> const& a) print_vector_on(std::basic_ostream<CTy, CTr>& os, V<T,P> const& a)
@ -204,34 +196,32 @@ namespace io
{ {
io::basic_state_saver<CTy> const bss(os); io::basic_state_saver<CTy> const bss(os);
os << std::fixed os << std::fixed << std::right << std::setprecision(fmt.precision) << std::setfill(fmt.space) << fmt.delim_left;
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< 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 << std::setw(fmt.width) << a[i];
if(components-1 != i)
if (components-1 != i) { os << fmt.separator; } os << fmt.separator;
} }
os << fmt.delim_right; os << fmt.delim_right;
} }
else else
{ {
for (length_t i(0); i < components; ++i) { for(length_t i(0); i < components; ++i)
{
os << a[i]; os << a[i];
if (components-1 != i) { os << fmt.space; } if(components-1 != i)
os << fmt.space;
} }
} }
} }
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, 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)
@ -263,8 +253,8 @@ namespace io
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)
@ -278,55 +268,69 @@ namespace io
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) { for(length_t i(0); i < rows; ++i)
if (0 != i) { os << fmt.space; } {
if (0 != i)
os << fmt.space;
os << row(a, i); os << row(a, i);
if (rows-1 != i) { os << fmt.newline; } if(rows-1 != i)
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(a, i); os << column(a, i);
if (cols-1 != i) { os << fmt.newline; } if(cols-1 != i)
os << fmt.newline;
} }
} }
break; break;
} }
os << fmt.delim_right; os << fmt.delim_right;
} else { }
switch (fmt.order) { else
{
switch (fmt.order)
{
case io::column_major: case io::column_major:
{ {
for (length_t i(0); i < cols; ++i) { for(length_t i(0); i < cols; ++i)
{
os << column(a, i); os << column(a, i);
if (cols-1 != i) { os << fmt.space; } if(cols - 1 != i)
os << fmt.space;
} }
} }
break; break;
case io::row_major: case io::row_major:
{ {
for (length_t i(0); i < rows; ++i) { for (length_t i(0); i < rows; ++i)
{
os << row(a, i); os << row(a, i);
if (rows-1 != i) { os << fmt.space; } if (rows-1 != i)
os << fmt.space;
} }
} }
break; break;
@ -336,8 +340,7 @@ namespace io
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, 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,8 +396,8 @@ 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)
@ -409,57 +412,59 @@ namespace io
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) { for(length_t i(0); i < rows; ++i)
if (0 != i) { os << fmt.space; } {
if(0 != i)
os << fmt.space;
os << row(ml, i) os << row(ml, i) << ((rows-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << row(mr, 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; } if(rows-1 != i)
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) os << column(ml, i) << ((cols-1 != i) ? fmt.space : fmt.delim_right) << fmt.space << ((0 != i) ? fmt.space : fmt.delim_left) << column(mr, 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; } 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);
} }