Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-09-20 11:42:34


From: "Adam Badura" <abadura_at_[hidden]>
>
> For now I think taht template representation would be best. What i mean
> is for example
>
> struct rgb_8888 {
> unsigned char r : 8;
> unsigned char g : 8;
> unsigned char b : 8;
> unsigned char : 8;
> };
>
> struct yuv_422 {
> unsigned char y : 4;
> unsigned char u : 2;
> unsigned char v : 2;
> };
>
> template<typename Components> class color {
> private:
> Components mComponents;
> };

I haven't been following your discussion but this looks suspect.

First, you'd need to specialize color for each color structure
type so the color member functions know how to do the right
thing. That obviates what I think you're trying to do with the
template.

Second, all code using colors must be either templated on color
type or will only work with one type. That is, including the
representation in the type (color<yuv_422>) means that functions
must be written in terms of color<something> and can't work with
color<something_else_entirely>.

To fix the former problem, you might consider that the color
template can provide higher level functionality from primitives
supplied by a policy type. Thus, your Components type would have
to provide represention plus primitives.

To fix the latter problem, you would need an ABC from which
color<T> derives.

HTH

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk