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_DESTRUCTOR_HPP_
0003 #define BOOST_CONTRACT_DETAIL_DESTRUCTOR_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 // Dtor subcontracting impl via C++ obj destruction mechanism.
0031 template<class C> // Non-copyable base.
0032 class destructor : public cond_inv</* VR = */ none, C> {
0033 public:
0034     explicit destructor(C* obj) : cond_inv</* VR = */ none, C>(
0035             boost::contract::from_destructor, 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                     // Obj exists (before dtor body), check static and non- inv.
0051                     this->check_entry_all_inv();
0052                     // Dtor cannot have pre because it has no parameters.
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         ~destructor() 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 dtor body threw, obj still exists so check subcontracted
0073             // static and non- inv (but no post because of throw). Otherwise,
0074             // obj destructed so check static inv and post (even if there is no
0075             // obj after dtor body, this library allows dtor post, for example
0076             // to check static members for an instance counter class).
0077             // NOTE: In theory C++ destructors should not throw, but the
0078             // language allows for that (even if in C++11 dtors declarations are
0079             // implicitly noexcept(true) unless specified otherwise) so this
0080             // library must handle such a case.
0081             if(uncaught_exception()) {
0082                 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
0083                     this->check_exit_all_inv();
0084                 #endif
0085                 #ifndef BOOST_CONTRACT_NO_EXCEPTS
0086                     this->check_except();
0087                 #endif
0088             } else {
0089                 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
0090                     this->check_exit_static_inv();
0091                 #endif
0092                 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
0093                     this->check_post(none());
0094                 #endif
0095             }
0096         }
0097     #endif
0098 };
0099 
0100 } } } // namespace
0101 
0102 #endif // #include guard
0103