Remove Nz::String and Nz::StringStream

This commit is contained in:
Jérôme Leclercq
2020-09-25 19:31:01 +02:00
parent d665af1f9d
commit 2b6a463a45
212 changed files with 1877 additions and 8721 deletions

View File

@@ -3,15 +3,13 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <cstring>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
namespace Nz
{
/*!
@@ -212,7 +210,7 @@ namespace Nz
template<typename T>
Vector2<T>& Vector2<T>::MakeUnit()
{
return Set(F(1.0), F(1.0));
return Set(T(1.0), T(1.0));
}
/*!
@@ -225,7 +223,7 @@ namespace Nz
template<typename T>
Vector2<T>& Vector2<T>::MakeUnitX()
{
return Set(F(1.0), F(0.0));
return Set(T(1.0), T(0.0));
}
/*!
@@ -238,7 +236,7 @@ namespace Nz
template<typename T>
Vector2<T>& Vector2<T>::MakeUnitY()
{
return Set(F(0.0), F(1.0));
return Set(T(0.0), T(1.0));
}
/*!
@@ -251,7 +249,7 @@ namespace Nz
template<typename T>
Vector2<T>& Vector2<T>::MakeZero()
{
return Set(F(0.0), F(0.0));
return Set(T(0.0), T(0.0));
}
/*!
@@ -311,9 +309,9 @@ namespace Nz
Vector2<T>& Vector2<T>::Normalize(T* length)
{
T norm = GetLength();
if (norm > F(0.0))
if (norm > T(0.0))
{
T invNorm = F(1.0) / norm;
T invNorm = T(1.0) / norm;
x *= invNorm;
y *= invNorm;
}
@@ -383,8 +381,8 @@ namespace Nz
template<typename U>
Vector2<T>& Vector2<T>::Set(const Vector2<U>& vec)
{
x = F(vec.x);
y = F(vec.y);
x = T(vec.x);
y = T(vec.y);
return *this;
}
@@ -442,11 +440,12 @@ namespace Nz
*/
template<typename T>
String Vector2<T>::ToString() const
std::string Vector2<T>::ToString() const
{
StringStream ss;
std::ostringstream ss;
ss << *this;
return ss << "Vector2(" << x << ", " << y << ')';
return ss.str();
}
/*!
@@ -550,24 +549,11 @@ namespace Nz
* \return A vector where components are the quotient of this vector and the other one
*
* \param vec The other vector to divide components with
*
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
*/
template<typename T>
Vector2<T> Vector2<T>::operator/(const Vector2& vec) const
{
#if NAZARA_MATH_SAFE
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
{
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error.ToStdString());
}
#endif
return Vector2(x / vec.x, y / vec.y);
}
@@ -576,24 +562,11 @@ namespace Nz
* \return A vector where components are the quotient of this vector and the scalar
*
* \param scale The scalar to divide components with
*
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
*/
template<typename T>
Vector2<T> Vector2<T>::operator/(T scale) const
{
#if NAZARA_MATH_SAFE
if (NumberEquals(scale, F(0.0)))
{
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error.ToStdString());
}
#endif
return Vector2(x / scale, y / scale);
}
@@ -666,24 +639,11 @@ namespace Nz
* \return A reference to this vector where components are the quotient of this vector and the other one
*
* \param vec The other vector to multiply components with
*
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
*/
template<typename T>
Vector2<T>& Vector2<T>::operator/=(const Vector2& vec)
{
#if NAZARA_MATH_SAFE
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
{
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error.ToStdString());
}
#endif
x /= vec.x;
y /= vec.y;
@@ -695,24 +655,11 @@ namespace Nz
* \return A reference to this vector where components are the quotient of this vector and the scalar
*
* \param scale The scalar to divide components with
*
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
*/
template<typename T>
Vector2<T>& Vector2<T>::operator/=(T scale)
{
#if NAZARA_MATH_SAFE
if (NumberEquals(scale, F(0.0)))
{
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error.ToStdString());
}
#endif
x /= scale;
y /= scale;
@@ -990,7 +937,7 @@ namespace Nz
template<typename T>
std::ostream& operator<<(std::ostream& out, const Nz::Vector2<T>& vec)
{
return out << vec.ToString();
return out << "Vector2(" << vec.x << ", " << vec.y << ')';
}
/*!
@@ -1011,24 +958,11 @@ Nz::Vector2<T> operator*(T scale, const Nz::Vector2<T>& vec)
* \return A vector where components are the quotient of this vector and the scalar
*
* \param scale The scalar to divide components with
*
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
*/
template<typename T>
Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
{
#if NAZARA_MATH_SAFE
if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)))
{
Nz::String error("Division by zero");
NazaraError(error);
throw std::domain_error(error.ToStdString());
}
#endif
return Nz::Vector2<T>(scale / vec.x, scale / vec.y);
}
@@ -1054,7 +988,5 @@ namespace std
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>