Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 #ifndef BOOST_CONTRACT_DETAIL_CONSTRUCTOR_HPP_
0003 #define BOOST_CONTRACT_DETAIL_CONSTRUCTOR_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 #include <boost/contract/core/exception.hpp>
0011 #include <boost/contract/core/config.hpp>
0012 #include <boost/contract/detail/condition/cond_inv.hpp>
0013 #include <boost/contract/detail/none.hpp>
0014 #include <boost/contract/detail/exception.hpp>
0015 #if     !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
0016         !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
0017         !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
0018         !defined(BOOST_CONTRACT_NO_EXCEPTS))
0019     #include <boost/contract/detail/checking.hpp>
0020 #endif
0021 #if     !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
0022         !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
0023         !defined(BOOST_CONTRACT_NO_EXCEPTS)
0024     #include <boost/config.hpp>
0025     #include <exception>
0026 #endif
0027 
0028 namespace boost { namespace contract { namespace detail {
0029 
0030 // Ctor subcontracting impl via C++ obj construction mechanism.
0031 template<class C> // Non-copyable base.
0032 class constructor : public cond_inv</* VR = */ none, C> {
0033 public:
0034     explicit constructor(C* obj) : cond_inv</* VR = */ none, C>(
0035             boost::contract::from_constructor, obj) {}
0036 
0037 private:
0038     #if     !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
0039             !defined(BOOST_CONTRACT_NO_OLDS)
0040         void init() /* override */ {
0041             #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
0042                 if(checking::already()) return;
0043             #endif
0044 
0045             #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
0046                 {
0047                     #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
0048                         checking k;
0049                     #endif
0050                     this->check_entry_static_inv();
0051                     // No object before ctor body so check only static inv at
0052                     // entry. Ctor pre checked by constructor_precondition.
0053                 }
0054             #endif
0055             #ifndef BOOST_CONTRACT_NO_OLDS
0056                 this->copy_old();
0057             #endif
0058         }
0059     #endif
0060 
0061 public:
0062     #if     !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
0063             !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
0064             !defined(BOOST_CONTRACT_NO_EXCEPTS)
0065         ~constructor() BOOST_NOEXCEPT_IF(false) {
0066             this->assert_initialized();
0067             #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
0068                 if(checking::already()) return;
0069                 checking k;
0070             #endif
0071 
0072             // If ctor body threw, no obj so check only static inv. Otherwise,
0073             // obj constructed so check static inv, non-static inv, and post.
0074             if(uncaught_exception()) {
0075                 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
0076                     this->check_exit_static_inv();
0077                 #endif
0078                 #ifndef BOOST_CONTRACT_NO_EXCEPTS
0079                     this->check_except();
0080                 #endif
0081             } else {
0082                 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
0083                     this->check_exit_all_inv();
0084                 #endif
0085                 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0086                     this->check_post(none());
0087                 #endif
0088             }
0089         }
0090     #endif
0091 };
0092 
0093 } } } // namespace
0094 
0095 #endif // #include guard
0096