C
Code4u
I need to design data storage classes and operators for an image
processing system that must support a range of basic data types of
different lengths i.e. float, int, char, double. I have a template
class that stores the data. The problem with this design is the
inability to treat image data generically- I have a set of specialized
classes with no connection. I'm considering deriving all ImageData<T>
classes from a image data abstract base class with virtual methods for
operations where possible. ImageData methods would then be called on
the base class and be implemented in the specialized template. The
code gets a little ugly when implementing operations with two image
data operands, i.e.
ImageDataBase& operator+(const ImageDataBase& r1, const ImageDataBase&
r2)
In this function I would need to write code to check for all the legal
operand types, using dynamic_cast, and then peform the calculation and
create the result ImageData or throw an exception.
Alternatively I could have an ImageData class that holds a void
pointer and an enum describing the data type.
I'm interested in getting input on the pros and cons of each, also if
there's a better pattern I would like to hear about it.
processing system that must support a range of basic data types of
different lengths i.e. float, int, char, double. I have a template
class that stores the data. The problem with this design is the
inability to treat image data generically- I have a set of specialized
classes with no connection. I'm considering deriving all ImageData<T>
classes from a image data abstract base class with virtual methods for
operations where possible. ImageData methods would then be called on
the base class and be implemented in the specialized template. The
code gets a little ugly when implementing operations with two image
data operands, i.e.
ImageDataBase& operator+(const ImageDataBase& r1, const ImageDataBase&
r2)
In this function I would need to write code to check for all the legal
operand types, using dynamic_cast, and then peform the calculation and
create the result ImageData or throw an exception.
Alternatively I could have an ImageData class that holds a void
pointer and an enum describing the data type.
I'm interested in getting input on the pros and cons of each, also if
there's a better pattern I would like to hear about it.