summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c91
1 files changed, 78 insertions, 13 deletions
diff --git a/tools.c b/tools.c
index 28ea2af..5561216 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.91 2005/03/20 14:44:33 kls Exp $
+ * $Id: tools.c 1.95 2005/05/29 10:18:26 kls Exp $
*/
#include "tools.h"
@@ -571,6 +571,25 @@ cString TimeToString(time_t t)
return "???";
}
+cString DateString(time_t t)
+{
+ char buf[32];
+ struct tm tm_r;
+ tm *tm = localtime_r(&t, &tm_r);
+ char *p = stpcpy(buf, WeekDayName(tm->tm_wday));
+ *p++ = ' ';
+ strftime(p, sizeof(buf) - (p - buf), "%d.%m.%Y", tm);
+ return buf;
+}
+
+cString TimeString(time_t t)
+{
+ char buf[25];
+ struct tm tm_r;
+ strftime(buf, sizeof(buf), "%R", localtime_r(&t, &tm_r));
+ return buf;
+}
+
// --- cReadLine -------------------------------------------------------------
char *cReadLine::Read(FILE *f)
@@ -913,6 +932,7 @@ int cListObject::Index(void) const
cListBase::cListBase(void)
{
objects = lastObject = NULL;
+ count = 0;
}
cListBase::~cListBase()
@@ -933,6 +953,7 @@ void cListBase::Add(cListObject *Object, cListObject *After)
objects = Object;
lastObject = Object;
}
+ count++;
}
void cListBase::Ins(cListObject *Object, cListObject *Before)
@@ -948,6 +969,7 @@ void cListBase::Ins(cListObject *Object, cListObject *Before)
lastObject = Object;
objects = Object;
}
+ count++;
}
void cListBase::Del(cListObject *Object, bool DeleteObject)
@@ -959,6 +981,7 @@ void cListBase::Del(cListObject *Object, bool DeleteObject)
Object->Unlink();
if (DeleteObject)
delete Object;
+ count--;
}
void cListBase::Move(int From, int To)
@@ -998,6 +1021,7 @@ void cListBase::Clear(void)
objects = object;
}
objects = lastObject = NULL;
+ count = 0;
}
cListObject *cListBase::Get(int Index) const
@@ -1010,18 +1034,6 @@ cListObject *cListBase::Get(int Index) const
return object;
}
-int cListBase::Count(void) const
-{
- int n = 0;
- cListObject *object = objects;
-
- while (object) {
- n++;
- object = object->Next();
- }
- return n;
-}
-
static int CompareListObjects(const void *a, const void *b)
{
const cListObject *la = *(const cListObject **)a;
@@ -1043,7 +1055,60 @@ void cListBase::Sort(void)
objects = lastObject = NULL;
for (i = 0; i < n; i++) {
a[i]->Unlink();
+ count--;
Add(a[i]);
}
}
+// --- cHashBase -------------------------------------------------------------
+
+cHashBase::cHashBase(int Size)
+{
+ size = Size;
+ hashTable = (cList<cHashObject>**)calloc(size, sizeof(cList<cHashObject>*));
+}
+
+cHashBase::~cHashBase(void)
+{
+ for (int i = 0; i < size; i++)
+ delete hashTable[i];
+ free(hashTable);
+}
+
+void cHashBase::Add(cListObject *Object, unsigned int Id)
+{
+ unsigned int hash = hashfn(Id);
+ if (!hashTable[hash])
+ hashTable[hash] = new cList<cHashObject>;
+ hashTable[hash]->Add(new cHashObject(Object, Id));
+}
+
+void cHashBase::Del(cListObject *Object, unsigned int Id)
+{
+ cList<cHashObject> *list = hashTable[hashfn(Id)];
+ if (list) {
+ for (cHashObject *hob = list->First(); hob; hob = list->Next(hob)) {
+ if (hob->object == Object) {
+ list->Del(hob);
+ break;
+ }
+ }
+ }
+}
+
+cListObject *cHashBase::Get(unsigned int Id) const
+{
+ cList<cHashObject> *list = hashTable[hashfn(Id)];
+ if (list) {
+ for (cHashObject *hob = list->First(); hob; hob = list->Next(hob)) {
+ if (hob->id == Id)
+ return hob->object;
+ }
+ }
+ return NULL;
+}
+
+cList<cHashObject> *cHashBase::GetList(unsigned int Id) const
+{
+ return hashTable[hashfn(Id)];
+}