Diffusion Krita 0bf6839a0de4

Prepare a bit for shared pointers with explicit constructors

Authored by gladhorn on Oct 30 2016, 9:51 PM.

Description

Prepare a bit for shared pointers with explicit constructors

While the implicit conversion may be convenient, it is also quite
dangerous. Let's try to move to explicit constructors.

Details

Committed
gladhornNov 7 2016, 10:02 PM
Parents
R37:8c5506fe319a: Cold init Lod Availability widget when switching presets
Branches
Unknown
Tags
Unknown

Hi, @gladhorn!

What so you think about such suggestions? Can we also implement them as part of your refactoring? I have a feeling that they would make the syntax of the resulting KisSharedPtr much more readable...

/libs/image/lazybrush/kis_colorize_mask.cpp
76

Can we introduce something like toKisShared() for this? Writing a full shared poihnter name every time might be too boring at the global scale. We already have toQShared() for things like that.

330

I was always wondering, if there was any solution not to write the full name every time in such returns? The only guess is to return nullptr instead of 0 or full class name and make an implicit costructor for nullptr...

/sdk/tests/testing_nodes.h
28

E.g. here nullptr would sound much more obvious syntax, I guess.

Thanks for the comments. I actually started adding these changed by adding explicit to the shared pointer constructors.
One thing that might be worth considering is to have a define for that, then it's possible to add the explicit keyword incrementally. The trick is that adding the keyword is binary compatible, so parts of Krita can be built with explicit smart pointer constructors while others are still being ported.

/libs/image/lazybrush/kis_colorize_mask.cpp
76

I don't find it so very hard, to write the constructor... but I also wonder if using a shared pointer is really justified in all cases. If you have a function that does some processing on an object, without holding on to it, then there is no need for any shared pointers, the caller can simply guarantee that the pointer stays alive for the duration of the function call.
If you really want, adding convenience API is of course possible.

330

I guess not easily. At least I can't think of a simple way, I can try to ask around.

/sdk/tests/testing_nodes.h
28

It could of course be return KisPaintDeviceSP(nullptr);
but I assume that doesn't feel right to you either then...