Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / contract / detail / operation / static_public_function.hpp
1
2 #ifndef BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_FUNCTION_HPP_
3 #define BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_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_inv.hpp>
13 #include <boost/contract/detail/none.hpp>
14 #include <boost/contract/detail/exception.hpp>
15 #if     !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
16         !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
17         !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
18         !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
19         !defined(BOOST_CONTRACT_NO_EXCEPTS))
20     #include <boost/contract/detail/checking.hpp>
21 #endif
22 #if     !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
23         !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
24         !defined(BOOST_CONTRACT_NO_EXCEPTS)
25     #include <boost/config.hpp>
26     #include <exception>
27 #endif
28
29 namespace boost { namespace contract { namespace detail {
30
31 // No subcontracting because static so no obj and no substitution principle.
32 template<class C> // Non-copyable base.
33 class static_public_function : public cond_inv</* VR = */ none, C> {
34 public:
35     explicit static_public_function() : cond_inv</* VR = */ none, C>(
36             boost::contract::from_function, /* obj = */ 0) {}
37
38 private:
39     #if     !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
40             !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
41             !defined(BOOST_CONTRACT_NO_OLDS)
42         void init() /* override */ {
43             #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
44                 if(checking::already()) return;
45             #endif
46             #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
47                     !defined(BOOST_CONTRACT_NO_PRECONDITIONS)
48                 { // Acquire checking guard.
49                     #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
50                         checking k;
51                     #endif
52                     #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
53                         this->check_entry_static_inv();
54                     #endif
55                     #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
56                         #ifndef \
57   BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
58                             this->check_pre();
59                             } // Release checking guard (after pre check).
60                         #else
61                             } // Release checking guard (before pre check).
62                             this->check_pre();
63                         #endif
64                     #else
65                         } // Release checking guard
66                     #endif
67             #endif
68             #ifndef BOOST_CONTRACT_NO_OLDS
69                 this->copy_old();
70             #endif
71         }
72     #endif
73
74 public:
75     #if     !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
76             !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
77             !defined(BOOST_CONTRACT_NO_EXCEPTS)
78         ~static_public_function() BOOST_NOEXCEPT_IF(false) {
79             this->assert_initialized();
80             #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
81                 if(checking::already()) return;
82                 checking k;
83             #endif
84
85             #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
86                 this->check_exit_static_inv();
87             #endif
88             if(uncaught_exception()) {
89                 #ifndef BOOST_CONTRACT_NO_EXCEPTS
90                     this->check_except();
91                 #endif
92             } else {
93                 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
94                     this->check_post(none());
95                 #endif
96             }
97         }
98     #endif
99 };
100
101 } } } // namespace
102
103 #endif // #include guard
104