Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:45:03

0001 
0002 #ifndef BOOST_CONTRACT_OVERRIDE_HPP_
0003 #define BOOST_CONTRACT_OVERRIDE_HPP_
0004 
0005 // Copyright (C) 2008-2018 Lorenzo Caminiti
0006 // Distributed under the Boost Software License, Version 1.0 (see accompanying
0007 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
0008 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
0009 
0010 /** @file
0011 Handle public function overrides (for subcontracting).
0012 */
0013 
0014 // IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes.
0015 #include <boost/contract/core/config.hpp>
0016 #include <boost/preprocessor/cat.hpp>
0017 #include <boost/preprocessor/config/config.hpp>
0018 
0019 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
0020     /**
0021     Declare an override type trait with an arbitrary name.
0022 
0023     Declare the override type trait named @c type_name to pass as an explicit
0024     template parameter to @RefFunc{boost::contract::public_function} for public
0025     function overrides.
0026     
0027     @see @RefSect{advanced.named_overrides, Named Overrides}
0028 
0029     @param type_name    Name of the override type trait this macro will declare.
0030                         (This is not a variadic macro parameter but it should
0031                         never contain commas because it is an identifier.)
0032     @param func_name    Function name of the public function override.
0033                         This macro is called just once even if the function name
0034                         is overloaded (the same override type trait is used for
0035                         all overloaded functions with the same name, see
0036                         @RefSect{advanced.function_overloads,
0037                         Function Overloads}).
0038                         (This is not a variadic macro parameter but it should
0039                         never contain commas because it is an identifier.)
0040     */
0041     #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)
0042 #elif !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS)
0043     #include <boost/contract/core/virtual.hpp>
0044     #include <boost/contract/detail/type_traits/mirror.hpp>
0045     #include <boost/contract/detail/tvariadic.hpp>
0046     #include <boost/contract/detail/none.hpp>
0047     #include <boost/contract/detail/name.hpp>
0048 
0049     /* PRIVATE */
0050 
0051     #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, arity_compl, \
0052             func_name) \
0053         template< \
0054             class BOOST_CONTRACT_DETAIL_NAME1(B), \
0055             class BOOST_CONTRACT_DETAIL_NAME1(C) \
0056             BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
0057             BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, \
0058                     BOOST_CONTRACT_DETAIL_NAME1(Args)) \
0059         > \
0060         static void BOOST_CONTRACT_DETAIL_NAME1(call_base)( \
0061             boost::contract::virtual_* BOOST_CONTRACT_DETAIL_NAME1(v), \
0062             BOOST_CONTRACT_DETAIL_NAME1(C)* BOOST_CONTRACT_DETAIL_NAME1(obj) \
0063             BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
0064             BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(z, arity, \
0065                 BOOST_CONTRACT_DETAIL_NAME1(Args), \
0066                 &, \
0067                 BOOST_CONTRACT_DETAIL_NAME1(args) \
0068             ) \
0069             BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \
0070             BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \
0071                     boost::contract::detail::none&) \
0072         ) { \
0073             BOOST_CONTRACT_DETAIL_NAME1(obj)-> \
0074             BOOST_CONTRACT_DETAIL_NAME1(B)::func_name( \
0075                 BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, \
0076                         BOOST_CONTRACT_DETAIL_NAME1(args)) \
0077                 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
0078                 BOOST_CONTRACT_DETAIL_NAME1(v) \
0079             ); \
0080         }
0081 
0082     #if BOOST_CONTRACT_DETAIL_TVARIADIC
0083         #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
0084             BOOST_CONTRACT_OVERRIDE_CALL_BASE_(1, ~, ~, func_name)
0085     #else
0086         #include <boost/preprocessor/repetition/repeat.hpp>
0087         #include <boost/preprocessor/arithmetic/inc.hpp>
0088         #include <boost/preprocessor/arithmetic/sub.hpp>
0089 
0090         #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
0091             BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \
0092                     BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_, func_name) \
0093         
0094         #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_(z, arity, func_name) \
0095             BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, \
0096                     BOOST_PP_SUB(BOOST_CONTRACT_MAX_ARGS, arity), func_name)
0097     #endif
0098 
0099     /* PUBLIC */
0100 
0101     #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
0102         struct type_name { \
0103             BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \
0104                 BOOST_CONTRACT_DETAIL_NAME1(has_member_function), \
0105                 func_name \
0106             ) \
0107             BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
0108         };
0109 #else
0110     #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
0111             struct type_name {}; /* empty (not used), just to compile */
0112 #endif
0113     
0114 /* PUBLIC */
0115 
0116 /**
0117 Declare an override type trait named <c>override_<i>func_name</i></c>.
0118 
0119 Declare the override type trait named <c>override_<i>func_name</i></c> to pass
0120 as an explicit template parameter to @RefFunc{boost::contract::public_function}
0121 for public function overrides.
0122 Use @RefMacro{BOOST_CONTRACT_NAMED_OVERRIDE} to generate an override type trait
0123 with a name different than <c>override_<i>func_name</i></c> (usually not
0124 needed).
0125 
0126 @see    @RefSect{tutorial.public_function_overrides__subcontracting_,
0127         Public Function Overrides}
0128 
0129 @param func_name    Function name of the public function override.
0130                     This macro is called just once even if the function name is
0131                     overloaded (the same override type trait is used for all
0132                     overloaded functions with the same name, see
0133                     @RefSect{advanced.function_overloads, Function Overloads}).
0134                     (This is not a variadic macro parameter but it should never
0135                     contain any comma because it is an identifier.)
0136 */
0137 #define BOOST_CONTRACT_OVERRIDE(func_name) \
0138     BOOST_CONTRACT_NAMED_OVERRIDE(BOOST_PP_CAT(override_, func_name), func_name)
0139     
0140 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
0141     /**
0142     Declare multiple override type traits at once naming them
0143     <c>override_...</c> (for convenience).
0144 
0145     This variadic macro is provided for convenience as
0146     <c>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</c> expands to code
0147     equivalent to:
0148 
0149     @code
0150     BOOST_CONTRACT_OVERRIDE(f_1)
0151     BOOST_CONTRACT_OVERRIDE(f_2)
0152     ...
0153     BOOST_CONTRACT_OVERRIDE(f_n)
0154     @endcode
0155 
0156     On compilers that do not support variadic macros,
0157     the override type traits can be equivalently programmed one-by-one calling
0158     @RefMacro{BOOST_CONTRACT_OVERRIDE} for each function name as shown above.
0159     
0160     @see    @RefSect{tutorial.public_function_overrides__subcontracting_,
0161             Public Function Overrides}
0162     
0163     @param ...  A comma separated list of one or more function names of public
0164                 function overrides.
0165                 (Each function name should never contain commas because it is an
0166                 identifier.)
0167     */
0168     #define BOOST_CONTRACT_OVERRIDES(...)
0169 #elif BOOST_PP_VARIADICS
0170     #include <boost/preprocessor/seq/for_each.hpp>
0171     #include <boost/preprocessor/variadic/to_seq.hpp>
0172     
0173     /* PRIVATE */
0174 
0175     #define BOOST_CONTRACT_OVERRIDES_SEQ_(r, unused, func_name) \
0176         BOOST_CONTRACT_OVERRIDE(func_name)
0177     
0178     /* PUBLIC */
0179 
0180     #define BOOST_CONTRACT_OVERRIDES(...) \
0181         BOOST_PP_SEQ_FOR_EACH(BOOST_CONTRACT_OVERRIDES_SEQ_, ~, \
0182                 BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
0183 #else
0184     #define BOOST_CONTRACT_OVERRIDES \
0185 BOOST_CONTRACT_ERROR_macro_OVERRIDES_requires_variadic_macros_otherwise_manually_repeat_OVERRIDE_macro
0186 #endif
0187 
0188 #endif // #include guard
0189