forked from berolinaro/dvbv5-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChannelList.cpp
67 lines (62 loc) · 1.88 KB
/
ChannelList.cpp
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
#include "ChannelList.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
ChannelList::ChannelList(std::string const &filename):std::map<Transponder*,std::vector<Service*>>() {
std::ifstream f(filename, std::ifstream::in);
if(!f.good())
return;
while(f.good()) {
std::string line;
if(!std::getline(f, line, '\n'))
break;
if(line[0] == '#')
continue;
if((line[0] >= 'A' && line[0] <= 'Z') || (line[0] >= 'a' && line[0] <= 'z')) {
Transponder *t = Transponder::fromString(line);
if(t)
insert(end(), make_pair(t, std::vector<Service*>()));
} else {
Service *s=new Service(line);
std::istringstream iss(line);
std::string tp;
std::getline(iss, tp, '\t');
uint32_t freq = std::stoi(tp);
for(auto &tp: *this) {
if(tp.first->frequency() == freq) {
at(tp.first).push_back(s);
break;
}
}
}
}
f.close();
}
Transponder *ChannelList::transponder(std::string const &name, std::string const &providerName) const {
for(auto const &tp: *this) {
for(auto const &s: tp.second) {
if(s->name() == name && (providerName.empty() || providerName == s->providerName()))
return tp.first;
}
}
return nullptr;
}
Service *ChannelList::service(std::string const &name, std::string const &providerName) const {
for(auto const &tp: *this) {
for(auto const &s: tp.second) {
if(s->name() == name && (providerName.empty() || providerName == s->providerName()))
return s;
}
}
return nullptr;
}
std::pair<Transponder const *,Service const *> ChannelList::find(std::string const &name, std::string const &providerName) const {
for(auto const &tp: *this) {
for(auto const &s: tp.second) {
if(s->name() == name && (providerName.empty() || providerName == s->providerName()))
return std::pair<Transponder const *,Service const *>(tp.first,s);
}
}
return std::pair<Transponder const *,Service const *>(nullptr, nullptr);
}