On Wed, Oct 22, 2014 at 07:40:34AM +0000, phil rosenberg wrote: > Hi Andrew and AlanI still think that a public plstream::plfill function is > bad C++ style. One af the big ideas in C++ is data hiding and doing this > exposes a method that we never want a user to call. I personally don't see > any problem with using C-Style functions in C++ - for example the only way > that is permitted to extend usage of std containers is with C-style function > as you are not permitted to inherit from them. > So in my opinion these are the options that are good C++ style > a) Just use the C plfill option - but obviously Andrew doesn't like this and > I do see why.b) Create a C-Style function in the C++ header with a slightly > different name - perhaps in a namespace to avoid clashes which calls plfill. > This is only really a very thin wrapper, but it does distinguish the C++ API > from the C APIc) If we want to go to town an do it in an object oriented way > then here is the method I would propose: We create a plfiller class which > accepts a function pointer in its constructor. This has a private method > getfillfunction() and declares plstream as a friend. Instead of passing a > function pointer to plshade, we pass a plfiller. We also declare a public > const static plfiller in plstream called defaultfiller or something which > uses plfill.Now the user can do a number of things. They can call > plstream::shade with plstream::defaultfiller, they can call it with plfill, > which will implicitly construct a plfiller, they can call it with their own > function pointer which will again implicitly create a filler object or they > can create their own plfiller which will return a different function pointer > of their own design. > > Option c is rather more complicated than the other 2, but is ensures all the > data hiding requiresments of good C++ style and to me is the much better > option style wise than just having a static plstream::plfill method. > Phil
I agree with Phil that c) is probably the "correct" C++ way to do this, but I also agree it seems like overkill. This is the kind of thing I did for the Java classes, but there using the C API is not an option so it was more enforced, b) seems like unnecessary work without any real benefit. I could live with a) I guess despite my reservations. We have the C++ version for the direct calls, and just use the C version for the callback. Alan - if we went for my suggestion of have a static and non-static version they would need different names. I'm pretty sure you couldn't overload the function that way if both versions had exactly the same arguments. Andrew ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel