summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/mirandacontact.h
blob: 16d6da320dddc48ad04b564ec9bbe829c6f27393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#if !defined(HISTORYSTATS_GUARD_MIRANDACONTACT_H)
#define HISTORYSTATS_GUARD_MIRANDACONTACT_H

#include "stdafx.h"

#include <vector>
#include <list>

/*
 * MirandaContact
 */

class MirandaContact
	: private pattern::NotCopyable<MirandaContact>
{
public:
	struct EventInfo {
		MCONTACT hContact;
		DBEVENTINFO dbe;
		int nAllocated;
//		int nDuplicates;
	};

	struct ContactInfo {
		MCONTACT hContact;
		MEVENT hEvent;
		EventInfo ei;
	};

	typedef std::vector<MCONTACT> SourceHandles;

private:
	// general info
	ext::string m_strNick;
	ext::string m_strProtocol;
	ext::string m_strGroup;
	SourceHandles m_Sources;

protected:
	// reading messages
	std::vector<ContactInfo> m_CIs;
	std::list<EventInfo> m_EIs;
	std::list<EventInfo> m_SpareEIs;

private:
	// reading messages
	void stripMetaID(DBEVENTINFO& dbe);

protected:
	// reading messages
	void fetchSlot(int i);
	virtual void fillQueue() = 0;

public:
	explicit MirandaContact(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources);
	virtual ~MirandaContact();

	// general info
	const ext::string& getNick() const { return m_strNick; }
	const ext::string& getProtocol() const { return m_strProtocol; }
	const ext::string& getGroup() const { return m_strGroup; }
	const SourceHandles& getSources() const { return m_Sources; }

	// merge
	void merge(const MirandaContact& other);

	// reading messages
	void beginRead();
	void endRead();
	bool hasNext() { return !m_EIs.empty(); }
	const DBEVENTINFO& getNext() { return m_EIs.front().dbe; }
	void readNext();
};

/*
 * MirandaContactTolerantMerge
 */

class MirandaContactTolerantMerge
	: private pattern::NotCopyable<MirandaContactTolerantMerge>
	, public MirandaContact
{
protected:
	// reading message
	virtual void fillQueue();

public:
	explicit MirandaContactTolerantMerge(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources)
		: MirandaContact(strNick, strProtocol, strGroup, sources)
	{
	}
};

/*
 * MirandaContactStrictMerge
 */

class MirandaContactStrictMerge
	: private pattern::NotCopyable<MirandaContactStrictMerge>
	, public MirandaContact
{
protected:
	// reading message
	virtual void fillQueue();

public:
	explicit MirandaContactStrictMerge(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources)
		: MirandaContact(strNick, strProtocol, strGroup, sources)
	{
	}
};

/*
 * MirandaContactNoMerge
 */

class MirandaContactNoMerge
	: private pattern::NotCopyable<MirandaContactNoMerge>
	, public MirandaContact
{
protected:
	// reading message
	virtual void fillQueue();

public:
	explicit MirandaContactNoMerge(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources)
		: MirandaContact(strNick, strProtocol, strGroup, sources)
	{
	}
};

/*
 * MirandaContactFactory
 */

class MirandaContactFactory
	: public pattern::NotInstantiable<MirandaContactFactory>
{
public:
	static MirandaContact* makeMirandaContact(int MergeMode, const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const MirandaContact::SourceHandles& sources);
};

#endif // HISTORYSTATS_GUARD_MIRANDACONTACT_H