Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / contract / detail / checking.hpp
1
2 #ifndef BOOST_CONTRACT_DETAIL_CHECKING_HPP_
3 #define BOOST_CONTRACT_DETAIL_CHECKING_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/config.hpp>
11 #include <boost/contract/detail/static_local_var.hpp>
12 #include <boost/contract/detail/declspec.hpp>
13 #include <boost/thread/mutex.hpp>
14 #include <boost/noncopyable.hpp>
15 #include <boost/config.hpp>
16
17 namespace boost { namespace contract { namespace detail {
18
19 #ifdef BOOST_MSVC
20     #pragma warning(push)
21     #pragma warning(disable: 4275) // Base w/o DLL spec (noncopyable).
22     #pragma warning(disable: 4251) // Member w/o DLL spec (mutex_ type).
23 #endif
24
25 // RAII facility to disable assertions while checking other assertions.
26 class BOOST_CONTRACT_DETAIL_DECLSPEC checking :
27     private boost::noncopyable // Non-copyable resource (might use mutex, etc.).
28 {
29 public:
30     explicit checking() {
31         #ifndef BOOST_CONTRACT_DISABLE_THREADS
32             init_locked();
33         #else
34             init_unlocked();
35         #endif
36     }
37
38     ~checking() {
39         #ifndef BOOST_CONTRACT_DISABLE_THREADS
40             done_locked();
41         #else
42             done_unlocked();
43         #endif
44     }
45     
46     static bool already() {
47         #ifndef BOOST_CONTRACT_DISABLE_THREADS
48             return already_locked();
49         #else
50             return already_unlocked();
51         #endif
52     }
53
54 private:
55     void init_unlocked();
56     void init_locked();
57
58     void done_unlocked();
59     void done_locked();
60
61     static bool already_unlocked();
62     static bool already_locked();
63
64     struct mutex_tag;
65     typedef static_local_var<mutex_tag, boost::mutex> mutex;
66
67     struct checking_tag;
68     typedef static_local_var_init<checking_tag, bool, bool, false> flag;
69 };
70
71 #ifdef BOOST_MSVC
72     #pragma warning(pop)
73 #endif
74
75 } } } // namespace
76
77 #ifdef BOOST_CONTRACT_HEADER_ONLY
78     #include <boost/contract/detail/inlined/detail/checking.hpp>
79 #endif
80
81 #endif // #include guard
82