macro for enum operations
Lubos Lunak
l.lunak at suse.cz
Wed Sep 10 12:15:12 BST 2003
On Wednesday 10 of September 2003 12:32, Simon Hausmann wrote:
> Hi,
>
> seeing that KFileDialog::setMode( KFile::Mode ) is deprecated in favour of
> KFileDialog::setMode( int ) makes me wonder about adding a a macro to
> kdecore/kdemacros.h that does that nifty trick of defining operations for
> combining enum values to get a nicer API but keep type safety (like we've
> see in the Qt4 presentation in n7y) :
>
> #define K_DEFINE_ENUM_OPERATIONS( EnumType ) \
> inline EnumType operator^( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); } \
> inline EnumType operator&( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); } \
> inline EnumType operator|( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); }
>
>
> Then we could mark the KFileDialog::setMode( int ) method deprecated :)
>
> Thoughts/Opinions?
s/int/unsigned long/ , I'd say
Looks like a good idea, even though creating enum values that are not defined
in the enum feels a bit scary, as enum is usually seen as 'one value from a
set', but that's probably just because I'm not used to them this way.
--
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o. e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27 tel: +420 2 9654 2373
190 00 Praha 9 fax: +420 2 9654 2374
Czech Republic http://www.suse.cz/
More information about the kde-core-devel
mailing list