2 // Copyright (C) 2008-2018 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0 (see accompanying
4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
7 //[mitchell02_push_button
8 #ifndef PUSH_BUTTON_HPP_
9 #define PUSH_BUTTON_HPP_
11 #include <boost/contract.hpp>
16 // No inv and no bases so contracts optional if no pre, post, and override.
20 // Create an enabled button.
21 push_button() : enabled_(true) {
22 boost::contract::check c = boost::contract::constructor(this)
24 BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
30 virtual ~push_button() {
31 // Could have omitted contracts here (nothing to check).
32 boost::contract::check c = boost::contract::destructor(this);
37 // If button is enabled.
38 bool enabled() const {
39 // Could have omitted contracts here (nothing to check).
40 boost::contract::check c = boost::contract::public_function(this);
48 boost::contract::check c = boost::contract::public_function(this)
50 BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
59 boost::contract::check c = boost::contract::public_function(this)
61 BOOST_CONTRACT_ASSERT(!enabled()); // Disabled.
68 // Invoke externally when button clicked.
69 virtual void on_bn_clicked(boost::contract::virtual_* v = 0) = 0;
75 void push_button::on_bn_clicked(boost::contract::virtual_* v) {
76 boost::contract::check c = boost::contract::public_function(v, this)
78 BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
84 #endif // #include guard