usp10: Add some tests for ScriptShape/Place and make them pass.
[wine] / dlls / ddraw / ddcomimpl.h
1 /* A few helpful macros for implementing COM objects.
2  *
3  * Copyright 2000 TransGaming Technologies Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #ifndef _DDCOMIMPL_H_
21 #define _DDCOMIMPL_H_
22
23 #include <stddef.h>
24
25 /* Generates the name for a vtable pointer for a given interface. */
26 /* The canonical name for a single interface is "lpVtbl". */
27 #define ICOM_VFIELD_MULTI_NAME2(iface) ITF_##iface
28 #define ICOM_VFIELD_MULTI_NAME(iface) ICOM_VFIELD_MULTI_NAME2(iface)
29
30 /* Declares a vtable pointer field in an implementation. */
31 #define ICOM_VFIELD_MULTI(iface) \
32         iface ICOM_VFIELD_MULTI_NAME(iface)
33
34 /* Returns the offset of a vtable pointer within an implementation object. */
35 #define ICOM_VFIELD_OFFSET(impltype, iface) \
36         offsetof(impltype, ICOM_VFIELD_MULTI_NAME(iface))
37
38 /* Given an interface pointer, returns the implementation pointer. */
39 #define ICOM_OBJECT(impltype, ifacename, ifaceptr)              \
40         (impltype*)((ifaceptr) == NULL ? NULL                   \
41                   : (char*)(ifaceptr) - ICOM_VFIELD_OFFSET(impltype,ifacename))
42
43 #define ICOM_THIS_FROM(impltype, ifacename, ifaceptr) \
44         impltype* This = ICOM_OBJECT(impltype, ifacename, ifaceptr)
45
46 /* Given an object and interface name, returns a pointer to that interface. */
47 #define ICOM_INTERFACE(implobj, iface) \
48         (implobj == NULL ? NULL :&((implobj)->ICOM_VFIELD_MULTI_NAME(iface)))
49
50 #define ICOM_INIT_INTERFACE(implobj, ifacename, vtblname) \
51         do { \
52           (implobj)->ICOM_VFIELD_MULTI_NAME(ifacename).lpVtbl = &(vtblname); \
53         } while (0)
54
55 #define COM_INTERFACE_CAST(impltype, ifnamefrom, ifnameto, ifaceptr)    \
56         ICOM_INTERFACE(ICOM_OBJECT(impltype, ifnamefrom, ifaceptr), ifnameto)
57
58 #endif /* _DDCOMIMPL_H_ */