mirror of
https://github.com/boostorg/contract.git
synced 2026-02-26 16:42:19 +00:00
46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
|
|
#ifndef OBSERVER_HPP_
|
|
#define OBSERVER_HPP_
|
|
|
|
#include <boost/contract.hpp>
|
|
|
|
// Observer.
|
|
class observer {
|
|
public:
|
|
// No inv so contracts could have been omitted when also no pre/post...
|
|
|
|
/* Creation */
|
|
|
|
observer() { auto c = boost::contract::constructor(this); }
|
|
|
|
virtual ~observer() { auto c = boost::contract::destructor(this); }
|
|
|
|
/* Commands */
|
|
|
|
// If up-to-date with related subject.
|
|
virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0)
|
|
const = 0;
|
|
|
|
// Update this observer.
|
|
virtual void update(boost::contract::virtual_* v = 0) = 0;
|
|
|
|
private:
|
|
friend class subject;
|
|
};
|
|
|
|
bool observer::up_to_date_with_subject(boost::contract::virtual_* v) const {
|
|
auto c = boost::contract::public_function(this);
|
|
return false; // Never reached.
|
|
}
|
|
|
|
void observer::update(boost::contract::virtual_* v) {
|
|
auto c = boost::contract::public_function(this)
|
|
.postcondition([&] {
|
|
BOOST_CONTRACT_ASSERT(up_to_date_with_subject()); // Up-to-date.
|
|
})
|
|
;
|
|
}
|
|
|
|
#endif // #include guard
|
|
|