[cairo] What is the closure in stream output to file based surfaces for?

David Weiß David.Weiss at ptvgroup.com
Tue Jul 29 02:03:57 PDT 2014


I want to implement file output for a rendering application and want to use C++ file streams using the following callback write function:

    cairo_status_t cairo_write_func (void *closure, const unsigned char *data, unsigned int length)
            const std::string s(data, length);
            fout << s;
        catch (std::exception &e)
            return CAIRO_STATUS_WRITE_ERROR;

        return CAIRO_STATUS_SUCCESS;

I just can't figure out what the closure is for.
Can anyone explain the concept to me?
Is it comparable to variable capturing in C++11 closures?
Could I just pass nullptr as I do not use it anyway?

David Weiß

Logistics Software Development

Haid-und-Neu-Str. 15, 76131 Karlsruhe, Germany

david.weiss at ptvgroup.com<mailto:david.weiss at ptvgroup.com>


PTV Planung Transport Verkehr AG
Headquarters: Karlsruhe
Executive Board: Vincent Kobesen (CEO)
Chairman of the Supervisory Board: Dr. h.c. Frank-Jürgen Weise
Commercial Register (HRB-Nr): 109262
Local Court: Mannheim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20140729/7b37e147/attachment.html>

More information about the cairo mailing list