goo/GooList.cc | 22 ++++++++++++++++++++++ goo/GooList.h | 10 ++++++++++ 2 files changed, 32 insertions(+)
New commits: commit e7e8082901e108130d5c98cc7648f143978c9562 Author: Albert Astals Cid <[email protected]> Date: Tue Aug 30 20:50:17 2011 +0200 xpdf303: GooList::copy, GooList::reverse and GooList::put diff --git a/goo/GooList.cc b/goo/GooList.cc index a7243ea..6ce4952 100644 --- a/goo/GooList.cc +++ b/goo/GooList.cc @@ -39,6 +39,16 @@ GooList::~GooList() { gfree(data); } +GooList *GooList::copy() { + GooList *ret; + + ret = new GooList(length); + ret->length = length; + memcpy(ret->data, data, length * sizeof(void *)); + ret->inc = inc; + return ret; +} + void GooList::append(void *p) { if (length >= size) { expand(); @@ -89,6 +99,18 @@ void GooList::sort(int (*cmp)(const void *obj1, const void *obj2)) { qsort(data, length, sizeof(void *), cmp); } +void GooList::reverse() { + void *t; + int n, i; + + n = length / 2; + for (i = 0; i < n; ++i) { + t = data[i]; + data[i] = data[length - 1 - i]; + data[length - 1 - i] = t; + } +} + void GooList::expand() { size += (inc > 0) ? inc : size; data = (void **)greallocn(data, size, sizeof(void*)); diff --git a/goo/GooList.h b/goo/GooList.h index 576f3e8..964568a 100644 --- a/goo/GooList.h +++ b/goo/GooList.h @@ -36,12 +36,19 @@ public: // Get the number of elements. int getLength() { return length; } + // Returns a (shallow) copy of this list. + GooList *copy(); + //----- ordered list support // Return the <i>th element. // Assumes 0 <= i < length. void *get(int i) { return data[i]; } + // Replace the <i>th element. + // Assumes 0 <= i < length. + void put(int i, void *p) { data[i] = p; } + // Append an element to the end of the list. void append(void *p); @@ -61,6 +68,9 @@ public: // be double-dereferenced. void sort(int (*cmp)(const void *ptr1, const void *ptr2)); + // Reverse the list. + void reverse(); + //----- control // Set allocation increment to <inc>. If inc > 0, that many _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
