summaryrefslogtreecommitdiff
path: root/src/core/smallvec_type.hpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-02-24 16:43:24 +0000
committerfrosch <frosch@openttd.org>2013-02-24 16:43:24 +0000
commit5cd5aca98c10fbf566d5c67bb2de4195db04ca01 (patch)
tree7dd2eb60bd6d7befe9f87606de98213945007882 /src/core/smallvec_type.hpp
parentb9aeb050e1372c8bc42c59f53e1a760bcae097af (diff)
downloadopenttd-5cd5aca98c10fbf566d5c67bb2de4195db04ca01.tar.xz
(svn r25043) -Change [FS#3764]: Only display subtypes in the refit GUI which are available for all selected vehicles. Also add a generic list item to refit while keeping the subtypes of individual vehicles.
Diffstat (limited to 'src/core/smallvec_type.hpp')
-rw-r--r--src/core/smallvec_type.hpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index ccf8dbaec..62de176a5 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -145,6 +145,20 @@ public:
}
/**
+ * Set the size of the vector, effectively truncating items from the end or appending uninitialised ones.
+ * @param num_items Target size.
+ */
+ inline void Resize(uint num_items)
+ {
+ this->items = num_items;
+
+ if (this->items > this->capacity) {
+ this->capacity = Align(this->items, S);
+ this->data = ReallocT(this->data, this->capacity);
+ }
+ }
+
+ /**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
* @param item Item to search for
@@ -213,6 +227,21 @@ public:
}
/**
+ * Remove items from the vector while preserving the order of other items.
+ * @param pos First item to remove.
+ * @param count Number of consecutive items to remove.
+ */
+ void ErasePreservingOrder(uint pos, uint count = 1)
+ {
+ if (count == 0) return;
+ assert(pos < this->items);
+ assert(pos + count <= this->items);
+ this->items -= count;
+ uint to_move = this->items - pos;
+ if (to_move > 0) MemMoveT(this->data + pos, this->data + pos + count, to_move);
+ }
+
+ /**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.
* @param item Item to test for