-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.h
89 lines (76 loc) · 1.88 KB
/
object.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _object_h
#define _object_h
#include <vdr/tools.h>
class cPulseObject : public cListObject {
private:
uint32_t _index;
cString _name;
public:
cPulseObject(uint32_t index, const char *name)
:_index(index)
,_name(name)
{
}
cPulseObject(const cPulseObject &object)
:_index(object.Index())
,_name(object.Name())
{
}
virtual ~cPulseObject(void)
{
}
uint32_t Index() const { return _index; }
const char *Name() const { return *_name; }
void SetName(const char *name)
{
_name = name;
}
virtual int Compare(const cListObject &ListObject) const
{
const cPulseObject &rhs = (const cPulseObject&)ListObject;
return strcmp(Name(), rhs.Name());
}
virtual cString MenuItemText(void) const
{
return cString::sprintf("%d - %s", _index, *_name);
}
};
template<class T> class cListHelper {
public:
static void Copy(const cList<T> &src, cList<T> &dst)
{
dst.Clear();
for (const T *o = src.First(); o; o = src.Next(o))
dst.Add(new T(*o));
}
static const T *Find(const cList<T> &list, uint32_t index)
{
for (const T *o = list.First(); o; o = list.Next(o)) {
const cPulseObject *obj = static_cast<const cPulseObject*>(o);
if (obj->Index() == index)
return o;
}
return NULL;
}
static T *Find(cList<T> &list, uint32_t index)
{
for (T *o = list.First(); o; o = list.Next(o)) {
cPulseObject *obj = static_cast<cPulseObject*>(o);
if (obj->Index() == index)
return o;
}
return NULL;
}
static const T *Find(const cList<T> &list, const char *name)
{
if (name) {
for (const T *o = list.First(); o; o = list.Next(o)) {
const cPulseObject *obj = static_cast<const cPulseObject*>(o);
if (strcasecmp(obj->Name(), name) == 0)
return o;
}
}
return NULL;
}
};
#endif