PageRenderTime 25ms CodeModel.GetById 9ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/install/xbt/linux/misc/alerts.h

http://torrentpier2.googlecode.com/
C++ Header | 75 lines | 65 code | 10 blank | 0 comment | 1 complexity | 73c0ccf6ad7b1624e5b780a4341b3295 MD5 | raw file
 1#pragma once
 2
 3#include <ctime>
 4#include <list>
 5#include "stream_writer.h"
 6
 7class Calert
 8{
 9public:
10	enum t_level
11	{
12		emerg,
13		alert,
14		crit,
15		error,
16		warn,
17		notice,
18		info,
19		debug,
20	};
21
22	time_t time() const
23	{
24		return m_time;
25	}
26
27	t_level level() const
28	{
29		return m_level;
30	}
31
32	const std::string& message() const
33	{
34		return m_message;
35	}
36
37	void message(const std::string& v)
38	{
39		m_message = v;
40	}
41
42	Calert(t_level level, const std::string& message)
43	{
44		m_time = ::time(NULL);
45		m_level = level;
46		m_message = message;
47	}
48
49	Calert(t_level level, const std::string& source, const std::string& message)
50	{
51		m_time = ::time(NULL);
52		m_level = level;
53		m_message = message;
54		m_source = source;
55	}
56
57	int pre_dump() const;
58	void dump(Cstream_writer&) const;
59private:
60	time_t m_time;
61	t_level m_level;
62	std::string m_message;
63	std::string m_source;
64};
65
66class Calerts: public std::list<Calert>
67{
68public:
69	void push_back(const value_type& v)
70	{
71		std::list<value_type>::push_back(v);
72		while (size() > 250)
73			erase(begin());
74	}
75};