singleton::exists() addition for K_GLOBAL_STATIC

Olivier Goffart ogoffart at kde.org
Sun May 4 21:40:26 BST 2008


Le dimanche 4 mai 2008, David Faure a écrit :
> I'm porting code like this
> void KonqFMSettings::reparseConfiguration()
> {
>     if (globalEmbedSettings) {
>         globalEmbedSettings->init();
>     }
> }
> to K_GLOBAL_STATIC.
> It used to do nothing if the singleton hadn't been constructed yet, but now
> it would create it just to reparse configuration, which is useless in this
> case.
>
> How about this addition?

Looks ok.
Maybe it should be documented anyway.



>
> Index: kglobal.h
> ===================================================================
> --- kglobal.h   (revision 802526)
> +++ kglobal.h   (working copy)
> @@ -266,6 +266,10 @@ static struct K_GLOBAL_STATIC_STRUCT_NAM
>      {                                                                     
>     \ return _k_static_##NAME##_destroyed;                                 
>  \ }                                                                       
>   \ +    bool exists()                                                     
>         \ +    {                                                           
>               \ +        return _k_static_##NAME != 0;                     
>                     \ +    }                                               
>                           \ inline operator TYPE*()                        
>                            \ {                                             
>                             \ return operator->();                         
>                          \
>
> Then I could write
>     if (globalEmbedSettings.exists()) {
>         globalEmbedSettings->init();
>     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080504/9fc2d7c9/attachment.sig>


More information about the kde-core-devel mailing list