Browse Source

Added specialization for string swap.

Lasse Öörni 14 years ago
parent
commit
d422219671

+ 12 - 0
Engine/Core/CoreString.cpp

@@ -224,6 +224,13 @@ void String::Clear()
     Resize(0);
     Resize(0);
 }
 }
 
 
+void String::Swap(String& str)
+{
+    ::Swap(length_, str.length_);
+    ::Swap(capacity_, str.capacity_);
+    ::Swap(buffer_, str.buffer_);
+}
+
 String String::Substring(unsigned pos) const
 String String::Substring(unsigned pos) const
 {
 {
     if (pos >= length_)
     if (pos >= length_)
@@ -402,3 +409,8 @@ void String::Replace(unsigned pos, unsigned length, const char* srcStart, unsign
     
     
     CopyChars(buffer_ + pos, srcStart, srcLength);
     CopyChars(buffer_ + pos, srcStart, srcLength);
 }
 }
+
+template<> void Swap<String>(String& first, String& second)
+{
+    first.Swap(second);
+}

+ 3 - 0
Engine/Core/CoreString.h

@@ -24,6 +24,7 @@
 #pragma once
 #pragma once
 
 
 #include "Iterator.h"
 #include "Iterator.h"
+#include "Swap.h"
 
 
 #include <cstring>
 #include <cstring>
 #include <ctype.h>
 #include <ctype.h>
@@ -257,6 +258,8 @@ public:
     void Compact();
     void Compact();
     /// Clear the string
     /// Clear the string
     void Clear();
     void Clear();
+    /// Swap with another string
+    void Swap(String& str);
     
     
     /// Return iterator to the beginning
     /// Return iterator to the beginning
     Iterator Begin() { return Iterator(buffer_); }
     Iterator Begin() { return Iterator(buffer_); }

+ 1 - 1
Engine/Core/Sort.h

@@ -23,7 +23,7 @@
 
 
 #pragma once
 #pragma once
 
 
-#include "MathDefs.h"
+#include "Swap.h"
 
 
 static const int QUICKSORT_THRESHOLD = 16;
 static const int QUICKSORT_THRESHOLD = 16;
 
 

+ 36 - 0
Engine/Core/Swap.h

@@ -0,0 +1,36 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2011 Lasse Öörni
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+class String;
+
+/// Swap two values
+template<class T> inline void Swap(T& first, T& second)
+{
+    T temp = first;
+    first = second;
+    second = temp;
+}
+
+template<> void Swap<String>(String& first, String& second);

+ 16 - 3
Engine/Math/BoundingBox.cpp

@@ -86,12 +86,25 @@ void BoundingBox::Intersect(const BoundingBox& box)
     if (box.max_.z_ < max_.z_)
     if (box.max_.z_ < max_.z_)
         max_.z_ = box.max_.z_;
         max_.z_ = box.max_.z_;
     
     
+    float temp;
     if (min_.x_ > max_.x_)
     if (min_.x_ > max_.x_)
-        Swap(min_.x_, max_.x_);
+    {
+        temp = min_.x_;
+        min_.x_ = max_.x_;
+        max_.x_ = temp;
+    }
     if (min_.y_ > max_.y_)
     if (min_.y_ > max_.y_)
-        Swap(min_.y_, max_.y_);
+    {
+        temp = min_.y_;
+        min_.y_ = max_.y_;
+        max_.y_ = temp;
+    }
     if (min_.z_ > max_.z_)
     if (min_.z_ > max_.z_)
-        Swap(min_.z_, max_.z_);
+    {
+        temp = min_.z_;
+        min_.z_ = max_.z_;
+        max_.z_ = temp;
+    }
 }
 }
 
 
 void BoundingBox::Transform(const Matrix3& transform)
 void BoundingBox::Transform(const Matrix3& transform)

+ 0 - 8
Engine/Math/MathDefs.h

@@ -125,14 +125,6 @@ inline int Clamp(int value, int min, int max)
     return value;
     return value;
 }
 }
 
 
-/// Swap two values
-template<class T> inline void Swap(T& first, T& second)
-{
-    T temp = first;
-    first = second;
-    second = temp;
-}
-
 /// Check whether an unsigned integer is a power of two
 /// Check whether an unsigned integer is a power of two
 inline bool IsPowerOfTwo(unsigned value)
 inline bool IsPowerOfTwo(unsigned value)
 {
 {