summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-12-20 17:09:44 +0000
committerfrosch <frosch@openttd.org>2008-12-20 17:09:44 +0000
commit5ea2dc97fd300fb7ca636a97b9f0f595574d7cae (patch)
treea1ff9bbe6aaf14771c0501bc41ad3042bfa74b19 /src/core
parent8db5bda4f795a43ed36e3ce47e13feeca8da99ee (diff)
downloadopenttd-5ea2dc97fd300fb7ca636a97b9f0f595574d7cae.tar.xz
(svn r14704) -Codechange: Add set capabilities to SmallVector.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/smallvec_type.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index 464274c4d..a7a0fbad4 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -81,6 +81,58 @@ public:
}
/**
+ * Search for the first occurence of an item.
+ * The '!=' operator of T is used for comparison.
+ * @param item Item to search for
+ * @return The position of the item, or End() when not present
+ */
+ FORCEINLINE const T *Find(const T &item) const
+ {
+ const T *pos = this->Begin();
+ const T *end = this->End();
+ while (pos != end && *pos != item) pos++;
+ return pos;
+ }
+
+ /**
+ * Search for the first occurence of an item.
+ * The '!=' operator of T is used for comparison.
+ * @param item Item to search for
+ * @return The position of the item, or End() when not present
+ */
+ FORCEINLINE T *Find(const T &item)
+ {
+ T *pos = this->Begin();
+ const T *end = this->End();
+ while (pos != end && *pos != item) pos++;
+ return pos;
+ }
+
+ /**
+ * Tests whether a item is present in the vector.
+ * The '!=' operator of T is used for comparison.
+ * @param item Item to test for
+ * @return true iff the item is present
+ */
+ FORCEINLINE bool Contains(const T &item) const
+ {
+ return this->Find(item) != this->End();
+ }
+
+ /**
+ * 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
+ * @return true iff the item is was already present
+ */
+ FORCEINLINE bool Include(const T &item)
+ {
+ bool is_member = this->Contains(item);
+ if (!is_member) *this->Append() = item;
+ return is_member;
+ }
+
+ /**
* Get the number of items in the list.
*/
FORCEINLINE uint Length() const