• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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
6 
7 //[mitchell02_observer
8 #ifndef OBSERVER_HPP_
9 #define OBSERVER_HPP_
10 
11 #include <boost/contract.hpp>
12 #include <cassert>
13 
14 // Observer.
15 class observer {
16     friend class subject;
17 public:
18     // No inv and no bases so contracts optional if no pre, post, and override.
19 
20     /* Creation */
21 
observer()22     observer() {
23         // Could have omitted contracts here (nothing to check).
24         boost::contract::check c = boost::contract::constructor(this);
25     }
26 
~observer()27     virtual ~observer() {
28         // Could have omitted contracts here (nothing to check).
29         boost::contract::check c = boost::contract::destructor(this);
30     }
31 
32     /* Commands */
33 
34     // If up-to-date with related subject.
35     virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0)
36             const = 0;
37 
38     // Update this observer.
39     virtual void update(boost::contract::virtual_* v = 0) = 0;
40 };
41 
up_to_date_with_subject(boost::contract::virtual_ * v) const42 bool observer::up_to_date_with_subject(boost::contract::virtual_* v) const {
43     boost::contract::check c = boost::contract::public_function(v, this);
44     assert(false);
45     return false;
46 }
47 
update(boost::contract::virtual_ * v)48 void observer::update(boost::contract::virtual_* v) {
49     boost::contract::check c = boost::contract::public_function(v, this)
50         .postcondition([&] {
51             BOOST_CONTRACT_ASSERT(up_to_date_with_subject()); // Up-to-date.
52         })
53     ;
54     assert(false);
55 }
56 
57 #endif // #include guard
58 //]
59 
60