monotone

monotone Mtn Source Tree

Root/outdated_indicator.cc

1// 2007 Timothy Brownawell <tbrownaw@gmail.com>
2// GNU GPL V2 or later
3
4#include "outdated_indicator.hh"
5#include "sanity.hh"
6
7class outdated_indicator_factory_impl
8{
9 unsigned int changed;
10 unsigned int dispensed;
11public:
12 outdated_indicator_factory_impl();
13 void note_change();
14 unsigned int last_change() const;
15 unsigned int dispense();
16};
17
18outdated_indicator_factory_impl::outdated_indicator_factory_impl()
19 : changed(0), dispensed(0)
20{}
21
22unsigned int
23outdated_indicator_factory_impl::last_change() const
24{
25 return changed;
26}
27
28unsigned int
29outdated_indicator_factory_impl::dispense()
30{
31 I(changed == dispensed || changed == dispensed + 1);
32 dispensed = changed;
33 return dispensed;
34}
35
36void
37outdated_indicator_factory_impl::note_change()
38{
39 I(changed == dispensed || changed == dispensed + 1);
40 if (changed == dispensed)
41 ++changed;
42}
43
44
45outdated_indicator::outdated_indicator()
46 : parent(), when(0)
47{}
48
49outdated_indicator::outdated_indicator(boost::shared_ptr<outdated_indicator_factory_impl> p)
50 : parent(p), when(p->dispense())
51{}
52
53bool
54outdated_indicator::outdated()
55{
56 if (parent)
57 {
58 I(when <= parent->last_change());
59 return when < parent->last_change();
60 }
61 else
62 return true;
63}
64
65
66outdated_indicator_factory::outdated_indicator_factory()
67 : impl(new outdated_indicator_factory_impl)
68{}
69
70outdated_indicator_factory::~outdated_indicator_factory()
71{
72 impl->note_change();
73}
74
75outdated_indicator
76outdated_indicator_factory::get_indicator()
77{
78 return outdated_indicator(impl);
79}
80
81void
82outdated_indicator_factory::note_change()
83{
84 impl->note_change();
85}
86
87#ifdef BUILD_UNIT_TESTS
88#include "unit_tests.hh"
89
90UNIT_TEST(outdated_indicator, )
91{
92 outdated_indicator indicator;
93 {
94 outdated_indicator_factory factory;
95 BOOST_CHECK(indicator.outdated());
96 indicator = factory.get_indicator();
97 BOOST_CHECK(!indicator.outdated());
98 factory.note_change();
99 BOOST_CHECK(indicator.outdated());
100 factory.note_change();
101 factory.note_change();
102 indicator = factory.get_indicator();
103 BOOST_CHECK(!indicator.outdated());
104 }
105 BOOST_CHECK(indicator.outdated());
106}
107
108#endif
109
110
111// Local Variables:
112// mode: C++
113// fill-column: 76
114// c-file-style: "gnu"
115// indent-tabs-mode: nil
116// End:
117// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
118

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status