update credits
[LibreOffice.git] / include / tools / link.hxx
blobc325b67bae769e2fffa17b0beded93faec198fd1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _LINK_HXX
20 #define _LINK_HXX
22 #include "tools/toolsdllapi.h"
23 #include "sal/config.h"
24 #include "sal/types.h"
25 #include <tools/solar.h>
27 typedef long (*PSTUB)( void*, void* );
29 #define DECL_LINK( Method, ArgType ) \
30 long Method( ArgType ); \
31 static long LinkStub##Method( void* pThis, void* )
33 #define DECL_STATIC_LINK( Class, Method, ArgType ) \
34 static long Method( Class*, ArgType )
36 #define DECL_DLLPRIVATE_LINK(Method, ArgType) \
37 SAL_DLLPRIVATE long Method(ArgType); \
38 SAL_DLLPRIVATE static long LinkStub##Method(void * pThis, void *)
40 #define DECL_DLLPRIVATE_STATIC_LINK(Class, Method, ArgType) \
41 SAL_DLLPRIVATE static long Method(Class *, ArgType)
43 #define IMPL_STUB(Class, Method, ArgType) \
44 long Class::LinkStub##Method( void* pThis, void* pCaller) \
45 { \
46 return ((Class*)pThis )->Method( (ArgType)pCaller ); \
49 #define IMPL_STATIC_LINK( Class, Method, ArgType, ArgName ) \
50 long Class::Method( Class* pThis, ArgType ArgName )
52 #define IMPL_STATIC_LINK_NOINSTANCE( Class, Method, ArgType, ArgName ) \
53 long Class::Method( SAL_UNUSED_PARAMETER Class*, ArgType ArgName )
55 #define LINK( Inst, Class, Member ) \
56 Link( (Class*)Inst, (PSTUB)&Class::LinkStub##Member )
58 #define STATIC_LINK( Inst, Class, Member ) \
59 Link( (Class*)Inst, (PSTUB)&Class::Member )
61 #define IMPL_LINK( Class, Method, ArgType, ArgName ) \
62 IMPL_STUB( Class, Method, ArgType ) \
63 long Class::Method( ArgType ArgName )
65 #define IMPL_LINK_NOARG( Class, Method ) \
66 IMPL_STUB( Class, Method, void* ) \
67 long Class::Method( SAL_UNUSED_PARAMETER void* )
69 #define IMPL_LINK_INLINE_START( Class, Method, ArgType, ArgName ) \
70 inline long Class::Method( ArgType ArgName )
72 #define IMPL_LINK_INLINE_END( Class, Method, ArgType, ArgName ) \
73 IMPL_STUB( Class, Method, ArgType )
75 #define IMPL_LINK_NOARG_INLINE_START( Class, Method ) \
76 inline long Class::Method( SAL_UNUSED_PARAMETER void* )
78 #define IMPL_LINK_NOARG_INLINE_END( Class, Method ) \
79 IMPL_STUB( Class, Method, void* )
81 #define IMPL_LINK_INLINE( Class, Method, ArgType, ArgName, Body ) \
82 long Class::Method( ArgType ArgName ) \
83 Body \
84 IMPL_STUB( Class, Method, ArgType )
86 #define EMPTYARG
88 class TOOLS_DLLPUBLIC Link
90 void* pInst;
91 PSTUB pFunc;
93 public:
94 Link();
95 Link( void* pLinkHdl, PSTUB pMemFunc );
97 long Call( void* pCaller ) const;
99 sal_Bool IsSet() const;
100 sal_Bool operator !() const;
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); }
109 inline Link::Link()
111 pInst = 0;
112 pFunc = 0;
115 inline Link::Link( void* pLinkHdl, PSTUB pMemFunc )
117 pInst = pLinkHdl;
118 pFunc = pMemFunc;
121 inline long Link::Call(void *pCaller) const
123 return pFunc ? (*pFunc)(pInst, pCaller) : 0;
126 inline sal_Bool Link::IsSet() const
128 if ( pFunc )
129 return sal_True;
130 else
131 return sal_False;
134 inline sal_Bool Link::operator !() const
136 if ( !pFunc )
137 return sal_True;
138 else
139 return sal_False;
142 #endif
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */