Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / contract / detail / operation / function.hpp
1
2 #ifndef BOOST_CONTRACT_DETAIL_FUNCTION_HPP_
3 #define BOOST_CONTRACT_DETAIL_FUNCTION_HPP_
4
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
9
10 #include <boost/contract/core/exception.hpp>
11 #include <boost/contract/core/config.hpp>
12 #include <boost/contract/detail/condition/cond_post.hpp>
13 #include <boost/contract/detail/exception.hpp>
14 #if     !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
15         !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
16         !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
17         !defined(BOOST_CONTRACT_NO_EXCEPTS))
18     #include <boost/contract/detail/checking.hpp>
19 #endif
20 #if     !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
21         !defined(BOOST_CONTRACT_NO_EXCEPTS)
22     #include <boost/config.hpp>
23     #include <exception>
24 #endif
25
26 namespace boost { namespace contract { namespace detail {
27
28 // Used for free function, private and protected member functions.
29 class function : public cond_post</* VR = */ none> { // Non-copyable base.
30 public:
31     explicit function() : cond_post</* VR = */ none>(
32             boost::contract::from_function) {}
33
34 private:
35     #if     !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
36             !defined(BOOST_CONTRACT_NO_OLDS)
37         void init() /* override */ {
38             #ifndef  BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
39                 if(checking::already()) return;
40             #endif
41             #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
42                 {
43                     #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && \
44                         !defined( \
45                             BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION)
46                         checking k;
47                     #endif
48                     this->check_pre();
49                 }
50             #endif
51             #ifndef BOOST_CONTRACT_NO_OLDS
52                 this->copy_old();
53             #endif
54         }
55     #endif
56
57 public:
58     #if     !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
59             !defined(BOOST_CONTRACT_NO_EXCEPTS)
60         ~function() BOOST_NOEXCEPT_IF(false) {
61             this->assert_initialized();
62             #ifndef  BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
63                 if(checking::already()) return;
64                 checking k;
65             #endif
66             
67             if(uncaught_exception()) {
68                 #ifndef BOOST_CONTRACT_NO_EXCEPTS
69                     this->check_except();
70                 #endif
71             } else {
72                 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
73                     this->check_post(none());
74                 #endif
75             }
76         }
77     #endif
78 };
79
80 } } } // namespace
81
82 #endif // #include guard
83