macro for enum operations

Simon Hausmann hausmann at kde.org
Wed Sep 10 11:32:05 BST 2003


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?

Simon




More information about the kde-core-devel mailing list