Next: 4.4.3 Building argument structures Up: 4.4 Using function dispatch Previous: 4.4.1 Adding and removing Contents

## 4.4.2 Searching the function database

    void *im_map_packages(
        im_list_map_fn fn, void *a )

This function applies the argument function `fn` to every package in the database, starting with the most recently added package. As with `im_list_map()`, the argument function should return `NULL` to continue searching, or non-`NULL` to terminate the search early. `im_map_packages()` returns `NULL` if `fn` returned `NULL` for all arguments. The extra argument `a` is carried around by VIPS for your use.

For example, this fragment of code prints the names of all loaded packages to `fd`:

    static void *
    print_package_name( im_package *pack,
        FILE *fp )
    {
        (void) fprintf( fp,
            "package: \"%s\"\n",
    	pack->name );

        /* Continue search.
         */
        return( NULL );
    }

    static void
    print_packages( FILE *fp )
    {
        (void) im_map_packages(
            (im_list_map_fn)
    	print_package_name, fp );
    }

VIPS defines three convenience functions based on `im_map_packages()` which simplify searching for specific functions:

    im_function *
        im_find_function( char *name )
    im_package *
        im_find_package( char *name )
    im_package *
        im_package_of_function( char *name )