1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added the functions IndexOf(), InsertUnique(), AppendUnique() and RemoveElement() to the cVector class

This commit is contained in:
Klaus Schmidinger 2015-01-12 12:10:15 +01:00
parent 6514649439
commit 6e35f47a3e
3 changed files with 31 additions and 1 deletions

View File

@ -3298,3 +3298,7 @@ Dietmar Spingler <d_spingler@gmx.de>
a CAM needs to receive the TS
for reporting a problem that led to a fix with EMM pids not being properly reset for
CAMs that need to receive the TS
Stefan Schallenberg <infos@nafets.de>
for adding the functions IndexOf(), InsertUnique(), AppendUnique() and RemoveElement()
to the cVector class

View File

@ -8346,3 +8346,5 @@ Video Disk Recorder Revision History
Lars Hanisch).
- Added subsystem id support for DVB devices connected via USB (thanks to Jose
Alberto Reguero).
- Added the functions IndexOf(), InsertUnique(), AppendUnique() and RemoveElement()
to the cVector class (thanks to Stefan Schallenberg).

26
tools.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 3.3 2013/09/22 13:30:14 kls Exp $
* $Id: tools.h 3.4 2015/01/12 12:03:59 kls Exp $
*/
#ifndef __TOOLS_H
@ -537,6 +537,14 @@ public:
{
return At(Index);
}
int IndexOf(const T &Data) // returns the index of Data, or -1 if not found
{
for (int i = 0; i < size; i++) {
if (data[i] == Data)
return i;
}
return -1;
}
int Size(void) const { return size; }
virtual void Insert(T Data, int Before = 0)
{
@ -549,18 +557,34 @@ public:
else
Append(Data);
}
void InsertUnique(T Data, int Before = 0)
{
if (IndexOf(Data) < 0)
Insert(Data, Before);
}
virtual void Append(T Data)
{
if (size >= allocated)
Realloc(allocated * 3 / 2); // increase size by 50%
data[size++] = Data;
}
void AppendUnique(T Data)
{
if (IndexOf(Data) < 0)
Append(Data);
}
virtual void Remove(int Index)
{
if (Index < size - 1)
memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T));
size--;
}
void RemoveElement(const T &Data)
{
int i = IndexOf(Data);
if (i >= 0)
Remove(i);
}
virtual void Clear(void)
{
for (int i = 0; i < size; i++)