Check the class of objects

Mael mael.primet at
Thu Jun 5 08:14:11 PDT 2008


another newb question !
I'm trying to design a large image library, that should be usable enough for students to learn it quickly, but powerful enough to be used in medium-sized projects

Since I'm building several image classes (depending on the characteristics of the image, such as grey / color, byte / float, etc), I can either include a flag in each image that tells its class ("I'm a color-byte image", "I'm a grey-byte image", etc.), or use many if( cast(ColorByteImage)img !is null ) { doactionColorByte ; } to check the type. What would be the most efficient way to test the type of the class ? How is the cast(Class)v construct implemented in the compiler (I guess there's some equivalent of a "i'm a color-byte image" flag in the class structure) ?

Another question for people designing graphic libraries : would you recommend to pad image rows on 32-bits ? I hardly see when this is useful in practice (usually it's done for efficiency reasons, but I don't see how this would improve speed significantly, except if you're trying to extract a couple of lines of an image...). The only advantage I see is that it permits to make fast 'ImageViews' of a subset of an Image without having to duplicate it. Maybe some webcams give padded output, and it would therefore be faster to have them output directly in the image ? Someone sees the main reason (I might be missing some thing here?) 

More information about the Digitalmars-d-learn mailing list