colour: add type_name specialisation
This commit is contained in:
parent
bc8cac0e1e
commit
94ef217778
30
colour.cpp
30
colour.cpp
@ -440,14 +440,38 @@ util::operator>> (std::istream &is, util::colour<S,T> &c)
|
|||||||
template std::istream& util::operator>> (std::istream&, util::colour<3,uint8_t>&);
|
template std::istream& util::operator>> (std::istream&, util::colour<3,uint8_t>&);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INSTANTIATE_S_T(S,T) \
|
// we need to instantiate the various type_name specialisations for colour.
|
||||||
template struct util::colour<S,T>; \
|
//
|
||||||
template std::ostream& util::operator<< (std::ostream&, util::colour<S,T>);
|
// we provide a declaration here, before then instantiating a routine that we
|
||||||
|
// know will cause an implicit instantiation (ie util::to_string) for each
|
||||||
|
// colour specialisation we require.
|
||||||
|
template <size_t S, typename T>
|
||||||
|
constexpr
|
||||||
|
const char util::type_name<colour<S,T>>::value[];
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#define INSTANTIATE_S_T(S,T) \
|
||||||
|
template \
|
||||||
|
struct util::colour<S,T>; \
|
||||||
|
\
|
||||||
|
template \
|
||||||
|
std::ostream& \
|
||||||
|
util::operator<< (std::ostream&, util::colour<S,T>); \
|
||||||
|
\
|
||||||
|
template \
|
||||||
|
const char* \
|
||||||
|
util::to_string<util::colour<S,T>> (void);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
#define INSTANTIATE_S(S) \
|
#define INSTANTIATE_S(S) \
|
||||||
INSTANTIATE_S_T(S,uint8_t) \
|
INSTANTIATE_S_T(S,uint8_t) \
|
||||||
INSTANTIATE_S_T(S,float) \
|
INSTANTIATE_S_T(S,float) \
|
||||||
INSTANTIATE_S_T(S,double)
|
INSTANTIATE_S_T(S,double)
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
INSTANTIATE_S(1)
|
||||||
INSTANTIATE_S(3)
|
INSTANTIATE_S(3)
|
||||||
INSTANTIATE_S(4)
|
INSTANTIATE_S(4)
|
||||||
|
17
colour.hpp
17
colour.hpp
@ -18,6 +18,7 @@
|
|||||||
#define __UTIL_COLOUR_HPP
|
#define __UTIL_COLOUR_HPP
|
||||||
|
|
||||||
#include "coord.hpp"
|
#include "coord.hpp"
|
||||||
|
#include "introspection.hpp"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ namespace util {
|
|||||||
template <typename T> using colour3 = colour<3,T>;
|
template <typename T> using colour3 = colour<3,T>;
|
||||||
template <typename T> using colour4 = colour<4,T>;
|
template <typename T> using colour4 = colour<4,T>;
|
||||||
|
|
||||||
|
typedef colour3<uint8_t> colour1u;
|
||||||
typedef colour3<uint8_t> colour3u;
|
typedef colour3<uint8_t> colour3u;
|
||||||
typedef colour4<uint8_t> colour4u;
|
typedef colour4<uint8_t> colour4u;
|
||||||
|
|
||||||
@ -55,15 +57,24 @@ namespace util {
|
|||||||
typedef colour3<float> colour3f;
|
typedef colour3<float> colour3f;
|
||||||
typedef colour4<float> colour4f;
|
typedef colour4<float> colour4f;
|
||||||
|
|
||||||
// RGB <-> HSV
|
// RGB/HSV conversions
|
||||||
colour3f rgb_to_hsv (colour3f);
|
colour3f rgb_to_hsv (colour3f);
|
||||||
colour3f hsv_to_rgb (colour3f);
|
colour3f hsv_to_rgb (colour3f);
|
||||||
|
|
||||||
|
// ostream/istream operators
|
||||||
template <size_t S, typename T>
|
template <size_t S, typename T>
|
||||||
std::ostream& operator<< (std::ostream&, util::colour<S,T>);
|
std::ostream&
|
||||||
|
operator<< (std::ostream&, util::colour<S,T>);
|
||||||
|
|
||||||
template <size_t S, typename T>
|
template <size_t S, typename T>
|
||||||
std::istream& operator>> (std::istream&, util::colour<S,T>&);
|
std::istream&
|
||||||
|
operator>> (std::istream&, util::colour<S,T>&);
|
||||||
|
|
||||||
|
// type name introspection specialisation
|
||||||
|
template <size_t S, typename T>
|
||||||
|
struct type_name<colour<S,T>> {
|
||||||
|
static constexpr const char value[] = "colour";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "colour.ipp"
|
#include "colour.ipp"
|
||||||
|
Loading…
Reference in New Issue
Block a user