mirror of
				https://github.com/vdr-projects/vdr.git
				synced 2025-03-01 10:50:46 +00:00 
			
		
		
		
	Added the functions IndexOf(), InsertUnique(), AppendUnique() and RemoveElement() to the cVector class
This commit is contained in:
		@@ -3298,3 +3298,7 @@ Dietmar Spingler <d_spingler@gmx.de>
 | 
				
			|||||||
 a CAM needs to receive the TS
 | 
					 a CAM needs to receive the TS
 | 
				
			||||||
 for reporting a problem that led to a fix with EMM pids not being properly reset for
 | 
					 for reporting a problem that led to a fix with EMM pids not being properly reset for
 | 
				
			||||||
 CAMs that need to receive the TS
 | 
					 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
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								HISTORY
									
									
									
									
									
								
							@@ -8346,3 +8346,5 @@ Video Disk Recorder Revision History
 | 
				
			|||||||
  Lars Hanisch).
 | 
					  Lars Hanisch).
 | 
				
			||||||
- Added subsystem id support for DVB devices connected via USB (thanks to Jose
 | 
					- Added subsystem id support for DVB devices connected via USB (thanks to Jose
 | 
				
			||||||
  Alberto Reguero).
 | 
					  Alberto Reguero).
 | 
				
			||||||
 | 
					- Added the functions IndexOf(), InsertUnique(), AppendUnique() and RemoveElement()
 | 
				
			||||||
 | 
					  to the cVector class (thanks to Stefan Schallenberg).
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								tools.h
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								tools.h
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
 * See the main source file 'vdr.c' for copyright information and
 | 
					 * See the main source file 'vdr.c' for copyright information and
 | 
				
			||||||
 * how to reach the author.
 | 
					 * 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
 | 
					#ifndef __TOOLS_H
 | 
				
			||||||
@@ -537,6 +537,14 @@ public:
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    return At(Index);
 | 
					    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; }
 | 
					  int Size(void) const { return size; }
 | 
				
			||||||
  virtual void Insert(T Data, int Before = 0)
 | 
					  virtual void Insert(T Data, int Before = 0)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
@@ -549,18 +557,34 @@ public:
 | 
				
			|||||||
    else
 | 
					    else
 | 
				
			||||||
       Append(Data);
 | 
					       Append(Data);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  void InsertUnique(T Data, int Before = 0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (IndexOf(Data) < 0)
 | 
				
			||||||
 | 
					       Insert(Data, Before);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  virtual void Append(T Data)
 | 
					  virtual void Append(T Data)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    if (size >= allocated)
 | 
					    if (size >= allocated)
 | 
				
			||||||
       Realloc(allocated * 3 / 2); // increase size by 50%
 | 
					       Realloc(allocated * 3 / 2); // increase size by 50%
 | 
				
			||||||
    data[size++] = Data;
 | 
					    data[size++] = Data;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  void AppendUnique(T Data)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (IndexOf(Data) < 0)
 | 
				
			||||||
 | 
					       Append(Data);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  virtual void Remove(int Index)
 | 
					  virtual void Remove(int Index)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    if (Index < size - 1)
 | 
					    if (Index < size - 1)
 | 
				
			||||||
       memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T));
 | 
					       memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T));
 | 
				
			||||||
    size--;
 | 
					    size--;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  void RemoveElement(const T &Data)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    int i = IndexOf(Data);
 | 
				
			||||||
 | 
					    if (i >= 0)
 | 
				
			||||||
 | 
					       Remove(i);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  virtual void Clear(void)
 | 
					  virtual void Clear(void)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    for (int i = 0; i < size; i++)
 | 
					    for (int i = 0; i < size; i++)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user