K_GLOBAL_STATIC and other macros

Thiago Macieira thiago at kde.org
Fri Apr 13 10:27:43 BST 2007


Thomas Zander wrote:
> I've been looking for a way to do statics since the kde3 method has been
> deprecated. Unfortunately the only code example I found doesn't contain
> enough information for me to figure how the macro applies to me (or even
> how in general it works).
>
> Thats a generic problem with macros; they are not documented in our API
> docs and in general you need a lot more then api docs anyway since their
> usage tends to need more info than a generic method.  Its more in the
> reach of class-docs in that there are quire some usages.

Fortunately, in this case, the macro is very well documented in the apidocs:
http://lxr.kde.org/source/KDE/kdelibs/kdecore/kernel/kglobal.h#071

I have no idea where that shows up in api.kde.org or EBN. But the macro is
documented nonetheless.

> I'm looking for a way to;
> init the static to zero initially;
> Define a method like 'instance' or 'self' that either returns an existing
> one or creates a new one including some initialisation code.

K_GLOBAL_STATIC(MyType, name)

Usage:
   [...]
   name->member = foo;
   name->setFoo(foo);
   MyType *ptr = name;
   MyType &ref = *name;

I.e., "name" behaves just like a pointer to MyType (MyType*).

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358






More information about the kde-core-devel mailing list