Re: [C++ API] Making member functions const

Bob Friesenhahn <[email protected]> Fri, 5 Jul 2019 08:46:22 -0500 (CDT)
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
On Fri, 5 Jul 2019, Bob Friesenhahn wrote:
> Normally 'const' methods are required to not modify the object but a closer 
> look will reveal that the attribute method may modify the object because of 
> how attribute support was implemented in the C code (deferred handling).  For 
> example, requesting an EXIF attribute results in parsing an attached EXIF 
> blob, but also add key/value pairs for each EXIF attribute.  This does happen 
> in C code rather than C++ code.

I should say that it is possible for an implementation to lie and add 
necessary casts so that the wrapper method can be const.  It is really 
a judgement call as to if the API user can be safely unaware that 
non-const code is being called.  In a multi-threaded program it would 
be necessary to assure that locking is implemented so that multiple 
threads can call the function/method at once without causing harm. 
The final result should be that no modifications were performed from 
an external observer/API perspective.

Bob
-- 
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
Public Key,     http://www.simplesystems.org/users/bfriesen/public-key.txt