Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:25

0001 
0002 #ifndef BOOST_CONTRACT_VIRTUAL_HPP_
0003 #define BOOST_CONTRACT_VIRTUAL_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 virtual public functions with contracts (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 #ifndef BOOST_CONTRACT_NO_CONDITIONS
0017     #include <boost/contract/detail/decl.hpp>
0018 #endif
0019 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0020     #include <boost/any.hpp>
0021 #endif
0022 #ifndef BOOST_CONTRACT_NO_OLDS
0023     #include <boost/shared_ptr.hpp>
0024     #include <queue>
0025 #endif
0026 
0027 namespace boost { namespace contract {
0028         
0029 #ifndef BOOST_CONTRACT_NO_CONDITIONS
0030     namespace detail {
0031         BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1,
0032                 /* is_friend = */ 0, OO, RR, FF, CC, AArgs);
0033     }
0034 #endif
0035 
0036 /**
0037 Type of extra function parameter to handle contracts for virtual public
0038 functions (for subcontracting).
0039 
0040 Virtual public functions (and therefore also public function overrides)
0041 declaring contracts using this library must specify an extra function parameter
0042 at the very end of their parameter list.
0043 This parameter must be a pointer to this class and it must have default value
0044 @c 0 or @c nullptr (this extra parameter is often named @c v in this
0045 documentation, but any name can be used):
0046 
0047 @code
0048 class u {
0049 public:
0050     virtual void f(int x, boost::contract::virtual_* v = 0) { // Declare `v`.
0051         ... // Contract declaration (which will use `v`) and function body.
0052     }
0053 
0054     ...
0055 };
0056 @endcode
0057 
0058 In practice this extra parameter does not alter the calling interface of the
0059 enclosing function declaring the contract because it is always the very last
0060 parameter and it has a default value (so it can always be omitted when users
0061 call the function).
0062 This extra parameter must be passed to
0063 @RefFunc{boost::contract::public_function}, @RefMacro{BOOST_CONTRACT_OLDOF}, and
0064 all other operations of this library that accept a pointer to
0065 @RefClass{boost::contract::virtual_}.
0066 A part from that, this class is not intended to be directly used by programmers
0067 (and that is why this class does not have any public member and it is not
0068 copyable).
0069 
0070 @see    @RefSect{tutorial.virtual_public_functions, Virtual Public Functions},
0071         @RefSect{tutorial.public_function_overrides__subcontracting_,
0072         Public Function Overrides}
0073 */
0074 class virtual_ { // Non-copyable (see below) to avoid copy queue, stack, etc.
0075 /** @cond */
0076 private: // No public API (so users cannot use it directly by mistake).
0077 
0078     // No boost::noncopyable to avoid its overhead when contracts disabled.
0079     virtual_(virtual_&);
0080     virtual_& operator=(virtual_&);
0081 
0082     #ifndef BOOST_CONTRACT_NO_CONDITIONS
0083         enum action_enum {
0084             // virtual_ always held/passed as ptr so nullptr used for user call.
0085             no_action,
0086             #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
0087                 check_entry_inv,
0088             #endif
0089             #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
0090                 check_pre,
0091             #endif
0092             #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
0093                 check_exit_inv,
0094             #endif
0095             #ifndef BOOST_CONTRACT_NO_OLDS
0096                 // For outside .old(...).
0097                 push_old_init_copy,
0098                 // pop_old_init_copy as static function below.
0099                 // For inside .old(...).
0100                 call_old_ftor,
0101                 push_old_ftor_copy,
0102                 pop_old_ftor_copy,
0103             #endif
0104             #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0105                 check_post,
0106             #endif
0107             #ifndef BOOST_CONTRACT_NO_EXCEPTS
0108                 check_except,
0109             #endif
0110         };
0111     #endif
0112 
0113     #ifndef BOOST_CONTRACT_NO_OLDS
0114         // Not just an enum value because the logical combination of two values.
0115         inline static bool pop_old_init_copy(action_enum a) {
0116             return
0117                 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0118                     a == check_post
0119                 #endif
0120                 #if     !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
0121                         !defined(BOOST_CONTRACT_NO_EXCEPTS)
0122                     ||
0123                 #endif
0124                 #ifndef BOOST_CONTRACT_NO_EXCEPTS
0125                     a == check_except
0126                 #endif
0127             ;
0128         }
0129     #endif
0130 
0131     #ifndef BOOST_CONTRACT_NO_CONDITIONS
0132         explicit virtual_(action_enum a) :
0133               action_(a)
0134             , failed_(false)
0135             #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0136                 , result_type_name_()
0137                 , result_optional_()
0138             #endif
0139         {}
0140     #endif
0141 
0142     #ifndef BOOST_CONTRACT_NO_CONDITIONS
0143         action_enum action_;
0144         bool failed_;
0145     #endif
0146     #ifndef BOOST_CONTRACT_NO_OLDS
0147         std::queue<boost::shared_ptr<void> > old_init_copies_;
0148         std::queue<boost::shared_ptr<void> > old_ftor_copies_;
0149     #endif
0150     #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0151         boost::any result_ptr_; // Result for virtual and overriding functions.
0152         char const* result_type_name_;
0153         bool result_optional_;
0154     #endif
0155 
0156     // Friends (used to limit library's public API).
0157     #ifndef BOOST_CONTRACT_NO_OLDS
0158         friend bool copy_old(virtual_*);
0159         friend class old_pointer;
0160     #endif
0161     #ifndef BOOST_CONTRACT_NO_CONDITIONS
0162         BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1,
0163                 /* is_friend = */ 1, OO, RR, FF, CC, AArgs);
0164     #endif
0165 /** @endcond */
0166 };
0167 
0168 } } // namespace
0169 
0170 #endif // #include guard
0171