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 _LINK_HXX
20 : #define _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 Method( Class*, ArgType )
35 :
36 : #define DECL_DLLPRIVATE_LINK(Method, ArgType) \
37 : SAL_DLLPRIVATE long Method(ArgType); \
38 : SAL_DLLPRIVATE static long LinkStub##Method(void * pThis, void *)
39 :
40 : #define DECL_DLLPRIVATE_STATIC_LINK(Class, Method, ArgType) \
41 : SAL_DLLPRIVATE static long Method(Class *, ArgType)
42 :
43 : #define IMPL_STUB(Class, Method, ArgType) \
44 : long Class::LinkStub##Method( void* pThis, void* pCaller) \
45 : { \
46 : return ((Class*)pThis )->Method( (ArgType)pCaller ); \
47 : }
48 :
49 : #define IMPL_STATIC_LINK( Class, Method, ArgType, ArgName ) \
50 : long Class::Method( Class* pThis, ArgType ArgName )
51 :
52 : #define IMPL_STATIC_LINK_NOINSTANCE( Class, Method, ArgType, ArgName ) \
53 : long Class::Method( SAL_UNUSED_PARAMETER Class*, ArgType ArgName )
54 :
55 : #define LINK( Inst, Class, Member ) \
56 : Link( (Class*)Inst, (PSTUB)&Class::LinkStub##Member )
57 :
58 : #define STATIC_LINK( Inst, Class, Member ) \
59 : Link( (Class*)Inst, (PSTUB)&Class::Member )
60 :
61 : #define IMPL_LINK( Class, Method, ArgType, ArgName ) \
62 : IMPL_STUB( Class, Method, ArgType ) \
63 : long Class::Method( ArgType ArgName )
64 :
65 : #define IMPL_LINK_NOARG( Class, Method ) \
66 : IMPL_STUB( Class, Method, void* ) \
67 : long Class::Method( SAL_UNUSED_PARAMETER void* )
68 :
69 : #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
70 : inline long Class::Method( ArgType ArgName )
71 :
72 : #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName ) \
73 : IMPL_STUB( Class, Method, ArgType )
74 :
75 : #define IMPL_LINK_NOARG_INLINE_START( Class, Method ) \
76 : inline long Class::Method( SAL_UNUSED_PARAMETER void* )
77 :
78 : #define IMPL_LINK_NOARG_INLINE_END( Class, Method ) \
79 : IMPL_STUB( Class, Method, void* )
80 :
81 : #define IMPL_LINK_INLINE( Class, Method, ArgType, ArgName, Body ) \
82 : long Class::Method( ArgType ArgName ) \
83 : Body \
84 : IMPL_STUB( Class, Method, ArgType )
85 :
86 : #define EMPTYARG
87 :
88 : class TOOLS_DLLPUBLIC Link
89 : {
90 : void* pInst;
91 : PSTUB pFunc;
92 :
93 : public:
94 : Link();
95 : Link( void* pLinkHdl, PSTUB pMemFunc );
96 :
97 : sal_IntPtr Call( void* pCaller ) const;
98 :
99 : bool IsSet() const;
100 : bool operator !() const;
101 :
102 : bool operator==( const Link& rLink ) const;
103 : bool operator!=( const Link& rLink ) const
104 : { return !(Link::operator==( rLink )); }
105 : bool operator<( const Link& rLink ) const
106 : { return ((sal_uIntPtr)rLink.pFunc < (sal_uIntPtr)pFunc); }
107 : };
108 :
109 1367556 : inline Link::Link()
110 : {
111 1367556 : pInst = 0;
112 1367556 : pFunc = 0;
113 1367556 : }
114 :
115 660708 : inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
116 : {
117 660708 : pInst = pLinkHdl;
118 660708 : pFunc = pMemFunc;
119 660708 : }
120 :
121 8135191 : inline sal_IntPtr Link::Call(void *pCaller) const
122 : {
123 8135191 : return pFunc ? (*pFunc)(pInst, pCaller) : 0;
124 : }
125 :
126 2931654 : inline bool Link::IsSet() const
127 : {
128 2931654 : if ( pFunc )
129 173697 : return true;
130 : else
131 2757957 : return false;
132 : }
133 :
134 0 : inline bool Link::operator !() const
135 : {
136 0 : if ( !pFunc )
137 0 : return true;
138 : else
139 0 : return false;
140 : }
141 :
142 : #endif
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|