Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_TOOLS_LINK_HXX
20 : #define INCLUDED_TOOLS_LINK_HXX
21 :
22 : #include <tools/toolsdllapi.h>
23 : #include <sal/config.h>
24 : #include <sal/types.h>
25 : #include <tools/solar.h>
26 :
27 : typedef long (*PSTUB)( void*, void* );
28 :
29 : #define DECL_LINK( Method, ArgType ) \
30 : long Method( ArgType ); \
31 : static long LinkStub##Method( void* pThis, void* )
32 :
33 : #define DECL_STATIC_LINK( Class, Method, ArgType ) \
34 : static long LinkStub##Method( void* pThis, void* ); \
35 : static long Method( Class*, ArgType )
36 :
37 : #define DECL_DLLPRIVATE_LINK(Method, ArgType) \
38 : SAL_DLLPRIVATE long Method(ArgType); \
39 : SAL_DLLPRIVATE static long LinkStub##Method(void * pThis, void *)
40 :
41 : #define DECL_DLLPRIVATE_STATIC_LINK(Class, Method, ArgType) \
42 : SAL_DLLPRIVATE static long LinkStub##Method( void* pThis, void* ); \
43 : SAL_DLLPRIVATE static long Method(Class *, ArgType)
44 :
45 : #define IMPL_STUB(Class, Method, ArgType) \
46 : long Class::LinkStub##Method( void* pThis, void* pCaller) \
47 : { \
48 : return static_cast<Class*>(pThis)->Method( (ArgType)pCaller ); \
49 : }
50 :
51 : #define IMPL_STATIC_LINK( Class, Method, ArgType, ArgName ) \
52 : long Class::LinkStub##Method( void* pThis, void* pCaller) \
53 : { \
54 : return Method( static_cast<Class*>(pThis), (ArgType)pCaller ); \
55 : } \
56 : long Class::Method( Class* pThis, ArgType ArgName )
57 :
58 : #define IMPL_STATIC_LINK_NOINSTANCE( Class, Method, ArgType, ArgName ) \
59 : long Class::LinkStub##Method( void* pThis, void* pCaller) \
60 : { \
61 : return Method( static_cast<Class*>(pThis), (ArgType)pCaller ); \
62 : } \
63 : long Class::Method( SAL_UNUSED_PARAMETER Class*, ArgType ArgName )
64 :
65 : #define IMPL_STATIC_LINK_NOINSTANCE_NOARG( Class, Method ) \
66 : long Class::LinkStub##Method( void* pThis, void* pCaller) \
67 : { \
68 : return Method( static_cast<Class*>(pThis), pCaller ); \
69 : } \
70 : long Class::Method( SAL_UNUSED_PARAMETER Class*, SAL_UNUSED_PARAMETER void* )
71 :
72 : #define LINK( Inst, Class, Member ) \
73 : Link( static_cast<Class*>(Inst), (PSTUB)&Class::LinkStub##Member )
74 :
75 : #define STATIC_LINK( Inst, Class, Member ) LINK(Inst, Class, Member)
76 :
77 : #define IMPL_LINK( Class, Method, ArgType, ArgName ) \
78 : IMPL_STUB( Class, Method, ArgType ) \
79 : long Class::Method( ArgType ArgName )
80 :
81 : #define IMPL_LINK_NOARG( Class, Method ) \
82 : IMPL_STUB( Class, Method, void* ) \
83 : long Class::Method( SAL_UNUSED_PARAMETER void* )
84 :
85 : #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
86 : inline long Class::Method( ArgType ArgName )
87 :
88 : #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName ) \
89 : IMPL_STUB( Class, Method, ArgType )
90 :
91 : #define IMPL_LINK_NOARG_INLINE_START( Class, Method ) \
92 : inline long Class::Method( SAL_UNUSED_PARAMETER void* )
93 :
94 : #define IMPL_LINK_NOARG_INLINE_END( Class, Method ) \
95 : IMPL_STUB( Class, Method, void* )
96 :
97 : #define IMPL_LINK_INLINE( Class, Method, ArgType, ArgName, Body ) \
98 : long Class::Method( ArgType ArgName ) \
99 : Body \
100 : IMPL_STUB( Class, Method, ArgType )
101 :
102 : #define EMPTYARG
103 :
104 : class TOOLS_DLLPUBLIC Link
105 : {
106 : void* pInst;
107 : PSTUB pFunc;
108 :
109 : public:
110 : Link();
111 : Link( void* pLinkHdl, PSTUB pMemFunc );
112 :
113 : sal_IntPtr Call( void* pCaller ) const;
114 :
115 : bool IsSet() const;
116 : bool operator !() const;
117 :
118 : bool operator==( const Link& rLink ) const;
119 : bool operator!=( const Link& rLink ) const
120 : { return !(Link::operator==( rLink )); }
121 : bool operator<( const Link& rLink ) const
122 : { return reinterpret_cast<sal_uIntPtr>(rLink.pFunc) < reinterpret_cast<sal_uIntPtr>(pFunc); }
123 : };
124 :
125 5188859 : inline Link::Link()
126 : {
127 5188859 : pInst = 0;
128 5188859 : pFunc = 0;
129 5188859 : }
130 :
131 2711435 : inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
132 : {
133 2711435 : pInst = pLinkHdl;
134 2711435 : pFunc = pMemFunc;
135 2711435 : }
136 :
137 25830757 : inline sal_IntPtr Link::Call(void *pCaller) const
138 : {
139 25830757 : return pFunc ? (*pFunc)(pInst, pCaller) : 0;
140 : }
141 :
142 7795495 : inline bool Link::IsSet() const
143 : {
144 7795495 : if ( pFunc )
145 1670372 : return true;
146 : else
147 6125123 : return false;
148 : }
149 :
150 0 : inline bool Link::operator !() const
151 : {
152 0 : if ( !pFunc )
153 0 : return true;
154 : else
155 0 : return false;
156 : }
157 :
158 : #endif
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|