aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/array.h78
-rw-r--r--common/recorderfile.cpp4
-rw-r--r--common/scummsys.h4
-rw-r--r--common/str.cpp20
4 files changed, 96 insertions, 10 deletions
diff --git a/common/array.h b/common/array.h
index db1a62ba34..e9b97aa38a 100644
--- a/common/array.h
+++ b/common/array.h
@@ -361,6 +361,84 @@ protected:
};
+/**
+ * Double linked list with sorted nodes.
+ */
+template<class T>
+class SortedArray : public Array<T> {
+public:
+ typedef T *iterator;
+ typedef uint size_type;
+
+ SortedArray(int (*comparator)(const void *, const void *)) {
+ _comparator = comparator;
+ }
+
+ /**
+ * Inserts element at the sorted position.
+ */
+ void insert(const T &element) {
+ if (!this->_size) {
+ this->insert_aux(this->_storage, &element, &element + 1);
+ return;
+ }
+
+ T *where = (T *)bsearchMin(element, this->front(), this->_size, sizeof(T), _comparator);
+ insert(where, element);
+ }
+
+ T &operator[](size_type idx) {
+ error("Operation not allowed with SortedArray");
+ }
+
+ void insert_at(size_type idx, const T &element) {
+ error("Operation not allowed with SortedArray");
+ }
+
+ void insert_at(size_type idx, const Array<T> &array) {
+ error("Operation not allowed with SortedArray");
+ }
+
+ void insert(iterator pos, const T &element) {
+ error("Operation not allowed with SortedArray");
+ }
+
+ void push_back(const T &element) {
+ error("Operation not allowed with SortedArray");
+ }
+
+ void push_back(const Array<T> &array) {
+ error("Operation not allowed with SortedArray");
+ }
+
+private:
+ // Based on code Copyright (C) 2008-2009 Ksplice, Inc.
+ // Author: Tim Abbott <tabbott@ksplice.com>
+ // Licensed under GPLv2+
+ void *bsearchMin(void *key, void *base, uint num, uint size_,
+ int (*cmp)(const void *key, const void *elt)) {
+ uint start_ = 0, end_ = num;
+ int result;
+
+ while (start_ < end_) {
+ uint mid = start_ + (end_ - start_) / 2;
+
+ result = cmp(key, (byte *)base + mid * size_);
+ if (result < 0)
+ end_ = mid;
+ else if (result > 0)
+ start_ = mid + 1;
+ else
+ return (void *)((byte *)base + mid * size_);
+ }
+
+ return (void *)((byte *)base + start_ * size_);
+ }
+
+private:
+ int (*_comparator)(const void *, const void *);
+};
+
} // End of namespace Common
#endif
diff --git a/common/recorderfile.cpp b/common/recorderfile.cpp
index 71f8272b44..04802aa0c8 100644
--- a/common/recorderfile.cpp
+++ b/common/recorderfile.cpp
@@ -30,6 +30,8 @@
#include "graphics/surface.h"
#include "graphics/scaler.h"
+#ifdef ENABLE_EVENTRECORDER
+
#define RECORD_VERSION 1
namespace Common {
@@ -714,3 +716,5 @@ void PlaybackFile::checkRecordedMD5() {
}
+
+#endif // ENABLE_EVENTRECORDER
diff --git a/common/scummsys.h b/common/scummsys.h
index 5e1069fb46..3513ee2d7d 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -215,6 +215,10 @@
#include "config.h"
#endif
+// Now we need to adjust some settings when running tests
+#ifdef COMPILING_TESTS
+#undef ENABLE_EVENTRECORDER
+#endif
// In the following we configure various targets, in particular those
// which can't use our "configure" tool and hence don't use config.h.
diff --git a/common/str.cpp b/common/str.cpp
index c41e958349..3ff49a90c6 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -144,7 +144,7 @@ void String::ensureCapacity(uint32 new_size, bool keep_old) {
// Allocate new storage
newStorage = new char[newCapacity];
assert(newStorage);
-
+
// Copy old data if needed, elsewise reset the new storage.
if (keep_old) {
@@ -447,12 +447,12 @@ void String::replace(uint32 pos, uint32 count, const char *str) {
replace(pos, count, str, 0, strlen(str));
}
-void String::replace(iterator begin, iterator end, const String &str) {
- replace(begin - _str, end - begin, str._str, 0, str._size);
+void String::replace(iterator begin_, iterator end_, const String &str) {
+ replace(begin_ - _str, end_ - begin_, str._str, 0, str._size);
}
-void String::replace(iterator begin, iterator end, const char *str) {
- replace(begin - _str, end - begin, str, 0, strlen(str));
+void String::replace(iterator begin_, iterator end_, const char *str) {
+ replace(begin_ - _str, end_ - begin_, str, 0, strlen(str));
}
void String::replace(uint32 posOri, uint32 countOri, const String &str,
@@ -472,21 +472,21 @@ void String::replace(uint32 posOri, uint32 countOri, const char *str,
_size = newSize;
// Push the old characters to the end of the string
- for (uint32 i = _size; i >= posOri + countDest; i--)
+ for (uint32 i = _size; i >= posOri + countDest; i--)
_str[i] = _str[i - offset];
} else if (countOri > countDest){
uint32 offset = countOri - countDest; ///< Number of positions that we have to pull back
// Pull the remainder string back
- for (uint32 i = posOri + countDest; i < _size; i++)
- _str[i] = _str[i + offset];
+ for (uint32 i = posOri + countDest; i < _size; i++)
+ _str[i] = _str[i + offset];
- _size -= offset;
+ _size -= offset;
}
// Copy the replaced part of the string
- for (uint32 i = 0; i < countDest; i++)
+ for (uint32 i = 0; i < countDest; i++)
_str[posOri + i] = str[posDest + i];
}