From cfaa7c19d41ed61b664bb7270306bef90167f06f Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Wed, 22 Nov 2017 22:29:52 +0100 Subject: [PATCH] Cleanup a couple of classes --- es-core/src/math/Misc.h | 32 ++++++++--------- es-core/src/math/Transform4x4f.h | 20 +++++------ es-core/src/math/Vector2f.cpp | 4 +-- es-core/src/math/Vector2f.h | 46 ++++++++++++------------ es-core/src/math/Vector2i.h | 44 +++++++++++------------ es-core/src/math/Vector3f.cpp | 2 +- es-core/src/math/Vector3f.h | 46 ++++++++++++------------ es-core/src/math/Vector4f.cpp | 2 +- es-core/src/math/Vector4f.h | 46 ++++++++++++------------ es-core/src/utils/FileSystemUtil.cpp | 52 ++++++++++++++-------------- es-core/src/utils/FileSystemUtil.h | 22 ++++++------ es-core/src/utils/StringUtil.cpp | 19 ++++------ es-core/src/utils/StringUtil.h | 16 ++++----- 13 files changed, 172 insertions(+), 179 deletions(-) diff --git a/es-core/src/math/Misc.h b/es-core/src/math/Misc.h index 094ecac3f..a571796f1 100644 --- a/es-core/src/math/Misc.h +++ b/es-core/src/math/Misc.h @@ -3,31 +3,31 @@ #define ES_CORE_MATH_MISC_H #define ES_PI (3.1415926535897932384626433832795028841971693993751058209749445923) -#define ES_RAD_TO_DEG(x) ((x) * (180.0 / ES_PI)) -#define ES_DEG_TO_RAD(x) ((x) * (ES_PI / 180.0)) +#define ES_RAD_TO_DEG(_x) ((_x) * (180.0 / ES_PI)) +#define ES_DEG_TO_RAD(_x) ((_x) * (ES_PI / 180.0)) namespace Math { // added here to avoid including math.h whenever these are used - float cosf(const float _num); - float sinf(const float _num); - float floorf(const float _num); - float ceilf(const float _num); + float cosf (const float _num); + float sinf (const float _num); + float floorf (const float _num); + float ceilf (const float _num); - int min(const int _num1, const int _num2); - int max(const int _num1, const int _num2); - float min(const float _num1, const float _num2); - float max(const float _num1, const float _num2); - float clamp(const float _num, const float _min, const float _max); - float round(const float _num); - float lerp(const float _start, const float _end, const float _fraction); - float smoothStep(const float _left, const float _right, const float _x); + int min (const int _num1, const int _num2); + int max (const int _num1, const int _num2); + float min (const float _num1, const float _num2); + float max (const float _num1, const float _num2); + float clamp (const float _num, const float _min, const float _max); + float round (const float _num); + float lerp (const float _start, const float _end, const float _fraction); + float smoothStep (const float _left, const float _right, const float _x); float smootherStep(const float _left, const float _right, const float _x); - + namespace Scroll { float bounce(const float _delayTime, const float _scrollTime, const float _currentTime, const float _scrollLength); - float loop(const float _delayTime, const float _scrollTime, const float _currentTime, const float _scrollLength); + float loop (const float _delayTime, const float _scrollTime, const float _currentTime, const float _scrollLength); } // Math::Scroll:: diff --git a/es-core/src/math/Transform4x4f.h b/es-core/src/math/Transform4x4f.h index db20a303d..b1646a692 100644 --- a/es-core/src/math/Transform4x4f.h +++ b/es-core/src/math/Transform4x4f.h @@ -12,9 +12,9 @@ public: Transform4x4f() { } Transform4x4f(const Vector4f& _r0, const Vector4f& _r1, const Vector4f& _r2, const Vector4f& _r3) : mR0(_r0), mR1(_r1), mR2(_r2), mR3(_r3) { } - const Transform4x4f operator*(const Transform4x4f& _other) const; - const Vector3f operator*(const Vector3f& _other) const; - Transform4x4f& operator*=(const Transform4x4f& _other) { *this = *this * _other; return *this; } + const Transform4x4f operator* (const Transform4x4f& _other) const; + const Vector3f operator* (const Vector3f& _other) const; + Transform4x4f& operator*=(const Transform4x4f& _other) { *this = *this * _other; return *this; } inline Vector4f& r0() { return mR0; } inline Vector4f& r1() { return mR1; } @@ -25,14 +25,14 @@ public: inline const Vector4f& r2() const { return mR2; } inline const Vector4f& r3() const { return mR3; } - Transform4x4f& invert(const Transform4x4f& _other); - Transform4x4f& scale(const Vector3f& _scale); - Transform4x4f& rotate(const float _angle, const Vector3f& _axis); - Transform4x4f& rotateX(const float _angle); - Transform4x4f& rotateY(const float _angle); - Transform4x4f& rotateZ(const float _angle); + Transform4x4f& invert (const Transform4x4f& _other); + Transform4x4f& scale (const Vector3f& _scale); + Transform4x4f& rotate (const float _angle, const Vector3f& _axis); + Transform4x4f& rotateX (const float _angle); + Transform4x4f& rotateY (const float _angle); + Transform4x4f& rotateZ (const float _angle); Transform4x4f& translate(const Vector3f& _translation); - Transform4x4f& round(); + Transform4x4f& round (); inline Vector3f& translation() { return mR3.v3(); } inline const Vector3f& translation() const { return mR3.v3(); } diff --git a/es-core/src/math/Vector2f.cpp b/es-core/src/math/Vector2f.cpp index 6cb341623..f98f17194 100644 --- a/es-core/src/math/Vector2f.cpp +++ b/es-core/src/math/Vector2f.cpp @@ -4,9 +4,9 @@ Vector2f& Vector2f::round() { mX = (float)(int)(mX + 0.5f); mY = (float)(int)(mY + 0.5f); - + return *this; - + } // round Vector2f& Vector2f::lerp(const Vector2f& _start, const Vector2f& _end, const float _fraction) diff --git a/es-core/src/math/Vector2f.h b/es-core/src/math/Vector2f.h index d8103da30..061684284 100644 --- a/es-core/src/math/Vector2f.h +++ b/es-core/src/math/Vector2f.h @@ -18,33 +18,33 @@ public: explicit Vector2f(const Vector3f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) { } explicit Vector2f(const Vector4f& _v) : mX(((Vector2f&)_v).mX), mY(((Vector2f&)_v).mY) { } - const bool operator==(const Vector2f& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); } - const bool operator!=(const Vector2f& _other) const { return ((mX != _other.mX) || (mY != _other.mY)); } + const bool operator==(const Vector2f& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); } + const bool operator!=(const Vector2f& _other) const { return ((mX != _other.mX) || (mY != _other.mY)); } - const Vector2f operator+(const Vector2f& _other) const { return { mX + _other.mX, mY + _other.mY }; } - const Vector2f operator-(const Vector2f& _other) const { return { mX - _other.mX, mY - _other.mY }; } - const Vector2f operator*(const Vector2f& _other) const { return { mX * _other.mX, mY * _other.mY }; } - const Vector2f operator/(const Vector2f& _other) const { return { mX / _other.mX, mY / _other.mY }; } + const Vector2f operator+ (const Vector2f& _other) const { return { mX + _other.mX, mY + _other.mY }; } + const Vector2f operator- (const Vector2f& _other) const { return { mX - _other.mX, mY - _other.mY }; } + const Vector2f operator* (const Vector2f& _other) const { return { mX * _other.mX, mY * _other.mY }; } + const Vector2f operator/ (const Vector2f& _other) const { return { mX / _other.mX, mY / _other.mY }; } - const Vector2f operator+(const float& _other) const { return { mX + _other, mY + _other }; } - const Vector2f operator-(const float& _other) const { return { mX - _other, mY - _other }; } - const Vector2f operator*(const float& _other) const { return { mX * _other, mY * _other }; } - const Vector2f operator/(const float& _other) const { return { mX / _other, mY / _other }; } + const Vector2f operator+ (const float& _other) const { return { mX + _other, mY + _other }; } + const Vector2f operator- (const float& _other) const { return { mX - _other, mY - _other }; } + const Vector2f operator* (const float& _other) const { return { mX * _other, mY * _other }; } + const Vector2f operator/ (const float& _other) const { return { mX / _other, mY / _other }; } - const Vector2f operator-() const { return { -mX , -mY }; } + const Vector2f operator- () const { return { -mX , -mY }; } - Vector2f& operator+=(const Vector2f& _other) { *this = *this + _other; return *this; } - Vector2f& operator-=(const Vector2f& _other) { *this = *this - _other; return *this; } - Vector2f& operator*=(const Vector2f& _other) { *this = *this * _other; return *this; } - Vector2f& operator/=(const Vector2f& _other) { *this = *this / _other; return *this; } + Vector2f& operator+=(const Vector2f& _other) { *this = *this + _other; return *this; } + Vector2f& operator-=(const Vector2f& _other) { *this = *this - _other; return *this; } + Vector2f& operator*=(const Vector2f& _other) { *this = *this * _other; return *this; } + Vector2f& operator/=(const Vector2f& _other) { *this = *this / _other; return *this; } - Vector2f& operator+=(const float& _other) { *this = *this + _other; return *this; } - Vector2f& operator-=(const float& _other) { *this = *this - _other; return *this; } - Vector2f& operator*=(const float& _other) { *this = *this * _other; return *this; } - Vector2f& operator/=(const float& _other) { *this = *this / _other; return *this; } + Vector2f& operator+=(const float& _other) { *this = *this + _other; return *this; } + Vector2f& operator-=(const float& _other) { *this = *this - _other; return *this; } + Vector2f& operator*=(const float& _other) { *this = *this * _other; return *this; } + Vector2f& operator/=(const float& _other) { *this = *this / _other; return *this; } - float& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } - const float& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } + float& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } + const float& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } float& x() { return mX; } float& y() { return mY; } @@ -52,9 +52,9 @@ public: const float& y() const { return mY; } Vector2f& round(); - Vector2f& lerp(const Vector2f& _start, const Vector2f& _end, const float _fraction); + Vector2f& lerp (const Vector2f& _start, const Vector2f& _end, const float _fraction); - static const Vector2f Zero() { return { 0, 0 }; } + static const Vector2f Zero () { return { 0, 0 }; } static const Vector2f UnitX() { return { 1, 0 }; } static const Vector2f UnitY() { return { 0, 1 }; } diff --git a/es-core/src/math/Vector2i.h b/es-core/src/math/Vector2i.h index 693619da8..7cc020ea5 100644 --- a/es-core/src/math/Vector2i.h +++ b/es-core/src/math/Vector2i.h @@ -12,40 +12,40 @@ public: Vector2i(const int _i) : mX(_i), mY(_i) { } Vector2i(const int _x, const int _y) : mX(_x), mY(_y) { } - const bool operator==(const Vector2i& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); } - const bool operator!=(const Vector2i& _other) const { return ((mX != _other.mX) || (mY != _other.mY)); } + const bool operator==(const Vector2i& _other) const { return ((mX == _other.mX) && (mY == _other.mY)); } + const bool operator!=(const Vector2i& _other) const { return ((mX != _other.mX) || (mY != _other.mY)); } - const Vector2i operator+(const Vector2i& _other) const { return { mX + _other.mX, mY + _other.mY }; } - const Vector2i operator-(const Vector2i& _other) const { return { mX - _other.mX, mY - _other.mY }; } - const Vector2i operator*(const Vector2i& _other) const { return { mX * _other.mX, mY * _other.mY }; } - const Vector2i operator/(const Vector2i& _other) const { return { mX / _other.mX, mY / _other.mY }; } + const Vector2i operator+ (const Vector2i& _other) const { return { mX + _other.mX, mY + _other.mY }; } + const Vector2i operator- (const Vector2i& _other) const { return { mX - _other.mX, mY - _other.mY }; } + const Vector2i operator* (const Vector2i& _other) const { return { mX * _other.mX, mY * _other.mY }; } + const Vector2i operator/ (const Vector2i& _other) const { return { mX / _other.mX, mY / _other.mY }; } - const Vector2i operator+(const int& _other) const { return { mX + _other, mY + _other }; } - const Vector2i operator-(const int& _other) const { return { mX - _other, mY - _other }; } - const Vector2i operator*(const int& _other) const { return { mX * _other, mY * _other }; } - const Vector2i operator/(const int& _other) const { return { mX / _other, mY / _other }; } + const Vector2i operator+ (const int& _other) const { return { mX + _other, mY + _other }; } + const Vector2i operator- (const int& _other) const { return { mX - _other, mY - _other }; } + const Vector2i operator* (const int& _other) const { return { mX * _other, mY * _other }; } + const Vector2i operator/ (const int& _other) const { return { mX / _other, mY / _other }; } - const Vector2i operator-() const { return { -mX , -mY }; } + const Vector2i operator- () const { return { -mX , -mY }; } - Vector2i& operator+=(const Vector2i& _other) { *this = *this + _other; return *this; } - Vector2i& operator-=(const Vector2i& _other) { *this = *this - _other; return *this; } - Vector2i& operator*=(const Vector2i& _other) { *this = *this * _other; return *this; } - Vector2i& operator/=(const Vector2i& _other) { *this = *this / _other; return *this; } + Vector2i& operator+=(const Vector2i& _other) { *this = *this + _other; return *this; } + Vector2i& operator-=(const Vector2i& _other) { *this = *this - _other; return *this; } + Vector2i& operator*=(const Vector2i& _other) { *this = *this * _other; return *this; } + Vector2i& operator/=(const Vector2i& _other) { *this = *this / _other; return *this; } - Vector2i& operator+=(const int& _other) { *this = *this + _other; return *this; } - Vector2i& operator-=(const int& _other) { *this = *this - _other; return *this; } - Vector2i& operator*=(const int& _other) { *this = *this * _other; return *this; } - Vector2i& operator/=(const int& _other) { *this = *this / _other; return *this; } + Vector2i& operator+=(const int& _other) { *this = *this + _other; return *this; } + Vector2i& operator-=(const int& _other) { *this = *this - _other; return *this; } + Vector2i& operator*=(const int& _other) { *this = *this * _other; return *this; } + Vector2i& operator/=(const int& _other) { *this = *this / _other; return *this; } - int& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } - const int& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } + int& operator[](const int _index) { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } + const int& operator[](const int _index) const { assert(_index < 2 && "index out of range"); return (&mX)[_index]; } int& x() { return mX; } int& y() { return mY; } const int& x() const { return mX; } const int& y() const { return mY; } - static const Vector2i Zero() { return { 0, 0 }; } + static const Vector2i Zero () { return { 0, 0 }; } static const Vector2i UnitX() { return { 1, 0 }; } static const Vector2i UnitY() { return { 0, 1 }; } diff --git a/es-core/src/math/Vector3f.cpp b/es-core/src/math/Vector3f.cpp index 3dd9b01d9..15fc22e7b 100644 --- a/es-core/src/math/Vector3f.cpp +++ b/es-core/src/math/Vector3f.cpp @@ -5,7 +5,7 @@ Vector3f& Vector3f::round() mX = (float)(int)(mX + 0.5f); mY = (float)(int)(mY + 0.5f); mZ = (float)(int)(mZ + 0.5f); - + return *this; } // round diff --git a/es-core/src/math/Vector3f.h b/es-core/src/math/Vector3f.h index db33912f4..c6237bc2c 100644 --- a/es-core/src/math/Vector3f.h +++ b/es-core/src/math/Vector3f.h @@ -19,33 +19,33 @@ public: explicit Vector3f(const Vector2f& _v, const float _z) : mX(((Vector3f&)_v).mX), mY(((Vector3f&)_v).mY), mZ(_z) { } explicit Vector3f(const Vector4f& _v) : mX(((Vector3f&)_v).mX), mY(((Vector3f&)_v).mY), mZ(((Vector3f&)_v).mZ) { } - const bool operator==(const Vector3f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && (mZ == _other.mZ)); } - const bool operator!=(const Vector3f& _other) const { return ((mX != _other.mX) || (mY != _other.mY) || (mZ != _other.mZ)); } + const bool operator==(const Vector3f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && (mZ == _other.mZ)); } + const bool operator!=(const Vector3f& _other) const { return ((mX != _other.mX) || (mY != _other.mY) || (mZ != _other.mZ)); } - const Vector3f operator+(const Vector3f& _other) const { return { mX + _other.mX, mY + _other.mY, mZ + _other.mZ }; } - const Vector3f operator-(const Vector3f& _other) const { return { mX - _other.mX, mY - _other.mY, mZ - _other.mZ }; } - const Vector3f operator*(const Vector3f& _other) const { return { mX * _other.mX, mY * _other.mY, mZ * _other.mZ }; } - const Vector3f operator/(const Vector3f& _other) const { return { mX / _other.mX, mY / _other.mY, mZ / _other.mZ }; } + const Vector3f operator+ (const Vector3f& _other) const { return { mX + _other.mX, mY + _other.mY, mZ + _other.mZ }; } + const Vector3f operator- (const Vector3f& _other) const { return { mX - _other.mX, mY - _other.mY, mZ - _other.mZ }; } + const Vector3f operator* (const Vector3f& _other) const { return { mX * _other.mX, mY * _other.mY, mZ * _other.mZ }; } + const Vector3f operator/ (const Vector3f& _other) const { return { mX / _other.mX, mY / _other.mY, mZ / _other.mZ }; } - const Vector3f operator+(const float& _other) const { return { mX + _other, mY + _other, mZ + _other }; } - const Vector3f operator-(const float& _other) const { return { mX - _other, mY - _other, mZ - _other }; } - const Vector3f operator*(const float& _other) const { return { mX * _other, mY * _other, mZ * _other }; } - const Vector3f operator/(const float& _other) const { return { mX / _other, mY / _other, mZ / _other }; } + const Vector3f operator+ (const float& _other) const { return { mX + _other, mY + _other, mZ + _other }; } + const Vector3f operator- (const float& _other) const { return { mX - _other, mY - _other, mZ - _other }; } + const Vector3f operator* (const float& _other) const { return { mX * _other, mY * _other, mZ * _other }; } + const Vector3f operator/ (const float& _other) const { return { mX / _other, mY / _other, mZ / _other }; } - const Vector3f operator-() const { return { -mX , -mY, -mZ }; } + const Vector3f operator- () const { return { -mX , -mY, -mZ }; } - Vector3f& operator+=(const Vector3f& _other) { *this = *this + _other; return *this; } - Vector3f& operator-=(const Vector3f& _other) { *this = *this - _other; return *this; } - Vector3f& operator*=(const Vector3f& _other) { *this = *this * _other; return *this; } - Vector3f& operator/=(const Vector3f& _other) { *this = *this / _other; return *this; } + Vector3f& operator+=(const Vector3f& _other) { *this = *this + _other; return *this; } + Vector3f& operator-=(const Vector3f& _other) { *this = *this - _other; return *this; } + Vector3f& operator*=(const Vector3f& _other) { *this = *this * _other; return *this; } + Vector3f& operator/=(const Vector3f& _other) { *this = *this / _other; return *this; } - Vector3f& operator+=(const float& _other) { *this = *this + _other; return *this; } - Vector3f& operator-=(const float& _other) { *this = *this - _other; return *this; } - Vector3f& operator*=(const float& _other) { *this = *this * _other; return *this; } - Vector3f& operator/=(const float& _other) { *this = *this / _other; return *this; } + Vector3f& operator+=(const float& _other) { *this = *this + _other; return *this; } + Vector3f& operator-=(const float& _other) { *this = *this - _other; return *this; } + Vector3f& operator*=(const float& _other) { *this = *this * _other; return *this; } + Vector3f& operator/=(const float& _other) { *this = *this / _other; return *this; } - float& operator[](const int _index) { assert(_index < 3 && "index out of range"); return (&mX)[_index]; } - const float& operator[](const int _index) const { assert(_index < 3 && "index out of range"); return (&mX)[_index]; } + float& operator[](const int _index) { assert(_index < 3 && "index out of range"); return (&mX)[_index]; } + const float& operator[](const int _index) const { assert(_index < 3 && "index out of range"); return (&mX)[_index]; } float& x() { return mX; } float& y() { return mY; } @@ -58,9 +58,9 @@ public: inline const Vector2f& v2() const { return *(Vector2f*)this; } Vector3f& round(); - Vector3f& lerp(const Vector3f& _start, const Vector3f& _end, const float _fraction); + Vector3f& lerp (const Vector3f& _start, const Vector3f& _end, const float _fraction); - static const Vector3f Zero() { return { 0, 0, 0 }; } + static const Vector3f Zero () { return { 0, 0, 0 }; } static const Vector3f UnitX() { return { 1, 0, 0 }; } static const Vector3f UnitY() { return { 0, 1, 0 }; } static const Vector3f UnitZ() { return { 0, 0, 1 }; } diff --git a/es-core/src/math/Vector4f.cpp b/es-core/src/math/Vector4f.cpp index c0f933aa3..088552172 100644 --- a/es-core/src/math/Vector4f.cpp +++ b/es-core/src/math/Vector4f.cpp @@ -6,7 +6,7 @@ Vector4f& Vector4f::round() mY = (float)(int)(mY + 0.5f); mZ = (float)(int)(mZ + 0.5f); mW = (float)(int)(mW + 0.5f); - + return *this; } // round diff --git a/es-core/src/math/Vector4f.h b/es-core/src/math/Vector4f.h index 1cf1b0dac..518c1450b 100644 --- a/es-core/src/math/Vector4f.h +++ b/es-core/src/math/Vector4f.h @@ -21,33 +21,33 @@ public: explicit Vector4f(const Vector3f& _v) : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(((Vector4f&)_v).mZ), mW(0) { } explicit Vector4f(const Vector3f& _v, const float _w) : mX(((Vector4f&)_v).mX), mY(((Vector4f&)_v).mY), mZ(((Vector4f&)_v).mZ), mW(_w) { } - const bool operator==(const Vector4f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && (mZ == _other.mZ) && (mW == _other.mW)); } - const bool operator!=(const Vector4f& _other) const { return ((mX != _other.mX) || (mY != _other.mY) || (mZ != _other.mZ) || (mW != _other.mW)); } + const bool operator==(const Vector4f& _other) const { return ((mX == _other.mX) && (mY == _other.mY) && (mZ == _other.mZ) && (mW == _other.mW)); } + const bool operator!=(const Vector4f& _other) const { return ((mX != _other.mX) || (mY != _other.mY) || (mZ != _other.mZ) || (mW != _other.mW)); } - const Vector4f operator+(const Vector4f& _other) const { return { mX + _other.mX, mY + _other.mY, mZ + _other.mZ, mW + _other.mW }; } - const Vector4f operator-(const Vector4f& _other) const { return { mX - _other.mX, mY - _other.mY, mZ - _other.mZ, mW - _other.mW }; } - const Vector4f operator*(const Vector4f& _other) const { return { mX * _other.mX, mY * _other.mY, mZ * _other.mZ, mW * _other.mW }; } - const Vector4f operator/(const Vector4f& _other) const { return { mX / _other.mX, mY / _other.mY, mZ / _other.mZ, mW / _other.mW }; } + const Vector4f operator+ (const Vector4f& _other) const { return { mX + _other.mX, mY + _other.mY, mZ + _other.mZ, mW + _other.mW }; } + const Vector4f operator- (const Vector4f& _other) const { return { mX - _other.mX, mY - _other.mY, mZ - _other.mZ, mW - _other.mW }; } + const Vector4f operator* (const Vector4f& _other) const { return { mX * _other.mX, mY * _other.mY, mZ * _other.mZ, mW * _other.mW }; } + const Vector4f operator/ (const Vector4f& _other) const { return { mX / _other.mX, mY / _other.mY, mZ / _other.mZ, mW / _other.mW }; } - const Vector4f operator+(const float& _other) const { return { mX + _other, mY + _other, mZ + _other, mW + _other }; } - const Vector4f operator-(const float& _other) const { return { mX - _other, mY - _other, mZ - _other, mW - _other }; } - const Vector4f operator*(const float& _other) const { return { mX * _other, mY * _other, mZ * _other, mW * _other }; } - const Vector4f operator/(const float& _other) const { return { mX / _other, mY / _other, mZ / _other, mW / _other }; } + const Vector4f operator+ (const float& _other) const { return { mX + _other, mY + _other, mZ + _other, mW + _other }; } + const Vector4f operator- (const float& _other) const { return { mX - _other, mY - _other, mZ - _other, mW - _other }; } + const Vector4f operator* (const float& _other) const { return { mX * _other, mY * _other, mZ * _other, mW * _other }; } + const Vector4f operator/ (const float& _other) const { return { mX / _other, mY / _other, mZ / _other, mW / _other }; } - const Vector4f operator-() const { return {-mX , -mY, -mZ, -mW }; } + const Vector4f operator- () const { return {-mX , -mY, -mZ, -mW }; } - Vector4f& operator+=(const Vector4f& _other) { *this = *this + _other; return *this; } - Vector4f& operator-=(const Vector4f& _other) { *this = *this - _other; return *this; } - Vector4f& operator*=(const Vector4f& _other) { *this = *this * _other; return *this; } - Vector4f& operator/=(const Vector4f& _other) { *this = *this / _other; return *this; } + Vector4f& operator+=(const Vector4f& _other) { *this = *this + _other; return *this; } + Vector4f& operator-=(const Vector4f& _other) { *this = *this - _other; return *this; } + Vector4f& operator*=(const Vector4f& _other) { *this = *this * _other; return *this; } + Vector4f& operator/=(const Vector4f& _other) { *this = *this / _other; return *this; } - Vector4f& operator+=(const float& _other) { *this = *this + _other; return *this; } - Vector4f& operator-=(const float& _other) { *this = *this - _other; return *this; } - Vector4f& operator*=(const float& _other) { *this = *this * _other; return *this; } - Vector4f& operator/=(const float& _other) { *this = *this / _other; return *this; } + Vector4f& operator+=(const float& _other) { *this = *this + _other; return *this; } + Vector4f& operator-=(const float& _other) { *this = *this - _other; return *this; } + Vector4f& operator*=(const float& _other) { *this = *this * _other; return *this; } + Vector4f& operator/=(const float& _other) { *this = *this / _other; return *this; } - float& operator[](const int _index) { assert(_index < 4 && "index out of range"); return (&mX)[_index]; } - const float& operator[](const int _index) const { assert(_index < 4 && "index out of range"); return (&mX)[_index]; } + float& operator[](const int _index) { assert(_index < 4 && "index out of range"); return (&mX)[_index]; } + const float& operator[](const int _index) const { assert(_index < 4 && "index out of range"); return (&mX)[_index]; } float& x() { return mX; } float& y() { return mY; } @@ -65,9 +65,9 @@ public: inline const Vector3f& v3() const { return *(Vector3f*)this; } Vector4f& round(); - Vector4f& lerp(const Vector4f& _start, const Vector4f& _end, const float _fraction); + Vector4f& lerp (const Vector4f& _start, const Vector4f& _end, const float _fraction); - static const Vector4f Zero() { return { 0, 0, 0, 0 }; } + static const Vector4f Zero () { return { 0, 0, 0, 0 }; } static const Vector4f UnitX() { return { 1, 0, 0, 0 }; } static const Vector4f UnitY() { return { 0, 1, 0, 0 }; } static const Vector4f UnitZ() { return { 0, 0, 1, 0 }; } diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 54e49d88c..b15f03766 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -14,55 +14,55 @@ namespace Utils { namespace FileSystem { - bool createDirectory(const std::string& path) + bool createDirectory(const std::string& _path) { // don't create if it already exists - if(exists(path)) + if(exists(_path)) return true; // convert '\\' to '/' - fixSeparators(path); + makeGeneric(_path); // try to create directory - if(mkdir(path.c_str(), 0755) == 0) + if(mkdir(_path.c_str(), 0755) == 0) return true; // failed to create directory, try to create the parent - std::string parent = getParent(path); + std::string parent = getParent(_path); // only try to create parent if it's not identical to path - if(parent != path) + if(parent != _path) createDirectory(parent); // try to create directory again now that the parent should exist - return (mkdir(path.c_str(), 0755) == 0); + return (mkdir(_path.c_str(), 0755) == 0); } // createDirectory - void fixSeparators(const std::string& path) + void makeGeneric(const std::string& _path) { char* p = nullptr; // convert '\\' to '/' - for(p = (char*)path.c_str() + 1; *p; ++p) + for(p = (char*)_path.c_str() + 1; *p; ++p) { if(*p == '\\') *p = '/'; } - } // fixSeparators + } // makeGeneric - std::string escapePath(const std::string& path) + std::string escapePath(const std::string& _path) { #ifdef WIN32 // windows escapes stuff by just putting everything in quotes - return '"' + path + '"'; + return '"' + _path + '"'; #else // WIN32 // insert a backslash before most characters that would mess up a bash path - std::string escapedPath = path; + std::string escapedPath = _path; const char* invalidChars = "\\ '\"!$^&*(){}[]?;<>"; - const char* invalidChar = invalidChars; + const char* invalidChar = invalidChars; while(*invalidChar) { @@ -83,14 +83,14 @@ namespace Utils } // escapePath - std::string getParent(const std::string& path) + std::string getParent(const std::string& _path) { // convert '\\' to '/' - fixSeparators(path); + makeGeneric(_path); // make a copy of the path char temp[512]; - size_t len = snprintf(temp, sizeof(temp), "%s", path.c_str()); + size_t len = snprintf(temp, sizeof(temp), "%s", _path.c_str()); // find last '/' and end the new path while(len > 1) @@ -103,18 +103,18 @@ namespace Utils } // no parent found - return path; + return _path; } // getParent - std::string getFileName(const std::string& path) + std::string getFileName(const std::string& _path) { // convert '\\' to '/' - fixSeparators(path); + makeGeneric(_path); // make a copy of the path char temp[512]; - size_t len = snprintf(temp, sizeof(temp), "%s", path.c_str()); + size_t len = snprintf(temp, sizeof(temp), "%s", _path.c_str()); // find last '/' and return the filename while(len > 1) @@ -125,13 +125,13 @@ namespace Utils } // no '/' found, entire path is a filename - return path; + return _path; } // getFileName - std::string getStem(const std::string& path) + std::string getStem(const std::string& _path) { - std::string fileName = getFileName(path); + std::string fileName = getFileName(_path); // empty fileName if(fileName == ".") @@ -156,10 +156,10 @@ namespace Utils } // getStem - bool exists(const std::string& path) + bool exists(const std::string& _path) { struct stat info; - return (stat(path.c_str(), &info) == 0); + return (stat(_path.c_str(), &info) == 0); } // exists diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index fe6929654..d91b5666c 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -1,6 +1,6 @@ #pragma once -#ifndef ES_CORE_FILE_SYSTEM_UTIL_H -#define ES_CORE_FILE_SYSTEM_UTIL_H +#ifndef ES_CORE_UTILS_FILE_SYSTEM_UTIL_H +#define ES_CORE_UTILS_FILE_SYSTEM_UTIL_H #include @@ -8,16 +8,16 @@ namespace Utils { namespace FileSystem { - bool createDirectory(const std::string& path); - void fixSeparators(const std::string& path); - std::string escapePath(const std::string& path); - std::string getParent(const std::string& path); - std::string getFileName(const std::string& path); - std::string getStem(const std::string& path); - bool exists(const std::string& path); + bool createDirectory(const std::string& _path); + void makeGeneric (const std::string& _path); + std::string escapePath (const std::string& _path); + std::string getParent (const std::string& _path); + std::string getFileName (const std::string& _path); + std::string getStem (const std::string& _path); + bool exists (const std::string& _path); - } // FileSystem:: + } // Utils::FileSystem:: } // Utils:: -#endif // ES_CORE_FILE_SYSTEM_UTIL_H +#endif // ES_CORE_UTILS_FILE_SYSTEM_UTIL_H diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index 52f426fba..695695ab3 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -132,22 +132,15 @@ namespace Utils } // moveCursor - void trim(std::string& _string) + std::string trim(const std::string& _path) { - if(_string.size()) - { - size_t cursorB = 0; - size_t cursorE = _string.size(); - - while((cursorB < _string.size()) && _string[cursorB] == ' ') - ++cursorB; + const size_t pathBegin = _path.find_first_not_of(" \t"); + const size_t pathEnd = _path.find_last_not_of(" \t"); - while((cursorE > 0) && _string[cursorE - 1] == ' ') - --cursorE; + if(pathBegin == std::string::npos) + return ""; - _string.erase(_string.begin() + cursorE, _string.end()); - _string.erase(_string.begin(), _string.begin() + cursorB); - } + return _path.substr(pathBegin, pathEnd - pathBegin + 1); } // trim diff --git a/es-core/src/utils/StringUtil.h b/es-core/src/utils/StringUtil.h index 29d82c338..3649ae4d8 100644 --- a/es-core/src/utils/StringUtil.h +++ b/es-core/src/utils/StringUtil.h @@ -1,6 +1,6 @@ #pragma once -#ifndef ES_CORE_STRING_UTIL_H -#define ES_CORE_STRING_UTIL_H +#ifndef ES_CORE_UTILS_STRING_UTIL_H +#define ES_CORE_UTILS_STRING_UTIL_H #include @@ -10,13 +10,13 @@ namespace Utils { unsigned int chars2Unicode(const std::string& _string, size_t& _cursor); std::string unicode2Chars(const unsigned int _unicode); - size_t nextCursor(const std::string& _string, const size_t _cursor); - size_t prevCursor(const std::string& _string, const size_t _cursor); - size_t moveCursor(const std::string& _string, const size_t _cursor, const int _amount); - void trim(std::string& _string); + size_t nextCursor (const std::string& _string, const size_t _cursor); + size_t prevCursor (const std::string& _string, const size_t _cursor); + size_t moveCursor (const std::string& _string, const size_t _cursor, const int _amount); + std::string trim (const std::string& _path); - } // String:: + } // Utils::String:: } // Utils:: -#endif // ES_CORE_STRING_UTIL_H +#endif // ES_CORE_UTILS_STRING_UTIL_H