P
Pierre Yves
Hi there,
Template, once again... Nice topic but a bit tricky to code.
My problem is the following:
I have to video parser which retrieve image frames. The pixel values can
be unsigned char (8 bit) or unsigned short (16 bit).
I've got a templated frame:
template <class T>
class Frame {
Frame(int height, int width) {
data = new T[height * width]
}
T * data;
}
I've got my readers:
class Video16bit : public Frame<unsigned char> {
Video16bit : Frame(20,20) {
// whatever
}
}
class Video16bit : public Frame<unsigned short> {
Video16bit : Frame(20,20) {
// whatever
}
}
This one seems to compile fine. Everything goes wrong when I try to
process these videos.
I would like to create a class which can take either of the videos but I
got lost...
class Processor {
public:
Processor();
LoadData(Frame<T> * data);
protected:
Frame<T> * mydata;
}
My main would look like (the two videos should be usable):
int main(void) {
Video16bit * vid = new Video16bit();
// Video8bit * vid = new Video8bit();
Processor * pro = new Processor();
pro->LoadData(vid);
delete whatever is required;
}
The problem is that the creation of my processor depends on the type of
template and ... I dunno how to pass it cleanly. My current solution is
to template the Processor as well. However, I could make a mistake of
type: I would like the T of the processor defined by the loaded video...
Does it make sense?
Another way to see it would be: can I do a
Processor<vid->getType()> * pro = new Processor();
Regards,
PY
Template, once again... Nice topic but a bit tricky to code.
My problem is the following:
I have to video parser which retrieve image frames. The pixel values can
be unsigned char (8 bit) or unsigned short (16 bit).
I've got a templated frame:
template <class T>
class Frame {
Frame(int height, int width) {
data = new T[height * width]
}
T * data;
}
I've got my readers:
class Video16bit : public Frame<unsigned char> {
Video16bit : Frame(20,20) {
// whatever
}
}
class Video16bit : public Frame<unsigned short> {
Video16bit : Frame(20,20) {
// whatever
}
}
This one seems to compile fine. Everything goes wrong when I try to
process these videos.
I would like to create a class which can take either of the videos but I
got lost...
class Processor {
public:
Processor();
LoadData(Frame<T> * data);
protected:
Frame<T> * mydata;
}
My main would look like (the two videos should be usable):
int main(void) {
Video16bit * vid = new Video16bit();
// Video8bit * vid = new Video8bit();
Processor * pro = new Processor();
pro->LoadData(vid);
delete whatever is required;
}
The problem is that the creation of my processor depends on the type of
template and ... I dunno how to pass it cleanly. My current solution is
to template the Processor as well. However, I could make a mistake of
type: I would like the T of the processor defined by the loaded video...
Does it make sense?
Another way to see it would be: can I do a
Processor<vid->getType()> * pro = new Processor();
Regards,
PY