1 // Copyright Daniel Wallin 2004. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef TORRENT_INVARIANT_ACCESS_HPP_INCLUDED
6 #define TORRENT_INVARIANT_ACCESS_HPP_INCLUDED
8 #include "libtorrent/assert.hpp"
13 class invariant_access
17 static void check_invariant(T
const& self
)
19 self
.check_invariant();
24 void check_invariant(T
const& x
)
26 invariant_access::check_invariant(x
);
29 struct invariant_checker
{};
32 struct invariant_checker_impl
: invariant_checker
34 invariant_checker_impl(T
const& self_
)
39 check_invariant(self
);
43 TORRENT_ASSERT(false);
47 ~invariant_checker_impl()
51 check_invariant(self
);
55 TORRENT_ASSERT(false);
63 invariant_checker_impl
<T
> make_invariant_checker(T
const& x
)
65 return invariant_checker_impl
<T
>(x
);
69 #if !defined NDEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
70 #define INVARIANT_CHECK \
71 invariant_checker const& _invariant_check = make_invariant_checker(*this); \
72 (void)_invariant_check; \
75 #define INVARIANT_CHECK do {} while (false)
78 #endif // TORRENT_INVARIANT_ACCESS_HPP_INCLUDED