summaryrefslogtreecommitdiff
path: root/timers.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2012-06-02 12:10:36 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2012-06-02 12:10:36 +0200
commit4e57f400967a27e9eca7632ae8a80129a065c5b5 (patch)
tree4752a0e466b4dd347e319f231f987f8d658cb830 /timers.c
parent754863902147fb87baf824db92e2073095d41386 (diff)
downloadvdr-4e57f400967a27e9eca7632ae8a80129a065c5b5.tar.gz
vdr-4e57f400967a27e9eca7632ae8a80129a065c5b5.tar.bz2
The new class cSortedTimers can be used to quickly get a list of all timers, sorted by their start time
Diffstat (limited to 'timers.c')
-rw-r--r--timers.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/timers.c b/timers.c
index a9880115..50aebb87 100644
--- a/timers.c
+++ b/timers.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: timers.c 2.8 2012/02/27 09:38:41 kls Exp $
+ * $Id: timers.c 2.9 2012/06/02 12:10:00 kls Exp $
*/
#include "timers.h"
@@ -142,7 +142,7 @@ cTimer& cTimer::operator= (const cTimer &Timer)
int cTimer::Compare(const cListObject &ListObject) const
{
- cTimer *ti = (cTimer *)&ListObject;
+ const cTimer *ti = (const cTimer *)&ListObject;
time_t t1 = StartTime();
time_t t2 = ti->StartTime();
int r = t1 - t2;
@@ -820,3 +820,18 @@ void cTimers::DeleteExpired(void)
}
lastDeleteExpired = time(NULL);
}
+
+// --- cSortedTimers ---------------------------------------------------------
+
+static int CompareTimers(const void *a, const void *b)
+{
+ return (*(const cTimer **)a)->Compare(**(const cTimer **)b);
+}
+
+cSortedTimers::cSortedTimers(void)
+:cVector(Timers.Count())
+{
+ for (const cTimer *Timer = Timers.First(); Timer; Timer = Timers.Next(Timer))
+ Append(Timer);
+ Sort(CompareTimers);
+}