[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [Patch] Fix undeleted "static QFont *_font" in kglobalsettings.cpp
From:       Ingo =?iso-8859-1?q?Kl=F6cker?= <kloecker () kde ! org>
Date:       2008-12-04 19:42:11
Message-ID: 200812042042.11947 () thufir ! ingo-kloecker ! de
[Download RAW message or body]


On Thursday 04 December 2008, Friedrich W. H. Kossebau wrote:
> Hi Louai,
>
> Am Donnerstag, 4. Dezember 2008, um 15:03 Uhr, schrieb Louai 
Al-Khanji:
> > On Thu, Dec 4, 2008 at 3:16 PM, Friedrich W. H. Kossebau
> >
> > <kossebau@kde.org> wrote:
> > > Two best practice questions, for handling the "QFont*
> > > mFonts[FontCount]"
> > >
> > > : 1. How to set an array of pointers all to 0 most efficiently
> > > : (mFonts)?
> >
> > Either memset or just loop through it.
>
> So no built-in mechanism? Alright.
>
> > > 2. How to mark the number of entries in an enum, so adding one
> > > more increases that number (FontCount) automatically?
> >
> > I don't know if there is a clean way to do it. If it is part of a
> > QObject you can use the meta object system to get the count.
> > Otherwise I tend to do something like this:
> >
> > enum Foo {
> >     Bar,
> >     Baz,
> >     FooSentinel /*  Keep as last entry, gives number of enum
> > elements */ }
>
> So is Bar always assigned to 0 by definition of C++?

Yes, but I think it's better pratice to add a FooBegin equaling the 
first enumerator value.


> And is there a nice KDE/Qt-pattern for naming the sentinel element?

Don't know. I suggest to call it FooEnd since this gives a nice 
correspondence to iterators, i.e.

enum Foo {
    Bar = FooBegin,
...
    FooEnd
}


Then a loop over all enumerator values would look as follows:

for ( int foo = FooBegin; foo < FooEnd; ++foo ) {
    // do something
}


Regards,
Ingo

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic