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

Bob Friesenhahn <[email protected]> Fri, 5 Jul 2019 08:09:59 -0500 (CDT)
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
On Thu, 4 Jul 2019, Przemysław Sobala wrote:

> Hello
>
> What do you think about making some (all) Imageclass member functions that 
> are /getters/ (don't modify the Image object) 
> const(https://www.geeksforgeeks.org/const-member-functions-c/)? It'd be then 
> possible to create methods that pass const Image &image as an argument in the 
> API consumer - make sure that the Image object does not get modified.
>
> I can see that some methods are already const:
>     ImageType       type ( void ) const;
> but not all of them that could be, eg:
>     std::string     attribute ( const std::string name_ );
>
> I could prepare such a patch.

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.

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

_______________________________________________
Graphicsmagick-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help