Re: Enums/flags as objects?

From: Date: Wed, 01 Sep 2004 21:26:39 +0000
Subject: Re: Enums/flags as objects?
References: 1 2  Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-743@lists.php.net to get a copy of this message
Hi
Do you think wrapping enums/flags as objects has advantages? PyGtk 2.3.x seems to do it this way.
backtracking, a class/function could be made which could be called when the programmer needs the name explicitly. The function returns the name b) one function which accepts a "enum type group" as parameter getEnumName( 4, ENUM_CURSOR);
I just sat down and made such a function, but see yourself: 8<================= <?php /** * helper function to determine return values * @author Christian Weiske <cweiske@php.net> */ //that we have something to find if( !extension_loaded('gtk')) {
    dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
} /** * returns a enum name for a given value * you can (and should) specify a group like "PLOT" or so * to limit the search results */ function resolvEnum( $nValue, $strGroup = '') {
    $strGroup = strtoupper( $strGroup);
    $arEnums    = get_defined_constants();
    $arFound    = array();
    foreach( $arEnums as $strEnumName => $nDefValue)
    {
        if( $nValue !== $nDefValue) continue;
        //here we could remove all the not GTK_ and GDK_ constants if we'd like to
        if( strstr( $strEnumName, '_' . $strGroup . '_') === false
            && substr( $strEnumName, 0,  strlen( $strGroup) + 1) !== $strGroup . '_'
        ) {
            continue;
        }
        $arFound[]  = $strEnumName;
    }
    return $arFound;
}//function resolvEnum( $nValue, $strGroup = '') var_dump( resolvEnum( 4, 'PLOT')); var_dump( resolvEnum( 4, 'PLO')); var_dump( resolvEnum( 3, 'GDK_WINDOW')); ?> 8<================= Regards/MfG, Christian Weiske -- XMMS is playing now: Nickelback - Breathe

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.gtk.dev (#743) next »