monotone

monotone Mtn Source Tree

Root/src/outdated_indicator.cc

1// Copyright (C) 2007 Timothy Brownawell <tbrownaw@gmail.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include "base.hh"
11#include "outdated_indicator.hh"
12#include "sanity.hh"
13
14class outdated_indicator_factory_impl
15{
16 unsigned int changed;
17 unsigned int dispensed;
18public:
19 outdated_indicator_factory_impl();
20 void note_change();
21 unsigned int last_change() const;
22 unsigned int dispense();
23};
24
25outdated_indicator_factory_impl::outdated_indicator_factory_impl()
26 : changed(0), dispensed(0)
27{}
28
29unsigned int
30outdated_indicator_factory_impl::last_change() const
31{
32 return changed;
33}
34
35unsigned int
36outdated_indicator_factory_impl::dispense()
37{
38 I(changed == dispensed || changed == dispensed + 1);
39 dispensed = changed;
40 return dispensed;
41}
42
43void
44outdated_indicator_factory_impl::note_change()
45{
46 I(changed == dispensed || changed == dispensed + 1);
47 if (changed == dispensed)
48 ++changed;
49}
50
51
52outdated_indicator::outdated_indicator()
53 : parent(), when(0)
54{}
55
56outdated_indicator::outdated_indicator(boost::shared_ptr<outdated_indicator_factory_impl> p)
57 : parent(p), when(p->dispense())
58{}
59
60bool
61outdated_indicator::outdated() const
62{
63 if (parent)
64 {
65 I(when <= parent->last_change());
66 return when < parent->last_change();
67 }
68 else
69 return true;
70}
71
72
73outdated_indicator_factory::outdated_indicator_factory()
74 : impl(new outdated_indicator_factory_impl)
75{}
76
77outdated_indicator_factory::~outdated_indicator_factory()
78{
79 impl->note_change();
80}
81
82outdated_indicator
83outdated_indicator_factory::get_indicator()
84{
85 return outdated_indicator(impl);
86}
87
88void
89outdated_indicator_factory::note_change()
90{
91 impl->note_change();
92}
93
94// Local Variables:
95// mode: C++
96// fill-column: 76
97// c-file-style: "gnu"
98// indent-tabs-mode: nil
99// End:
100// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

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