update emoji autocorrect entries from po-files
[LibreOffice.git] / include / tools / link.hxx
blobfa86e5db3a380ef3d95b4224f8b1e89ae84beadb
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 .
20 #ifndef INCLUDED_TOOLS_LINK_HXX
21 #define INCLUDED_TOOLS_LINK_HXX
23 #include <sal/config.h>
25 #include <sal/types.h>
27 #define DECL_LINK(Member, ArgType) \
28 static sal_IntPtr LinkStub##Member(void *, void *); \
29 sal_IntPtr Member(ArgType)
31 #define DECL_STATIC_LINK(Class, Member, ArgType) \
32 static sal_IntPtr LinkStub##Member(void *, void *); \
33 static sal_IntPtr Member(Class *, ArgType)
35 #define DECL_DLLPRIVATE_LINK(Member, ArgType) \
36 SAL_DLLPRIVATE static sal_IntPtr LinkStub##Member(void *, void *); \
37 SAL_DLLPRIVATE sal_IntPtr Member(ArgType)
39 #define DECL_DLLPRIVATE_STATIC_LINK(Class, Member, ArgType) \
40 SAL_DLLPRIVATE static sal_IntPtr LinkStub##Member(void *, void *); \
41 SAL_DLLPRIVATE static sal_IntPtr Member(Class *, ArgType)
43 #define IMPL_LINK(Class, Member, ArgType, ArgName) \
44 sal_IntPtr Class::LinkStub##Member(void * instance, void * data) { \
45 return static_cast<Class *>(instance)->Member( \
46 static_cast<ArgType>(data)); \
47 } \
48 sal_IntPtr Class::Member(ArgType ArgName)
50 #define IMPL_LINK_NOARG(Class, Member) \
51 sal_IntPtr Class::LinkStub##Member(void * instance, void * data) { \
52 return static_cast<Class *>(instance)->Member(data); \
53 } \
54 sal_IntPtr Class::Member(SAL_UNUSED_PARAMETER void *)
56 #define IMPL_STATIC_LINK(Class, Member, ArgType, ArgName) \
57 sal_IntPtr Class::LinkStub##Member(void * instance, void * data) { \
58 return Member( \
59 static_cast<Class *>(instance), static_cast<ArgType>(data)); \
60 } \
61 sal_IntPtr Class::Member(SAL_UNUSED_PARAMETER Class *, ArgType ArgName)
63 #define IMPL_STATIC_LINK_NOARG(Class, Member) \
64 sal_IntPtr Class::LinkStub##Member(void * instance, void * data) { \
65 return Member(static_cast<Class *>(instance), data); \
66 } \
67 sal_IntPtr Class::Member( \
68 SAL_UNUSED_PARAMETER Class *, SAL_UNUSED_PARAMETER void *)
70 #define DECL_LINK_TYPED(Member, ArgType, RetType) \
71 static RetType LinkStub##Member(void *, ArgType); \
72 RetType Member(ArgType)
74 #define DECL_STATIC_LINK_TYPED(Class, Member, ArgType, RetType) \
75 static RetType LinkStub##Member(void *, ArgType); \
76 static RetType Member(Class *, ArgType)
78 #define DECL_DLLPRIVATE_LINK_TYPED(Member, ArgType, RetType) \
79 SAL_DLLPRIVATE static RetType LinkStub##Member(void *, ArgType); \
80 SAL_DLLPRIVATE RetType Member(ArgType)
82 #define DECL_DLLPRIVATE_STATIC_LINK_TYPED(Class, Member, ArgType, RetType) \
83 SAL_DLLPRIVATE static RetType LinkStub##Member(void *, ArgType); \
84 SAL_DLLPRIVATE static RetType Member(Class *, ArgType)
86 #define IMPL_LINK_TYPED(Class, Member, ArgType, ArgName, RetType) \
87 RetType Class::LinkStub##Member(void * instance, ArgType data) { \
88 return static_cast<Class *>(instance)->Member(data); \
89 } \
90 RetType Class::Member(ArgType ArgName)
92 #define IMPL_LINK_NOARG_TYPED(Class, Member, ArgType, RetType) \
93 RetType Class::LinkStub##Member(void * instance, ArgType data) { \
94 return static_cast<Class *>(instance)->Member(data); \
95 } \
96 RetType Class::Member(SAL_UNUSED_PARAMETER ArgType)
98 #define IMPL_STATIC_LINK_TYPED( \
99 Class, Member, ArgType, ArgName, RetType) \
100 RetType Class::LinkStub##Member(void * instance, ArgType data) { \
101 return Member(static_cast<Class *>(instance), data); \
103 RetType Class::Member(SAL_UNUSED_PARAMETER Class *, ArgType ArgName)
105 #define IMPL_STATIC_LINK_NOARG_TYPED( \
106 Class, Member, ArgType, RetType) \
107 RetType Class::LinkStub##Member(void * instance, ArgType data) { \
108 return Member(static_cast<Class *>(instance), data); \
110 RetType Class::Member( \
111 SAL_UNUSED_PARAMETER Class *, SAL_UNUSED_PARAMETER ArgType)
113 #define LINK(Instance, Class, Member) ::tools::detail::makeLink( \
114 static_cast<Class *>(Instance), &Class::LinkStub##Member)
116 template<typename Arg = void *, typename Ret = sal_IntPtr>
117 class SAL_WARN_UNUSED Link {
118 public:
119 typedef Ret Stub(void *, Arg);
121 Link(): function_(nullptr), instance_(nullptr) {}
123 Link(void * instance, Stub * function):
124 function_(function), instance_(instance) {}
126 Ret Call(Arg data) const
127 { return function_ == nullptr ? Ret() : (*function_)(instance_, data); }
129 bool IsSet() const { return function_ != nullptr; }
131 bool operator !() const { return !IsSet(); }
133 bool operator <(Link const & other) const {
134 return reinterpret_cast<sal_uIntPtr>(function_)
135 < reinterpret_cast<sal_uIntPtr>(other.function_);
138 bool operator ==(Link const & other) const
139 { return function_ == other.function_ && instance_ == other.instance_; };
141 bool operator !=(Link const & other) const { return !operator ==(other); };
142 void *GetInstance() const { return instance_; }
144 private:
145 Stub * function_;
146 void * instance_;
149 namespace tools { namespace detail {
151 template<typename Arg, typename Ret>
152 Link<Arg, Ret> makeLink(void * instance, Ret (* function)(void *, Arg)) {
153 return Link<Arg, Ret>(instance, function);
158 #endif
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */