xref: /aoo41x/main/tools/inc/tools/link.hxx (revision 8b851043)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _LINK_HXX
24 #define _LINK_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include "sal/config.h"
28 #include "sal/types.h"
29 #include <tools/solar.h>
30 
31 // ---------------
32 // - Link-Makros -
33 // ---------------
34 
35 typedef long (*PSTUB)( void*, void* );
36 
37 #define DECL_LINK( Method, ArgType ) \
38     long Method( ArgType ); \
39     static long LinkStub##Method( void* pThis, void* )
40 
41 #define DECL_STATIC_LINK( Class, Method, ArgType ) \
42     static long Method( Class*, ArgType )
43 
44 #define DECL_DLLPRIVATE_LINK(Method, ArgType) \
45     SAL_DLLPRIVATE long Method(ArgType); \
46     SAL_DLLPRIVATE static long LinkStub##Method(void * pThis, void *)
47 
48 #define DECL_DLLPRIVATE_STATIC_LINK(Class, Method, ArgType) \
49     SAL_DLLPRIVATE static long Method(Class *, ArgType)
50 
51 #define IMPL_METHOD( Class, Method, ArgType, ArgName ) \
52     long Class::Method( ArgType ArgName )
53 
54 #define IMPL_STUB(Class, Method, ArgType) \
55     long __EXPORT Class::LinkStub##Method( void* pThis, void* pCaller) \
56     { \
57         return ((Class*)pThis )->Method( (ArgType)pCaller ); \
58     }
59 
60 #define IMPL_STATIC_LINK( Class, Method, ArgType, ArgName ) \
61     long __EXPORT Class::Method( Class* pThis, ArgType ArgName )
62 
63 #define IMPL_STATIC_LINK_NOINSTANCE( Class, Method, ArgType, ArgName ) \
64     long __EXPORT Class::Method( Class*, ArgType ArgName )
65 
66 #define LINK( Inst, Class, Member ) \
67     Link( (Class*)Inst, (PSTUB)&Class::LinkStub##Member )
68 
69 #define STATIC_LINK( Inst, Class, Member ) \
70     Link( (Class*)Inst, (PSTUB)&Class::Member )
71 
72 #define IMPL_LINK( Class, Method, ArgType, ArgName ) \
73     IMPL_STUB( Class, Method, ArgType ) \
74     long Class::Method( ArgType ArgName )
75 
76 #if defined GCC && defined NO_OPTIMIZE
77 #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
78 	IMPL_LINK( Class, Method, ArgType, ArgName )
79 
80 #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName )
81 #else
82 #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
83     inline long Class::Method( ArgType ArgName )
84 
85 #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName ) \
86     IMPL_STUB( Class, Method, ArgType )
87 #endif
88 
89 #define IMPL_LINK_INLINE( Class, Method, ArgType, ArgName, Body ) \
90     long Class::Method( ArgType ArgName ) \
91     Body \
92     IMPL_STUB( Class, Method, ArgType )
93 
94 #define EMPTYARG
95 
96 // --------
97 // - Link -
98 // --------
99 
100 class TOOLS_DLLPUBLIC Link
101 {
102     void*       pInst;
103     PSTUB       pFunc;
104 
105 public:
106                 Link();
107                 Link( void* pLinkHdl, PSTUB pMemFunc );
108 
109     long        Call( void* pCaller ) const;
110 
111     sal_Bool        IsSet() const;
112     sal_Bool        operator !() const;
113 
114     sal_Bool        operator==( const Link& rLink ) const;
operator !=(const Link & rLink) const115     sal_Bool        operator!=( const Link& rLink ) const
116                     { return !(Link::operator==( rLink )); }
operator <(const Link & rLink) const117     sal_Bool        operator<( const Link& rLink ) const
118                     { return ((sal_uIntPtr)rLink.pFunc < (sal_uIntPtr)pFunc); }
119 };
120 
Link()121 inline Link::Link()
122 {
123     pInst = 0;
124     pFunc = 0;
125 }
126 
Link(void * pLinkHdl,PSTUB pMemFunc)127 inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
128 {
129     pInst = pLinkHdl;
130     pFunc = pMemFunc;
131 }
132 
Call(void * pCaller) const133 inline long Link::Call(void *pCaller) const
134 {
135     return pFunc ? (*pFunc)(pInst, pCaller) : 0;
136 }
137 
IsSet() const138 inline sal_Bool Link::IsSet() const
139 {
140     if ( pFunc )
141         return sal_True;
142     else
143         return sal_False;
144 }
145 
operator !() const146 inline sal_Bool Link::operator !() const
147 {
148     if ( !pFunc )
149         return sal_True;
150     else
151         return sal_False;
152 }
153 
154 #endif  // _LINK_HXX
155