Refactored cSatipPid for upcoming API changes.

This commit is contained in:
Rolf Ahrenberg 2015-01-14 20:51:16 +02:00
parent 266aadb999
commit 09e6c272cd
1 changed files with 28 additions and 13 deletions

41
tuner.h
View File

@ -8,6 +8,7 @@
#ifndef __SATIP_TUNER_H #ifndef __SATIP_TUNER_H
#define __SATIP_TUNER_H #define __SATIP_TUNER_H
#include <vdr/config.h> // APIVERSNUM
#include <vdr/thread.h> #include <vdr/thread.h>
#include <vdr/tools.h> #include <vdr/tools.h>
@ -20,7 +21,14 @@
class cSatipPid : public cVector<int> { class cSatipPid : public cVector<int> {
private: private:
int PidIndex(const int &pidP) static int PidCompare(const void *aPidP, const void *bPidP)
{
return (*(int*)aPidP - *(int*)bPidP);
}
public:
#if defined(APIVERSNUM) && APIVERSNUM < 20107
int IndexOf(const int &pidP)
{ {
for (int i = 0; i < Size(); ++i) { for (int i = 0; i < Size(); ++i) {
if (pidP == At(i)) if (pidP == At(i))
@ -28,26 +36,33 @@ private:
} }
return -1; return -1;
} }
static int PidCompare(const void *aPidP, const void *bPidP) bool RemoveElement(const int &pidP)
{ {
return (*(int*)aPidP - *(int*)bPidP); int i = IndexOf(pidP);
}
public:
void RemovePid(const int &pidP)
{
int i = PidIndex(pidP);
if (i >= 0) { if (i >= 0) {
Remove(i); Remove(i);
Sort(PidCompare); return true;
} }
return false;
}
bool AppendUnique(int pidP)
{
if (IndexOf(pidP) < 0) {
Append(pidP);
return true;
}
return false;
}
#endif
void RemovePid(const int &pidP)
{
if (RemoveElement(pidP))
Sort(PidCompare);
} }
void AddPid(int pidP) void AddPid(int pidP)
{ {
if (PidIndex(pidP) < 0) { if (AppendUnique(pidP))
Append(pidP);
Sort(PidCompare); Sort(PidCompare);
}
} }
cString ListPids(void) cString ListPids(void)
{ {