xref: /aoo41x/main/tools/inc/tools/link.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _LINK_HXX
28 #define _LINK_HXX
29 
30 #include "tools/toolsdllapi.h"
31 #include "sal/config.h"
32 #include "sal/types.h"
33 #include <tools/solar.h>
34 
35 // ---------------
36 // - Link-Makros -
37 // ---------------
38 
39 typedef long (*PSTUB)( void*, void* );
40 
41 #define DECL_LINK( Method, ArgType ) \
42     long Method( ArgType ); \
43     static long LinkStub##Method( void* pThis, void* )
44 
45 #define DECL_STATIC_LINK( Class, Method, ArgType ) \
46     static long Method( Class*, ArgType )
47 
48 #define DECL_DLLPRIVATE_LINK(Method, ArgType) \
49     SAL_DLLPRIVATE long Method(ArgType); \
50     SAL_DLLPRIVATE static long LinkStub##Method(void * pThis, void *)
51 
52 #define DECL_DLLPRIVATE_STATIC_LINK(Class, Method, ArgType) \
53     SAL_DLLPRIVATE static long Method(Class *, ArgType)
54 
55 #define IMPL_METHOD( Class, Method, ArgType, ArgName ) \
56     long Class::Method( ArgType ArgName )
57 
58 #define IMPL_STUB(Class, Method, ArgType) \
59     long __EXPORT Class::LinkStub##Method( void* pThis, void* pCaller) \
60     { \
61         return ((Class*)pThis )->Method( (ArgType)pCaller ); \
62     }
63 
64 #define IMPL_STATIC_LINK( Class, Method, ArgType, ArgName ) \
65     long __EXPORT Class::Method( Class* pThis, ArgType ArgName )
66 
67 #define IMPL_STATIC_LINK_NOINSTANCE( Class, Method, ArgType, ArgName ) \
68     long __EXPORT Class::Method( Class*, ArgType ArgName )
69 
70 #define LINK( Inst, Class, Member ) \
71     Link( (Class*)Inst, (PSTUB)&Class::LinkStub##Member )
72 
73 #define STATIC_LINK( Inst, Class, Member ) \
74     Link( (Class*)Inst, (PSTUB)&Class::Member )
75 
76 #define IMPL_LINK( Class, Method, ArgType, ArgName ) \
77     IMPL_STUB( Class, Method, ArgType ) \
78     long Class::Method( ArgType ArgName )
79 
80 #if defined GCC && defined NO_OPTIMIZE
81 #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
82 	IMPL_LINK( Class, Method, ArgType, ArgName )
83 
84 #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName )
85 #else
86 #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
87     inline long Class::Method( ArgType ArgName )
88 
89 #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName ) \
90     IMPL_STUB( Class, Method, ArgType )
91 #endif
92 
93 #define IMPL_LINK_INLINE( Class, Method, ArgType, ArgName, Body ) \
94     long Class::Method( ArgType ArgName ) \
95     Body \
96     IMPL_STUB( Class, Method, ArgType )
97 
98 #define EMPTYARG
99 
100 // --------
101 // - Link -
102 // --------
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     long        Call( void* pCaller ) const;
114 
115     sal_Bool        IsSet() const;
116     sal_Bool        operator !() const;
117 
118     sal_Bool        operator==( const Link& rLink ) const;
119     sal_Bool        operator!=( const Link& rLink ) const
120                     { return !(Link::operator==( rLink )); }
121     sal_Bool        operator<( const Link& rLink ) const
122                     { return ((sal_uIntPtr)rLink.pFunc < (sal_uIntPtr)pFunc); }
123 };
124 
125 inline Link::Link()
126 {
127     pInst = 0;
128     pFunc = 0;
129 }
130 
131 inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
132 {
133     pInst = pLinkHdl;
134     pFunc = pMemFunc;
135 }
136 
137 inline long Link::Call(void *pCaller) const
138 {
139     return pFunc ? (*pFunc)(pInst, pCaller) : 0;
140 }
141 
142 inline sal_Bool Link::IsSet() const
143 {
144     if ( pFunc )
145         return sal_True;
146     else
147         return sal_False;
148 }
149 
150 inline sal_Bool Link::operator !() const
151 {
152     if ( !pFunc )
153         return sal_True;
154     else
155         return sal_False;
156 }
157 
158 #endif  // _LINK_HXX
159