Browse Source

Added constructors to String + code cleanup.

Lasse Öörni 14 years ago
parent
commit
4e30a2f032
3 changed files with 45 additions and 32 deletions
  1. 25 12
      Engine/Container/String.cpp
  2. 19 15
      Engine/Container/StringBase.h
  3. 1 5
      Tools/AssetImporter/AssetImporter.cpp

+ 25 - 12
Engine/Container/String.cpp

@@ -89,40 +89,53 @@ String::String(bool value) :
         *this = "false";
         *this = "false";
 }
 }
 
 
+String::String(char value) :
+    length_(0),
+    capacity_(0),
+    buffer_(&endZero)
+{
+    Resize(1);
+    buffer_[0] = value;
+}
+
+String::String(char value, unsigned length) :
+    length_(0),
+    capacity_(0),
+    buffer_(&endZero)
+{
+    Resize(length);
+    for (unsigned i = 0; i < length; ++i)
+        buffer_[i] = value;
+}
+
 String& String::operator += (int rhs)
 String& String::operator += (int rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String& String::operator += (short rhs)
 String& String::operator += (short rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String& String::operator += (unsigned rhs)
 String& String::operator += (unsigned rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String& String::operator += (unsigned short rhs)
 String& String::operator += (unsigned short rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String& String::operator += (float rhs)
 String& String::operator += (float rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String& String::operator += (bool rhs)
 String& String::operator += (bool rhs)
 {
 {
-    *this += String(rhs);
-    return *this;
+    return *this += String(rhs);
 }
 }
 
 
 String String::operator + (int rhs) const
 String String::operator + (int rhs) const

+ 19 - 15
Engine/Container/StringBase.h

@@ -96,6 +96,10 @@ public:
     explicit String(float value);
     explicit String(float value);
     /// Construct from a bool
     /// Construct from a bool
     explicit String(bool value);
     explicit String(bool value);
+    /// Construct from a character
+    explicit String(char value);
+    /// Construct from a character and fill length
+    explicit String(char value, unsigned length);
     
     
     /// Construct from a convertable value
     /// Construct from a convertable value
     template <class T> explicit String(const T& value) :
     template <class T> explicit String(const T& value) :
@@ -169,6 +173,21 @@ public:
         return *this;
         return *this;
     }
     }
     
     
+    /// Add-assign an integer
+    String& operator += (int rhs);
+    /// Add-assign a short integer
+    String& operator += (short rhs);
+    /// Add-assign an unsigned integer
+    String& operator += (unsigned rhs);
+    /// Add-assign a short unsigned integer
+    String& operator += (unsigned short rhs);
+    /// Add-assign a float
+    String& operator += (float rhs);
+    /// Add-assign a bool
+    String& operator += (bool rhs);
+    /// Add-assign an arbitraty type
+    template <class T> String operator += (const T& rhs) { return *this += rhs.ToString(); }
+    
     /// Add a string
     /// Add a string
     String operator + (const String& rhs) const
     String operator + (const String& rhs) const
     {
     {
@@ -207,21 +226,6 @@ public:
         return ret;
         return ret;
     }
     }
     
     
-    /// Add-assign an integer
-    String& operator += (int rhs);
-    /// Add-assign a short integer
-    String& operator += (short rhs);
-    /// Add-assign an unsigned integer
-    String& operator += (unsigned rhs);
-    /// Add-assign a short unsigned integer
-    String& operator += (unsigned short rhs);
-    /// Add-assign a float
-    String& operator += (float rhs);
-    /// Add-assign a bool
-    String& operator += (bool rhs);
-    /// Add-assign an arbitraty type
-    template <class T> String operator += (const T& rhs) { return *this += rhs.ToString(); }
-    
     /// Add an integer
     /// Add an integer
     String operator + (int rhs) const;
     String operator + (int rhs) const;
     /// Add a short integer
     /// Add a short integer

+ 1 - 5
Tools/AssetImporter/AssetImporter.cpp

@@ -399,11 +399,7 @@ void DumpNodes(aiNode* rootNode, unsigned level)
     if (!rootNode)
     if (!rootNode)
         return;
         return;
     
     
-    String indent;
-    indent.Resize(level * 2);
-    for (unsigned i = 0; i < level * 2; ++i)
-        indent[i] = ' ';
-    
+    String indent(' ', level * 2);
     Vector3 pos, scale;
     Vector3 pos, scale;
     Quaternion rot;
     Quaternion rot;
     aiMatrix4x4 transform = GetDerivedTransform(rootNode, rootNode_);
     aiMatrix4x4 transform = GetDerivedTransform(rootNode, rootNode_);