colour: add generic ostream operators
This commit is contained in:
parent
7c33efda62
commit
0d1fb0147e
25
colour.cpp
25
colour.cpp
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "range.hpp"
|
#include "range.hpp"
|
||||||
#include "random.hpp"
|
#include "random.hpp"
|
||||||
|
#include "stream.hpp"
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -87,15 +88,25 @@ namespace util {
|
|||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
template <size_t S, typename T>
|
||||||
std::ostream&
|
std::ostream&
|
||||||
util::operator<< (std::ostream &os, const util::colour4f &c) {
|
util::operator<< (std::ostream &os, util::colour<S,T> c) {
|
||||||
os << "colour(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
|
os << "colour(";
|
||||||
|
for (size_t i = 0; i < S - 1; ++i)
|
||||||
|
os << stream::numeric<T> (c[i]) << ", ";
|
||||||
|
os << stream::numeric<T> (c[S-1]) << ")";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template struct util::colour<3,float>;
|
#define INSTANTIATE_S_T(S,T) \
|
||||||
template struct util::colour<3,double>;
|
template struct util::colour<S,T>; \
|
||||||
template struct util::colour<4,float>;
|
template std::ostream& util::operator<< (std::ostream&, util::colour<S,T>);
|
||||||
template struct util::colour<4,double>;
|
|
||||||
|
#define INSTANTIATE_S(S) \
|
||||||
|
INSTANTIATE_S_T(S,uint8_t) \
|
||||||
|
INSTANTIATE_S_T(S,float) \
|
||||||
|
INSTANTIATE_S_T(S,double)
|
||||||
|
|
||||||
|
INSTANTIATE_S(3)
|
||||||
|
INSTANTIATE_S(4)
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
namespace util {
|
namespace util {
|
||||||
/// An RGBA colour POD type.
|
/// An RGBA colour POD type.
|
||||||
template <size_t S, typename T>
|
template <size_t S, typename T>
|
||||||
struct colour : public coord::base<S,T,colour,coord::rgba>
|
struct colour : public coord::base<S,T,colour,coord::rgba> {
|
||||||
{
|
|
||||||
using coord::base<S,T,util::colour,coord::rgba>::base;
|
using coord::base<S,T,util::colour,coord::rgba>::base;
|
||||||
|
|
||||||
static const colour WHITE;
|
static const colour WHITE;
|
||||||
@ -45,7 +44,9 @@ namespace util {
|
|||||||
|
|
||||||
// Serialisation
|
// Serialisation
|
||||||
const json::tree::node& operator>> (const json::tree::node&, util::colour4f&);
|
const json::tree::node& operator>> (const json::tree::node&, util::colour4f&);
|
||||||
std::ostream& operator<< (std::ostream&, const util::colour4f&);
|
|
||||||
|
template <size_t S, typename T>
|
||||||
|
std::ostream& operator<< (std::ostream&, util::colour<S,T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user