-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessagemap.h
73 lines (52 loc) · 2.11 KB
/
messagemap.h
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
#ifndef MESSAGEMAP_H
#define MESSAGEMAP_H
#include <QDebug>
#include <map>
#include <QString>
#include "notifyenums.h"
// # TODO LIST #
// 1. QSingleShot to erase deprecated alerts
// 2. Method to store actual number how many given type messages are there
// 3. Own for_each friend function to send data
namespace IDGenerator{ // generate unique ID for erasing objects
QByteArray generateUniqueID(){
return QByteArray();
}
}
template<typename MType, typename MAlert>
class MessageMap
{
public:
using messPair = std::pair<MType, MAlert>;
using initList = std::initializer_list<std::pair<const MType, MAlert>>;
using mapIter = typename std::multimap<MType,MAlert>::iterator;
MessageMap() {}
MessageMap(const std::multimap<MType, MAlert>& cpyMessage): messages(cpyMessage) {}
MessageMap(const initList& initMessages): messages(initMessages) {}
MessageMap(const mapIter& first, const mapIter& last): messages(first, last) {}
MessageMap(const MessageMap<MType, MAlert>& mMap): messages(mMap.messages) {}
MessageMap<MType, MAlert>& operator=(const MessageMap<MType, MAlert>& mMap);
mapIter insertMessage(const messPair& mPair); // give unique ID to del
mapIter insertMessage(const MType& fType, const MAlert& mAlert);
bool contains(const messPair& conMessage);
bool contains(const MType& fType, const MAlert& mAlert);
mapIter findByKey(const MType& key);
mapIter findByValue(const MAlert& value);
mapIter findByMessage(const messPair& message);
size_t uniqueKeyCount(const MType& key); // how many massages of given 'key' are contained
size_t size() const;
//MAlert& operator[](const MType& key);
friend QDebug operator<<(QDebug debug, const MessageMap& mMap);
private:
std::multimap<MType, MAlert> messages;
};
template<typename MType, typename MAlert>
MessageMap<MType, MAlert>& MessageMap<MType, MAlert>::operator=(const MessageMap<MType, MAlert>& mMap){
if(this == &mMap)
return *this;
// send deprecated datas to frontend
messages.clear();
messages = mMap.messages;
return *this;
}
#endif // MESSAGEMAP_H