Nah ;)
Suppose you wanted to define an "interface" - I think C++ calls them pure
virtual classes.
Well, in that case, work out what functions are required, then create a table
of vectors. In file.C, for example, if it doesn't know the file format, it does
a whole lot of specialised check_sig() calls to see if a class can handle the
format. And it uses switching. I'm suggesting that all this switching is
unecessary. Suppose you thought that the functions that were required were
check_sig(), init(), read_frame(), finalise(). Well, just define a table of
vectors (I don't know the precise syntax):
file_handler_table = {
{filemov_check_sig(), filemov_init(), filemov_read_frame(),
filemov_finalise()},
{fileogg_check_sig(), fileogg_init(), ...}
... }
Then, when you want to determine what format to use, you loop over the table,
using "file_handler" on each of the structs to see if its check_sig() produces
a matche. Once you've got the file handler, the rest is fairly straightforward.
Wanna read a frame? Then type file_handler->read_frame(). Wanna do colour
balancing? file_handler->colourBalance() (except that I hadn't defined it above
- but you get the idea). You can even write a macro that will fill out a lot of
this boilerplate for you, something like:
file_handler_table = { FHT(mov), FHT(ogg), ... }
I've looked at file.C, and it looks vastly bigger than it really needs to be.
It does switching all over the place. I'm suggesting that it if you want OO,
just do it in C.
We'll never agree, of course ;)
----- Original Message ----
From: Martin Ellison <[EMAIL PROTECTED]>
To: [email protected]
Sent: Saturday, 25 August, 2007 3:41:25 AM
Subject: Re: [CinCVS] Some of my thoughts on scripting
C and C++ are almost convertible, in that in C++ one can write
myPicture->colourBalance(rValue, gValue, bValue); // random example
while in C one would write
colourBalance(myPicture, rValue, gValue, bValue);
which is also good C++. Most interface things can be translated in this way.
The only real difference is polymorphism ie what if
myPicture could be either a JpegPicturePtr, a TiffPicturePtr
or a PngPicturePtr? In C++ one would subclass all these from PicturePtr and
create a virtual method
colourBalance. In C one does have several options (eg variants) but they do not
translate well into C++.
As to Mark's earlier comments about 'lots of switches', his example is not the
best in that somewhere in a C++ program one does need some switching code for
creating objects of the concrete class. But anyway, what is wrong with switches?
--
Regards,
Martin
([EMAIL PROTECTED])
IT: http://methodsupport.com Personal: http://thereisnoend.org
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/