瀏覽代碼

Added Contains() & Find() to Vector, PODVector and List.

Lasse Öörni 14 年之前
父節點
當前提交
47c9319bf1
共有 3 個文件被更改,包括 74 次插入3 次删除
  1. 24 0
      Engine/Container/List.h
  2. 48 1
      Engine/Container/Vector.h
  3. 2 2
      Engine/Graphics/Batch.h

+ 24 - 0
Engine/Container/List.h

@@ -282,6 +282,30 @@ public:
             EraseNode(Head());
     }
     
+    /// Return iterator to value, or to the end if not found
+    Iterator Find(const T& value)
+    {
+        Iterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return const iterator to value, or to the end if not found
+    ConstIterator Find(const T& value) const
+    {
+        ConstIterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return whether contains a specific value
+    bool Contains(const T& value) const
+    {
+        return Find(value) != End();
+    }
+    
     /// Return iterator to the first element
     Iterator Begin() { return Iterator(Head()); }
     /// Return iterator to the first element

+ 48 - 1
Engine/Container/Vector.h

@@ -326,6 +326,30 @@ public:
         Reserve(size_);
     }
     
+    /// Return iterator to value, or to the end if not found
+    Iterator Find(const T& value)
+    {
+        Iterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return const iterator to value, or to the end if not found
+    ConstIterator Find(const T& value) const
+    {
+        ConstIterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return whether contains a specific value
+    bool Contains(const T& value) const
+    {
+        return Find(value) != End();
+    }
+    
     /// Return iterator to the beginning
     Iterator Begin() { return Iterator(Buffer()); }
     /// Return const iterator to the beginning
@@ -348,7 +372,6 @@ public:
     unsigned Capacity() const { return capacity_; }
     /// Return whether vector is empty
     bool Empty() const { return size_ == 0; }
-
     
 private:
     /// Return the buffer with right type
@@ -755,6 +778,30 @@ public:
         Reserve(size_);
     }
     
+    /// Return iterator to value, or to the end if not found
+    Iterator Find(const T& value)
+    {
+        Iterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return const iterator to value, or to the end if not found
+    ConstIterator Find(const T& value) const
+    {
+        ConstIterator i = Begin();
+        while (i != End() && *i != value)
+            ++i;
+        return i;
+    }
+    
+    /// Return whether contains a specific value
+    bool Contains(const T& value) const
+    {
+        return Find(value) != End();
+    }
+    
     /// Return iterator to the beginning
     Iterator Begin() { return Iterator(Buffer()); }
     /// Return const iterator to the beginning

+ 2 - 2
Engine/Graphics/Batch.h

@@ -84,6 +84,8 @@ struct Batch
     unsigned shaderDataSize_;
     /// Distance from camera
     float distance_;
+    /// State sorting key
+    unsigned long long sortKey_;
     /// Geometry type
     GeometryType geometryType_;
     /// Vertex shader index
@@ -92,8 +94,6 @@ struct Batch
     bool overrideView_;
     /// Priority flag
     bool hasPriority_;
-    /// State sorting key
-    unsigned long long sortKey_;
 };
 
 /// Data for one geometry instance