Browse Source

Merge pull request #553 from signmotion/add-vector-reverse

Added method Vector::reverse().
Thomas Fischer 11 years ago
parent
commit
32abd2c149
1 changed files with 10 additions and 0 deletions
  1. 10 0
      Engine/source/core/util/tVector.h

+ 10 - 0
Engine/source/core/util/tVector.h

@@ -28,6 +28,7 @@
 #ifndef _PLATFORM_H_
 #ifndef _PLATFORM_H_
 #include "platform/platform.h"
 #include "platform/platform.h"
 #endif
 #endif
+#include <algorithm>
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // Helper definitions for the vector class.
 // Helper definitions for the vector class.
@@ -181,6 +182,9 @@ class Vector
    ///
    ///
    void merge( const T *addr, U32 count );
    void merge( const T *addr, U32 count );
 
 
+   // Reverses the order of elements.
+   void reverse();
+
    /// @}
    /// @}
 };
 };
 
 
@@ -760,6 +764,12 @@ template<class T> inline void Vector<T>::merge( const T *addr, U32 count )
    mElementCount = newSize;
    mElementCount = newSize;
 }
 }
 
 
+template<class T> inline void Vector<T>::reverse()
+{
+   for (U32 i = 0, j = size();  (i != j) && (i != --j);  ++i)
+      std::swap( mArray[ i ],  mArray[ j ] );
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 /// Template for vectors of pointers.
 /// Template for vectors of pointers.
 template <class T>
 template <class T>