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
|
#include <string>
#include <boost/shared_ptr.hpp>
#include "recordings.h"
namespace vdrlive {
RecordingsTree::RecordingsTree() :
m_maxLevel(0),
m_root(new RecordingsItemDir()),
m_recordingsLock(&Recordings)
{
for ( cRecording* recording = Recordings.First(); recording != 0; recording = Recordings.Next( recording ) ) {
if (m_maxLevel < recording->HierarchyLevels()) {
m_maxLevel = recording->HierarchyLevels();
}
RecordingsItemPtr dir = m_root;
string name(recording->Name());
int level = 0;
size_t index = 0;
size_t pos = 0;
do {
pos = name.find('~', index);
if (pos != string::npos) {
string dirName(name.substr(index, pos - index));
index = pos + 1;
Map::iterator i = dir->m_entries.find(dirName);
if (i == dir->m_entries.end()) {
RecordingsItemPtr recPtr (new RecordingsItemDir(dirName, level));
dir->m_entries[dirName] = recPtr;
}
dir = dir->m_entries[dirName];
level++;
}
else {
string dirName(name.substr(index, name.length() - index));
RecordingsItemPtr recPtr (new RecordingsItemRec(dirName, recording));
dir->m_entries[dirName] = recPtr;
}
} while (pos != string::npos);
}
}
RecordingsTree::~RecordingsTree()
{
}
RecordingsTree::Map::iterator RecordingsTree::begin(const vector< string >& path)
{
if (path.empty()) {
return m_root->m_entries.begin();
}
RecordingsItemPtr recItem = m_root;
for (vector< string >::const_iterator i = path.begin(); i != path.end(); ++i)
{
recItem = recItem->m_entries[*i];
}
return recItem->m_entries.begin();
}
RecordingsTree::Map::iterator RecordingsTree::end(const vector< string >&path)
{
if (path.empty()) {
return m_root->m_entries.end();
}
RecordingsItemPtr recItem = m_root;
for (vector< string >::const_iterator i = path.begin(); i != path.end(); ++i)
{
recItem = recItem->m_entries[*i];
}
return recItem->m_entries.end();
}
RecordingsTree::RecordingsItem::RecordingsItem(const string& name) :
m_name(name),
m_entries()
{
}
RecordingsTree::RecordingsItem::~RecordingsItem()
{
}
RecordingsTree::RecordingsItemDir::RecordingsItemDir() :
RecordingsItem(""),
m_level(0)
{
}
RecordingsTree::RecordingsItemDir::~RecordingsItemDir()
{
}
RecordingsTree::RecordingsItemDir::RecordingsItemDir(const string& name, int level) :
RecordingsItem(name),
m_level(level)
{
}
RecordingsTree::RecordingsItemRec::RecordingsItemRec(const string& name, cRecording* recording) :
RecordingsItem(name),
m_recording(recording)
{
}
RecordingsTree::RecordingsItemRec::~RecordingsItemRec()
{
}
time_t RecordingsTree::RecordingsItemRec::StartTime() const
{
return m_recording->start;
}
} // namespace vdrlive
|