2 #ifndef BOOST_CONTRACT_OVERRIDE_HPP_
3 #define BOOST_CONTRACT_OVERRIDE_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
11 Handle public function overrides (for subcontracting).
14 // IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes.
15 #include <boost/contract/core/config.hpp>
16 #include <boost/preprocessor/cat.hpp>
17 #include <boost/preprocessor/config/config.hpp>
19 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
21 Declare an override type with an arbitrary name.
23 Declare the override type to pass as an explicit template parameter to
24 @RefFunc{boost::contract::public_function} for public function overrides.
26 @see @RefSect{advanced.named_overrides, Named Overrides}
28 @param type_name Name of the override type this macro will declare.
29 (This is not a variadic macro parameter but it should
30 never contain commas because it is an identifier.)
31 @param func_name Function name of the public function override.
32 This macro is called just once even if the function name
33 is overloaded (the same override type is used for all
34 overloaded functions with the same name, see
35 @RefSect{advanced.function_overloads,
37 (This is not a variadic macro parameter but it should
38 never contain commas because it is an identifier.)
40 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)
41 #elif !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS)
42 #include <boost/contract/core/virtual.hpp>
43 #include <boost/contract/detail/type_traits/mirror.hpp>
44 #include <boost/contract/detail/tvariadic.hpp>
45 #include <boost/contract/detail/none.hpp>
46 #include <boost/contract/detail/name.hpp>
50 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, arity_compl, \
53 class BOOST_CONTRACT_DETAIL_NAME1(B), \
54 class BOOST_CONTRACT_DETAIL_NAME1(C) \
55 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
56 BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, \
57 BOOST_CONTRACT_DETAIL_NAME1(Args)) \
59 static void BOOST_CONTRACT_DETAIL_NAME1(call_base)( \
60 boost::contract::virtual_* BOOST_CONTRACT_DETAIL_NAME1(v), \
61 BOOST_CONTRACT_DETAIL_NAME1(C)* BOOST_CONTRACT_DETAIL_NAME1(obj) \
62 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
63 BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(z, arity, \
64 BOOST_CONTRACT_DETAIL_NAME1(Args), \
66 BOOST_CONTRACT_DETAIL_NAME1(args) \
68 BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \
69 BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \
70 boost::contract::detail::none&) \
72 BOOST_CONTRACT_DETAIL_NAME1(obj)-> \
73 BOOST_CONTRACT_DETAIL_NAME1(B)::func_name( \
74 BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, \
75 BOOST_CONTRACT_DETAIL_NAME1(args)) \
76 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
77 BOOST_CONTRACT_DETAIL_NAME1(v) \
81 #if BOOST_CONTRACT_DETAIL_TVARIADIC
82 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
83 BOOST_CONTRACT_OVERRIDE_CALL_BASE_(1, ~, ~, func_name)
85 #include <boost/preprocessor/repetition/repeat.hpp>
86 #include <boost/preprocessor/arithmetic/inc.hpp>
87 #include <boost/preprocessor/arithmetic/sub.hpp>
89 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
90 BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \
91 BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_, func_name) \
93 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_(z, arity, func_name) \
94 BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, \
95 BOOST_PP_SUB(BOOST_CONTRACT_MAX_ARGS, arity), func_name)
100 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
102 BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \
103 BOOST_CONTRACT_DETAIL_NAME1(has_member_function), \
106 BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
109 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
110 struct type_name {}; /* empty (not used), just to compile */
116 Declare an override type named <c>override_<i>func_name</i></c>.
118 Declare the override type to pass as an explicit template parameter to
119 @RefFunc{boost::contract::public_function} for public function overrides.
121 @see @RefSect{tutorial.public_function_overrides__subcontracting_,
122 Public Function Overrides}
124 @param func_name Function name of the public function override.
125 This macro is called just once even if the function name is
126 overloaded (the same override type is used for all
127 overloaded functions with the same name, see
128 @RefSect{advanced.function_overloads, Function Overloads}).
129 (This is not a variadic macro parameter but it should never
130 contain any comma because it is an identifier.)
132 #define BOOST_CONTRACT_OVERRIDE(func_name) \
133 BOOST_CONTRACT_NAMED_OVERRIDE(BOOST_PP_CAT(override_, func_name), func_name)
135 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
137 Declare multiple override types at once naming them <c>override_...</c> (for
140 This variadic macro is provided for convenience only,
141 <c>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</c> expands to code
145 BOOST_CONTRACT_OVERRIDE(f_1)
146 BOOST_CONTRACT_OVERRIDE(f_2)
148 BOOST_CONTRACT_OVERRIDE(f_n)
151 On compilers that do not support variadic macros,
152 the override types can be equivalently programmed one-by-one calling
153 @RefMacro{BOOST_CONTRACT_OVERRIDE} for each function name as shown above.
155 @see @RefSect{tutorial.public_function_overrides__subcontracting_,
156 Public Function Overrides}
158 @param ... A comma separated list of one or more function names of public
160 (Each function name should never contain commas because it is an
163 #define BOOST_CONTRACT_OVERRIDES(...)
164 #elif BOOST_PP_VARIADICS
165 #include <boost/preprocessor/seq/for_each.hpp>
166 #include <boost/preprocessor/variadic/to_seq.hpp>
170 #define BOOST_CONTRACT_OVERRIDES_SEQ_(r, unused, func_name) \
171 BOOST_CONTRACT_OVERRIDE(func_name)
175 #define BOOST_CONTRACT_OVERRIDES(...) \
176 BOOST_PP_SEQ_FOR_EACH(BOOST_CONTRACT_OVERRIDES_SEQ_, ~, \
177 BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
179 #define BOOST_CONTRACT_OVERRIDES \
180 BOOST_CONTRACT_ERROR_macro_OVERRIDES_requires_variadic_macros_otherwise_manually_repeat_OVERRIDE_macro
183 #endif // #include guard