diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2000-02-19 13:36:48 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2000-02-19 13:36:48 +0100 |
commit | 4a9d9c5876cde9f21ccd165a7630727e6aca576a (patch) | |
tree | 84548734048499e913f200e1359acec4fa441fb0 /tools.c | |
download | vdr-4a9d9c5876cde9f21ccd165a7630727e6aca576a.tar.gz vdr-4a9d9c5876cde9f21ccd165a7630727e6aca576a.tar.bz2 |
Initial revision0.0.1
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/tools.c b/tools.c new file mode 100644 index 00000000..e0eeaefd --- /dev/null +++ b/tools.c @@ -0,0 +1,124 @@ +/* + * tools.c: Various tools + * + * See the main source file 'osm.c' for copyright information and + * how to reach the author. + * + * $Id: tools.c 1.1 2000/02/19 13:36:48 kls Exp $ + */ + +#include "tools.h" +#include <stdlib.h> +#include <sys/time.h> + +int time_ms(void) +{ + struct timeval t; + if (gettimeofday(&t, NULL) == 0) + return t.tv_sec * 1000 + t.tv_usec / 1000; + return 0; +} + +// --- cListObject ----------------------------------------------------------- + +cListObject::cListObject(void) +{ + prev = next = NULL; +} + +cListObject::~cListObject() +{ +} + +void cListObject::Append(cListObject *Object) +{ + next = Object; + Object->prev = this; +} + +void cListObject::Unlink(void) +{ + if (next) + next->prev = prev; + if (prev) + prev->next = next; +} + +int cListObject::Index(void) +{ + cListObject *p = prev; + int i = 0; + + while (p) { + i++; + p = p->prev; + } + return i; +} + +// --- cListBase ------------------------------------------------------------- + +cListBase::cListBase(void) +{ + objects = lastObject = NULL; +} + +cListBase::~cListBase() +{ + Clear(); + while (objects) { + cListObject *object = objects->Next(); + delete objects; + objects = object; + } +} + +void cListBase::Add(cListObject *Object) +{ + if (lastObject) + lastObject->Append(Object); + else + objects = Object; + lastObject = Object; +} + +void cListBase::Del(cListObject *Object) +{ + if (Object == objects) + objects = Object->Next(); + if (Object == lastObject) + lastObject = Object->Prev(); + Object->Unlink(); + delete Object; +} + +void cListBase::Clear(void) +{ + while (objects) { + cListObject *object = objects->Next(); + delete objects; + objects = object; + } + objects = lastObject = NULL; +} + +cListObject *cListBase::Get(int Index) +{ + cListObject *object = objects; + while (object && Index-- > 0) + object = object->Next(); + return object; +} + +int cListBase::Count(void) +{ + int n = 0; + cListObject *object = objects; + + while (object) { + n++; + object = object->Next(); + } + return n; +} + |