forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSubscribeManager1.cpp
More file actions
85 lines (73 loc) · 1.29 KB
/
CSubscribeManager1.cpp
File metadata and controls
85 lines (73 loc) · 1.29 KB
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
#include "stdafx.h"
#include "CSubscribeManager1.h"
CSubscribeManager1::CSubscribeManager1()
{
}
CSubscribeManager1::~CSubscribeManager1()
{
}
set<string> CSubscribeManager1::Subscribe(set<string> ss)
{
lock_guard<mutex> cl(m_cs);
set<string> sss;
for (auto it = ss.begin(); it != ss.end(); ++it)
{
auto s = m_map.find(it->data());
if (s == m_map.end())
{
m_map.insert(pair<string, int>(it->data(), 1));
sss.insert(it->data());
}
else
{
int t = s->second + 1;
m_map[it->data()] = t;
}
}
return sss;
}
set<string> CSubscribeManager1::Unsubscribe(set<string> ss)
{
lock_guard<mutex> cl(m_cs);
set<string> sss;
for (auto it = ss.begin(); it != ss.end(); ++it)
{
auto s = m_map.find(it->data());
if (s == m_map.end())
{
// m_map.insert(pair<string, int>(it->data(), 1));
}
else
{
int t = s->second - 1;
if (t <= 0)
{
m_map.erase(it->data());
sss.insert(it->data());
}
else
{
m_map[it->data()] = t;
}
}
}
return sss;
}
set<string> CSubscribeManager1::GetInstruments()
{
lock_guard<mutex> cl(m_cs);
set<string> ss;
for (auto it = m_map.begin(); it != m_map.end(); ++it)
{
if (it->second>0)
{
ss.insert(it->first);
}
}
return ss;
}
void CSubscribeManager1::Clear()
{
lock_guard<mutex> cl(m_cs);
m_map.clear();
}