monotone

monotone Mtn Source Tree

Root/ui.hh

1#ifndef __UI_HH__
2#define __UI_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9// this file contains a couple utilities to deal with the user
10// interface. the global user_interface object 'ui' owns cerr, so
11// no writing to it directly!
12
13#include <map>
14#include <set>
15#include <string>
16#include <boost/format.hpp>
17
18struct user_interface;
19
20struct ticker
21{
22 size_t ticks;
23 size_t mod;
24 std::string name;
25 std::string shortname;
26 ticker(std::string const & n, std::string const & s, size_t mod = 64);
27 void operator++();
28 void operator+=(size_t t);
29 ~ticker();
30};
31
32struct tick_writer
33{
34public:
35 tick_writer() {}
36 virtual ~tick_writer() {}
37 virtual void write_ticks() = 0;
38};
39
40struct tick_write_count : virtual public tick_writer
41{
42public:
43 tick_write_count();
44 ~tick_write_count();
45 void write_ticks();
46private:
47 size_t last_tick_len;
48};
49
50struct tick_write_dot : virtual public tick_writer
51{
52public:
53 tick_write_dot();
54 ~tick_write_dot();
55 void write_ticks();
56private:
57 std::map<std::string,size_t> last_ticks;
58};
59
60struct tick_write_nothing : virtual public tick_writer
61{
62public:
63 void write_ticks() {}
64};
65
66struct user_interface
67{
68public:
69 user_interface();
70 ~user_interface();
71 void warn(std::string const & warning);
72 void warn(boost::format const & fmt) { warn(fmt.str()); }
73 void fatal(std::string const & warning);
74 void fatal(boost::format const & fmt) { warn(fmt.str()); }
75 void inform(std::string const & line);
76 void inform(boost::format const & fmt) { inform(fmt.str()); }
77 void set_tick_trailer(std::string const & trailer);
78 void set_tick_writer(tick_writer * t_writer);
79 void ensure_clean_line();
80
81private:
82 std::set<std::string> issued_warnings;
83
84 bool some_tick_is_dirty; // At least one tick needs being printed
85 bool last_write_was_a_tick;
86 std::map<std::string,ticker *> tickers;
87 tick_writer * t_writer;
88 void finish_ticking();
89 void write_ticks();
90 std::string tick_trailer;
91
92 friend struct tick_write_dot;
93 friend struct tick_write_count;
94 friend struct ticker;
95};
96
97extern struct user_interface ui;
98
99
100#endif // __UI_HH__

Archive Download this file

Branches

Tags

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