summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-25 16:12:13 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-25 16:12:13 +0000
commitbcd05a4bcebb6a89fe73cd6c35a119cf70373c84 (patch)
tree0f76f6fdcba28b90a10723f0c23c8155fddc3822 /src/misc
parent8d51e95c44f9d2b4338675f431098ce24c7690c0 (diff)
downloadopenttd-bcd05a4bcebb6a89fe73cd6c35a119cf70373c84.tar.xz
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/smallvec.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/misc/smallvec.h b/src/misc/smallvec.h
index 984d634ac..7f85cc96a 100644
--- a/src/misc/smallvec.h
+++ b/src/misc/smallvec.h
@@ -19,6 +19,29 @@ struct SmallVector {
}
/**
+ * Remove all items from the list.
+ */
+ void Clear()
+ {
+ /* In fact we just reset the item counter avoiding the need to
+ * probably reallocate the same amount of memory the list was
+ * previously using. */
+ this->items = 0;
+ }
+
+ /**
+ * Compact the list down to the smallest block size boundary.
+ */
+ void Compact()
+ {
+ uint capacity = Align(this->items, S);
+ if (capacity >= this->capacity) return;
+
+ this->capacity = capacity;
+ this->data = ReallocT(this->data, this->capacity);
+ }
+
+ /**
* Append an item and return it.
*/
T *Append()
@@ -31,6 +54,14 @@ struct SmallVector {
return &this->data[this->items++];
}
+ /**
+ * Get the number of items in the list.
+ */
+ uint Length() const
+ {
+ return this->items;
+ }
+
const T *Begin() const
{
return this->data;
@@ -60,6 +91,16 @@ struct SmallVector {
{
return &this->data[index];
}
+
+ const T &operator[](uint index) const
+ {
+ return this->data[index];
+ }
+
+ T &operator[](uint index)
+ {
+ return this->data[index];
+ }
};
#endif /* SMALLVEC_H */