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 : long Call( void* pCaller ) const;
98 :
99 : sal_Bool IsSet() const;
100 : sal_Bool operator !() const;
101 :
102 : sal_Bool operator==( const Link& rLink ) const;
103 : sal_Bool operator!=( const Link& rLink ) const
104 : { return !(Link::operator==( rLink )); }
105 : sal_Bool operator<( const Link& rLink ) const
106 : { return ((sal_uIntPtr)rLink.pFunc < (sal_uIntPtr)pFunc); }
107 : };
108 :
109 201474 : inline Link::Link()
110 : {
111 201474 : pInst = 0;
112 201474 : pFunc = 0;
113 201474 : }
114 :
115 93984 : inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
116 : {
117 93984 : pInst = pLinkHdl;
118 93984 : pFunc = pMemFunc;
119 93984 : }
120 :
121 2100567 : inline long Link::Call(void *pCaller) const
122 : {
123 2100567 : return pFunc ? (*pFunc)(pInst, pCaller) : 0;
124 : }
125 :
126 237920 : inline sal_Bool Link::IsSet() const
127 : {
128 237920 : if ( pFunc )
129 24032 : return sal_True;
130 : else
131 213888 : return sal_False;
132 : }
133 :
134 0 : inline sal_Bool Link::operator !() const
135 : {
136 0 : if ( !pFunc )
137 0 : return sal_True;
138 : else
139 0 : return sal_False;
140 : }
141 :
142 : #endif
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|