KWin
|
Variadic template to wrap an xcb request. More...
#include <xcbutils.h>
Public Types | |
typedef Reply | reply_type |
The type returned by the xcb reply function. | |
typedef Cookie | cookie_type |
The type returned by the xcb request function. | |
typedef std::tuple< Args... > | argument_types |
Variadic arguments combined as a std::tuple. | |
typedef Cookie(* | request_func) (xcb_connection_t *, Args...) |
The function pointer definition for the xcb request function. | |
typedef Reply *(* | reply_func) (xcb_connection_t *, Cookie, xcb_generic_error_t **) |
The function pointer definition for the xcb reply function. | |
Static Public Attributes | |
static constexpr std::size_t | argumentCount = sizeof...(Args) |
Number of variadic arguments. | |
Variadic template to wrap an xcb request.
This struct is part of the generic implementation to wrap xcb requests and fetching their reply. Each request is represented by two templated elements: WrapperData and Wrapper.
The WrapperData defines the following types:
As the WrapperData does not specify the actual function pointers one needs to derive another struct which specifies the function pointer requestFunc and the function pointer replyFunc as static constexpr of type reply_func and reply_type respectively. E.g. for the command xcb_get_geometry:
To simplify this definition the macro XCB_WRAPPER_DATA is provided. For the same xcb command this looks like this:
The derived WrapperData has to be passed as first template argument to Wrapper. The other template arguments of Wrapper are the same variadic template arguments as passed into WrapperData. This is ensured at compile time and will cause a compile error in case there is a mismatch of the variadic template arguments passed to WrapperData and Wrapper. Passing another type than a struct derived from WrapperData to Wrapper will result in a compile error. The following code snippets won't compile:
The Wrapper provides an easy to use RAII API which calls the WrapperData's requestFunc in the ctor and fetches the reply the first time it is used. In addition the dtor takes care of freeing the reply if it got fetched, otherwise it discards the reply. The Wrapper can be used as if it were the reply_type directly.
There are several command wrappers defined which either subclass Wrapper to add methods to simplify the usage of the result_type or use a typedef. To add a new typedef one can use the macro XCB_WRAPPER which creates the WrapperData struct as XCB_WRAPPER_DATA does and the typedef. E.g:
creates a typedef Geometry and the struct GeometryData.
Overall this allows to simplify the Xcb usage. For example consider the following xcb code snippet:
With the help of the Wrapper class this can be simplified to:
Definition at line 185 of file xcbutils.h.
typedef std::tuple<Args...> KWin::Xcb::WrapperData< Reply, Cookie, Args >::argument_types |
Variadic arguments combined as a std::tuple.
Definition at line 199 of file xcbutils.h.
typedef Cookie KWin::Xcb::WrapperData< Reply, Cookie, Args >::cookie_type |
The type returned by the xcb request function.
Definition at line 194 of file xcbutils.h.
typedef Reply *(* KWin::Xcb::WrapperData< Reply, Cookie, Args >::reply_func) (xcb_connection_t *, Cookie, xcb_generic_error_t **) |
The function pointer definition for the xcb reply function.
Definition at line 207 of file xcbutils.h.
typedef Reply KWin::Xcb::WrapperData< Reply, Cookie, Args >::reply_type |
The type returned by the xcb reply function.
Definition at line 190 of file xcbutils.h.
typedef Cookie(* KWin::Xcb::WrapperData< Reply, Cookie, Args >::request_func) (xcb_connection_t *, Args...) |
The function pointer definition for the xcb request function.
Definition at line 203 of file xcbutils.h.
|
staticconstexpr |
Number of variadic arguments.
Definition at line 212 of file xcbutils.h.