From ac23f7b9342ef5b877e6b9315e99ee6115133328 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 14 Sep 2017 00:59:21 +0200 Subject: [PATCH] [DEV] continue removing STL --- etk/Color.hpp | 44 +++++++++++--------------------- etk/Function.cpp | 9 +++++++ etk/Map.hpp | 2 -- etk/Noise.cpp | 10 ++++---- etk/Stream.hpp | 19 ++------------ etk/String.cpp | 46 ++++++++++++++++++++++++++++++++- etk/String.hpp | 6 ++++- etk/UString.cpp | 13 ++++++++++ etk/Vector.hpp | 51 +++++++++++++++++++++++++++++++++++-- etk/etk.cpp | 3 +-- etk/math/Matrix.hpp | 2 +- etk/math/Matrix2x2.cpp | 14 +++++------ etk/math/Matrix3x3.cpp | 26 +++++++++---------- etk/math/Matrix4x4.cpp | 2 +- etk/math/Quaternion.cpp | 12 ++++----- etk/math/Quaternion.hpp | 10 ++++---- etk/math/Vector2D.cpp | 4 +-- etk/math/Vector2D.hpp | 6 ++--- etk/math/Vector3D.hpp | 16 ++++++------ etk/math/Vector4D.hpp | 10 ++++---- etk/move.hpp | 20 ++++----------- etk/os/FSNode.cpp | 7 +++--- etk/os/Fifo.hpp | 31 ++++++++++++----------- etk/stdTools.hpp | 56 +++++++++++++++++++++++++++++++++++++++++ etk/tool.cpp | 13 ++++++---- etk/tool.hpp | 3 ++- etk/utf8.hpp | 4 +-- test/testQuaternion.cpp | 6 ++--- test/testTrait.cpp | 33 ++++++++++++++++++++---- 29 files changed, 317 insertions(+), 161 deletions(-) diff --git a/etk/Color.hpp b/etk/Color.hpp index bd30bcc..38dc368 100644 --- a/etk/Color.hpp +++ b/etk/Color.hpp @@ -523,22 +523,18 @@ namespace etk { //! @not_in_doc template etk::Stream& operator <<(etk::Stream& _os, const Color& _obj) { // RGB & RGBA 8 bits - // TODO: set it back !!!! - /* - std::ostringstream os; if (MY_TYPE_SIZE >= 3) { _os << "#"; - os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r()); + _os << etk::toHex(_obj.r()); if (MY_TYPE_SIZE >= 2) { - os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g()); + _os << etk::toHex(_obj.g()); } if (MY_TYPE_SIZE >= 3) { - os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.b()); + _os << etk::toHex(_obj.b()); } if (MY_TYPE_SIZE >= 4) { - os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.a()); + _os << etk::toHex(_obj.a()); } - _os << os.str(); } else { if (MY_TYPE_SIZE >= 2) { _os << "be"; @@ -546,14 +542,13 @@ namespace etk { _os << "Mono"; } _os << "[U8]("; - os << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r()); + _os << "0x" << etk::toHex(_obj.r()); if (MY_TYPE_SIZE >= 2) { _os << ","; - os << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g()); + _os << "0x" << etk::toHex(_obj.g()); } - _os << os.str(); _os << ")"; - }*/ + } return _os; } //! @not_in_doc @@ -568,25 +563,20 @@ namespace etk { _os << "Mono"; } _os << "[U16]("; - // TODO: set it back !!!! - /* - os << "0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.r(); + _os << "0x" << etk::toHex(_obj.r(), 4); if (MY_TYPE_SIZE >= 2) { - os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.g(); + _os << ",0x" << etk::toHex(_obj.g(), 4); } if (MY_TYPE_SIZE >= 3) { - os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.b(); + _os << ",0x" << etk::toHex(_obj.b(), 4); } if (MY_TYPE_SIZE >= 4) { - os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.a(); + _os << ",0x" << etk::toHex(_obj.a(), 4); } - _os << os.str() << ")"; - */ return _os; } //! @not_in_doc template etk::Stream& operator <<(etk::Stream& _os, const Color& _obj) { // RGB & RGBA 8 bits - //std::ostringstream os; if (MY_TYPE_SIZE >= 4) { _os << "rgba"; } else if (MY_TYPE_SIZE >= 3) { @@ -597,20 +587,16 @@ namespace etk { _os << "Mono"; } _os << "[U32]("; - // TODO: set it back !!!! - /* - os << "0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.r(); + _os << "0x" << etk::toHex(_obj.r(), 8); if (MY_TYPE_SIZE >= 2) { - os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.g(); + _os << ",0x" << etk::toHex(_obj.g(), 8); } if (MY_TYPE_SIZE >= 3) { - os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.b(); + _os << ",0x" << etk::toHex(_obj.b(), 8); } if (MY_TYPE_SIZE >= 4) { - os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.a(); + _os << ",0x" << etk::toHex(_obj.a(), 8); } - _os << os.str() << ")"; - */ return _os; } //! @not_in_doc diff --git a/etk/Function.cpp b/etk/Function.cpp index e69de29..c00d34b 100644 --- a/etk/Function.cpp +++ b/etk/Function.cpp @@ -0,0 +1,9 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + +#include +uint32_t etk::MM___pppppp = 0; + diff --git a/etk/Map.hpp b/etk/Map.hpp index fb6d2a4..ef70f41 100644 --- a/etk/Map.hpp +++ b/etk/Map.hpp @@ -19,8 +19,6 @@ namespace etk { * * @note The name is unique and the value is what you want * - * @todo check if something else exist in the generic library. (not the etk::Map and the std::unordered_map - * * @note The index are all time available since they are created. The order is the the one created * * A simple example of use: diff --git a/etk/Noise.cpp b/etk/Noise.cpp index 22dfa99..2a44752 100644 --- a/etk/Noise.cpp +++ b/etk/Noise.cpp @@ -9,11 +9,11 @@ #include #include #include -// for the rand ... -#include -#include - -#include +extern "C" { + #include + #include + #include +} etk::BaseNoise::BaseNoise(const ivec2& _size, float _min, float _max) : m_data(_size.x()*_size.y()), diff --git a/etk/Stream.hpp b/etk/Stream.hpp index c603ada..7405aac 100644 --- a/etk/Stream.hpp +++ b/etk/Stream.hpp @@ -14,7 +14,7 @@ namespace etk { */ class Stream { private: - // remove dependency of std::string and vector + // remove dependency of etk::String and vector etk::String* m_data; public: Stream(size_t _basicSize=0); @@ -40,21 +40,6 @@ namespace etk { const etk::String& str() const; const size_t size() const; }; - // TODO: This is not a good place ... - /* - //! @not_in_doc - template - etk::Stream& operator <<(etk::Stream& _os, const etk::Vector& _obj) { - _os << "{"; - for (size_t iii=0; iii< _obj.size(); iii++) { - if (iii>0) { - _os << ";"; - } - _os << _obj[iii]; - } - _os << "}"; - return _os; - } - */ + } diff --git a/etk/String.cpp b/etk/String.cpp index 31e01e5..58c1751 100644 --- a/etk/String.cpp +++ b/etk/String.cpp @@ -41,7 +41,7 @@ etk::String::String(const char* _obj) { } } /* -etk::String::String(const std::string _obj) { +etk::String::String(const etk::String _obj) { resize(_obj.size()); for (size_t iii=0; iii<_obj.size(); ++iii) { m_data[iii] = _obj[iii]; @@ -1124,3 +1124,47 @@ etk::String etk::operator+ (char _left, const etk::String& _right) { } + +namespace etk { + template<> etk::String toString(const etk::String& _val) { + return _val; + } + template<> bool from_string(etk::String& _variableRet, const etk::UString& _value) { + _variableRet = u32char::convertToUtf8(_value); + return true; + } +} + + + +char etk::toHexChar(uint8_t _value) { + char out; + if (_value < 10) { + return _value + '0'; + } + return _value - 10 + 'A'; +} + +etk::String etk::toHex(uint64_t _value, uint32_t _size) { + etk::String out; + for (int32_t iii = 15; iii >=0; --iii) { + if ( _size >= iii + || _value >= uint64_t(1)<>(iii*4)) & 0x0F); + } + } + return out; +} + + +etk::String etk::toBin(uint64_t _value, uint32_t _size) { + etk::String out; + for (int32_t iii = 63; iii >=0; --iii) { + if ( _size >= iii + || _value >= uint64_t(1)<>(iii)) & 0x01); + } + } + return out; +} + diff --git a/etk/String.hpp b/etk/String.hpp index c571c41..6e04c41 100644 --- a/etk/String.hpp +++ b/etk/String.hpp @@ -225,7 +225,7 @@ namespace etk { */ String(const char* _obj); // TODO : remove this when ready - //////// String(const std::string _obj); + //////// String(const etk::String _obj); /** * @brief Partial copy of the null-terminated C string. * @param[in] _obj String that might be copyC string that might be copy (end by '\0') @@ -574,4 +574,8 @@ namespace etk { out += "}"; return out; } + + char toHexChar(uint8_t _value); + etk::String toHex(uint64_t _value, uint32_t _size = 2); + etk::String toBin(uint64_t _value, uint32_t _size = 1); } diff --git a/etk/UString.cpp b/etk/UString.cpp index 891bf01..0f220e5 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -991,3 +991,16 @@ etk::UString etk::operator+ (char32_t _left, const etk::UString& _right) { } + +namespace etk { +/* + template<> etk::UString toString(const etk::UString& _val) { + return _val; + } +*/ + template<> bool from_string(etk::UString& _variableRet, const etk::String& _value) { + _variableRet = utf8::convertUnicode(_value); + return true; + } +} + diff --git a/etk/Vector.hpp b/etk/Vector.hpp index 6690826..7c55997 100644 --- a/etk/Vector.hpp +++ b/etk/Vector.hpp @@ -223,6 +223,17 @@ namespace etk { changeAllocation(_count); m_size = _count; } + /** + * @brief List initializer (ex: etk::Vector plop = {"hello", world"} + * @param[in] _element element to add in the vector + */ + template + Vector(const ETK_VECTOR_TYPE_2& ... _args): + m_data(nullptr), + m_size(0), + m_allocated(0) { + pushBackN(_args...); + } /** * @brief Re-copy constructor (copy all needed data) * @param[in] _obj Vector that might be copy @@ -414,6 +425,19 @@ namespace etk { void pushFront(const ETK_VECTOR_TYPE * _item, size_t _nbElement) { insert(0, _item, _nbElement); } + /** + * @brief Add at the Last position of the Vector (move push) + * @param[in] _item Element to add at the end of vector + */ + void pushBack(ETK_VECTOR_TYPE&& _item) { + size_t idElement = m_size; + resize(m_size+1); + if (idElement < m_size) { + m_data[idElement] = etk::move(_item); + } else { + //TK_ERROR("Resize does not work correctly ... not added item"); + } + } /** * @brief Add at the Last position of the Vector * @param[in] _item Element to add at the end of vector @@ -446,6 +470,14 @@ namespace etk { m_data[idElement+iii] = _item[iii]; } } + void pushBackN(const ETK_VECTOR_TYPE& _value) { + pushBack(_value); + } + template + void pushBackN(const ETK_VECTOR_TYPE& _value, const ETK_VECTOR_TYPE_2& ... _args) { + pushBack(_value); + pushBackN(_args...); + } /** * @brief Remove the first element of the vector */ @@ -809,8 +841,8 @@ namespace etk { } }; //! @not_in_doc - template - bool isIn(const T& _val, const etk::Vector& _list) { + template + bool isIn(const ETK_VECTOR_TYPE_1& _val, const etk::Vector& _list) { for (size_t iii=0; iii<_list.size(); ++iii) { if (_list[iii] == _val) { return true; @@ -818,4 +850,19 @@ namespace etk { } return false; } + class Stream; + //! @not_in_doc + template + etk::Stream& operator <<(etk::Stream& _os, const etk::Vector& _obj) { + _os << "{"; + for (size_t iii=0; iii< _obj.size(); iii++) { + if (iii>0) { + _os << ";"; + } + _os << _obj[iii]; + } + _os << "}"; + return _os; + } + } diff --git a/etk/etk.cpp b/etk/etk.cpp index e261e44..db84391 100644 --- a/etk/etk.cpp +++ b/etk/etk.cpp @@ -10,10 +10,9 @@ #include #include #include -#include static int32_t nbTimeInit = 0; -uint32_t etk::MM___pppppp = 0; + void etk::unInit() { if (nbTimeInit > 1) { nbTimeInit--; diff --git a/etk/math/Matrix.hpp b/etk/math/Matrix.hpp index 3e5df3f..17e9254 100644 --- a/etk/math/Matrix.hpp +++ b/etk/math/Matrix.hpp @@ -534,7 +534,7 @@ namespace etk { */ void identity() { // copy data for the same size : - for (int32_t iii=0; iii< std::mim(m_size.x(), m_size.y()); iii++) { + for (int32_t iii=0; iii< etk::mim(m_size.x(), m_size.y()); iii++) { (*this)(iii,iii) = (T)1; } }; diff --git a/etk/math/Matrix2x2.cpp b/etk/math/Matrix2x2.cpp index 57388f4..0817c7f 100644 --- a/etk/math/Matrix2x2.cpp +++ b/etk/math/Matrix2x2.cpp @@ -192,14 +192,14 @@ etk::Matrix2x2 etk::Matrix2x2::zero() { } etk::Matrix2x2 etk::Matrix2x2::getAbsolute() const { - return Matrix2x2(std::abs(m_mat[0]), std::abs(m_mat[1]), - std::abs(m_mat[2]), std::abs(m_mat[3])); + return Matrix2x2(etk::abs(m_mat[0]), etk::abs(m_mat[1]), + etk::abs(m_mat[2]), etk::abs(m_mat[3])); } void etk::Matrix2x2::absolute() { - m_mat[0] = std::abs(m_mat[0]); - m_mat[1] = std::abs(m_mat[1]); - m_mat[2] = std::abs(m_mat[2]); - m_mat[3] = std::abs(m_mat[3]); + m_mat[0] = etk::abs(m_mat[0]); + m_mat[1] = etk::abs(m_mat[1]); + m_mat[2] = etk::abs(m_mat[2]); + m_mat[3] = etk::abs(m_mat[3]); } void etk::Matrix2x2::inverse() { @@ -208,7 +208,7 @@ void etk::Matrix2x2::inverse() { etk::Matrix2x2 etk::Matrix2x2::getInverse() const { float det = determinant(); - //assert(std::abs(det) > MACHINE_EPSILON); + //assert(etk::abs(det) > MACHINE_EPSILON); float invDet = 1.0f / det; return etk::Matrix2x2(m_mat[3], -m_mat[1], -m_mat[2], m_mat[0]) * invDet; } diff --git a/etk/math/Matrix3x3.cpp b/etk/math/Matrix3x3.cpp index 8dfadc7..0329621 100644 --- a/etk/math/Matrix3x3.cpp +++ b/etk/math/Matrix3x3.cpp @@ -146,21 +146,21 @@ etk::Matrix3x3 etk::Matrix3x3::zero() { } void etk::Matrix3x3::absolute() { - m_mat[0] = std::abs(m_mat[0]); - m_mat[1] = std::abs(m_mat[1]); - m_mat[2] = std::abs(m_mat[2]); - m_mat[3] = std::abs(m_mat[3]); - m_mat[4] = std::abs(m_mat[4]); - m_mat[5] = std::abs(m_mat[5]); - m_mat[6] = std::abs(m_mat[6]); - m_mat[7] = std::abs(m_mat[7]); - m_mat[8] = std::abs(m_mat[8]); + m_mat[0] = etk::abs(m_mat[0]); + m_mat[1] = etk::abs(m_mat[1]); + m_mat[2] = etk::abs(m_mat[2]); + m_mat[3] = etk::abs(m_mat[3]); + m_mat[4] = etk::abs(m_mat[4]); + m_mat[5] = etk::abs(m_mat[5]); + m_mat[6] = etk::abs(m_mat[6]); + m_mat[7] = etk::abs(m_mat[7]); + m_mat[8] = etk::abs(m_mat[8]); } etk::Matrix3x3 etk::Matrix3x3::getAbsolute() const { - return etk::Matrix3x3(std::abs(m_mat[0]), std::abs(m_mat[1]), std::abs(m_mat[2]), - std::abs(m_mat[3]), std::abs(m_mat[4]), std::abs(m_mat[5]), - std::abs(m_mat[6]), std::abs(m_mat[7]), std::abs(m_mat[8])); + return etk::Matrix3x3(etk::abs(m_mat[0]), etk::abs(m_mat[1]), etk::abs(m_mat[2]), + etk::abs(m_mat[3]), etk::abs(m_mat[4]), etk::abs(m_mat[5]), + etk::abs(m_mat[6]), etk::abs(m_mat[7]), etk::abs(m_mat[8])); } @@ -272,7 +272,7 @@ void etk::Matrix3x3::inverse() { etk::Matrix3x3 etk::Matrix3x3::getInverse() const { float det = determinant(); - //assert(std::abs(det) > MACHINE_EPSILON); + //assert(etk::abs(det) > MACHINE_EPSILON); float invDet = 1.0f / det; return etk::Matrix3x3( (m_mat[4]*m_mat[8]-m_mat[7]*m_mat[5]), -(m_mat[1]*m_mat[8]-m_mat[7]*m_mat[2]), diff --git a/etk/math/Matrix4x4.cpp b/etk/math/Matrix4x4.cpp index 5d22004..2e4ff7a 100644 --- a/etk/math/Matrix4x4.cpp +++ b/etk/math/Matrix4x4.cpp @@ -346,7 +346,7 @@ float etk::Matrix4x4::determinant() const { etk::Matrix4x4 etk::Matrix4x4::invert() { float det = determinant(); - if(std::abs(det) < (1.0e-7f)) { + if(etk::abs(det) < (1.0e-7f)) { // The matrix is not invertible! Singular case! return *this; } diff --git a/etk/math/Quaternion.cpp b/etk/math/Quaternion.cpp index f6c5f13..270f6bd 100644 --- a/etk/math/Quaternion.cpp +++ b/etk/math/Quaternion.cpp @@ -125,14 +125,14 @@ etk::Quaternion etk::Quaternion::slerp(const Quaternion& _obj1, void etk::Quaternion::setEulerAngles(const vec3& _angles) { float angle = _angles.x() * 0.5f; - float sinX = std::sin(angle); - float cosX = std::cos(angle); + float sinX = etk::sin(angle); + float cosX = etk::cos(angle); angle = _angles.y() * 0.5f; - float sinY = std::sin(angle); - float cosY = std::cos(angle); + float sinY = etk::sin(angle); + float cosY = etk::cos(angle); angle = _angles.z() * 0.5f; - float sinZ = std::sin(angle); - float cosZ = std::cos(angle); + float sinZ = etk::sin(angle); + float cosZ = etk::cos(angle); float cosYcosZ = cosY * cosZ; float sinYcosZ = sinY * cosZ; float cosYsinZ = cosY * sinZ; diff --git a/etk/math/Quaternion.hpp b/etk/math/Quaternion.hpp index 9443550..248fecd 100644 --- a/etk/math/Quaternion.hpp +++ b/etk/math/Quaternion.hpp @@ -188,7 +188,7 @@ namespace etk { */ float length() const { #if __CPP_VERSION__ >= 2011 && !defined(__TARGET_OS__MacOs) && !defined(__TARGET_OS__IOs) - return std::sqrt(length2()); + return etk::sqrt(length2()); #else return sqrt(length2()); #endif @@ -270,10 +270,10 @@ namespace etk { * @return New quaternion with the absolute value */ Quaternion absolute() const { - return Quaternion( std::abs(m_floats[0]), - std::abs(m_floats[1]), - std::abs(m_floats[2]), - std::abs(m_floats[3])); + return Quaternion( etk::abs(m_floats[0]), + etk::abs(m_floats[1]), + etk::abs(m_floats[2]), + etk::abs(m_floats[3])); } /** * @brief Get X value diff --git a/etk/math/Vector2D.cpp b/etk/math/Vector2D.cpp index e23ade4..11dbc44 100644 --- a/etk/math/Vector2D.cpp +++ b/etk/math/Vector2D.cpp @@ -87,8 +87,8 @@ etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector& _obj) vec2 vec2rotate(const vec2& _val, const vec2& _point, float _angle) { vec2 out = _val; #if __CPP_VERSION__ >= 2011 && !defined(__STDCPP_LLVM__) - float sinAngle = std::sin(_angle); - float cosAngle = std::cos(_angle); + float sinAngle = etk::sin(_angle); + float cosAngle = etk::cos(_angle); #else float sinAngle = sin(_angle); float cosAngle = cos(_angle); diff --git a/etk/math/Vector2D.hpp b/etk/math/Vector2D.hpp index 7e199b2..dbcb34a 100644 --- a/etk/math/Vector2D.hpp +++ b/etk/math/Vector2D.hpp @@ -365,7 +365,7 @@ namespace etk { */ float length() const { #if __CPP_VERSION__ >= 2011 && !defined(__STDCPP_LLVM__) - return std::sqrt(length2()); + return etk::sqrt(length2()); #else return sqrt(length2()); #endif @@ -421,8 +421,8 @@ namespace etk { * @return New vector containing the value */ Vector2D absolute() const { - return Vector2D( std::abs(m_floats[0]), - std::abs(m_floats[1])); + return Vector2D( etk::abs(m_floats[0]), + etk::abs(m_floats[1])); } /** * @brief Return the axis with the smallest value diff --git a/etk/math/Vector3D.hpp b/etk/math/Vector3D.hpp index 39a1418..c4defa2 100644 --- a/etk/math/Vector3D.hpp +++ b/etk/math/Vector3D.hpp @@ -185,7 +185,7 @@ namespace etk { */ float length() const { #if __CPP_VERSION__ >= 2011 && !defined(__STDCPP_LLVM__) - return std::sqrt(length2()); + return etk::sqrt(length2()); #else return sqrt(length2()); #endif @@ -274,9 +274,9 @@ namespace etk { * @return New vector containing the value */ Vector3D absolute() const { - return Vector3D( std::abs(m_floats[0]), - std::abs(m_floats[1]), - std::abs(m_floats[2])); + return Vector3D( etk::abs(m_floats[0]), + etk::abs(m_floats[1]), + etk::abs(m_floats[2])); } /** * @brief Return the cross product between this and another vector @@ -567,16 +567,16 @@ namespace etk { * @return The ortho vector */ Vector3D getOrthoVector() const { - Vector3D vectorAbs(std::abs(m_floats[0]), std::abs(m_floats[1]), std::abs(m_floats[2])); + Vector3D vectorAbs(etk::abs(m_floats[0]), etk::abs(m_floats[1]), etk::abs(m_floats[2])); int32_t minElement = vectorAbs.getMinAxis(); if (minElement == 0) { - float devider = 1.0f / std::sqrt(m_floats[1]*m_floats[1] + m_floats[2]*m_floats[2]); + float devider = 1.0f / etk::sqrt(m_floats[1]*m_floats[1] + m_floats[2]*m_floats[2]); return Vector3D(0.0f, -m_floats[2]*devider, m_floats[1]*devider); } else if (minElement == 1) { - float devider = 1.0f / std::sqrt(m_floats[0]*m_floats[0] + m_floats[2]*m_floats[2]); + float devider = 1.0f / etk::sqrt(m_floats[0]*m_floats[0] + m_floats[2]*m_floats[2]); return Vector3D(-m_floats[2]*devider, 0.0f, m_floats[0]*devider); } - float devider = 1.0f / std::sqrt(m_floats[0]*m_floats[0] + m_floats[1]*m_floats[1]); + float devider = 1.0f / etk::sqrt(m_floats[0]*m_floats[0] + m_floats[1]*m_floats[1]); return Vector3D(-m_floats[1]*devider, m_floats[0]*devider, 0.0f); } diff --git a/etk/math/Vector4D.hpp b/etk/math/Vector4D.hpp index fa33df4..ee0e4ad 100644 --- a/etk/math/Vector4D.hpp +++ b/etk/math/Vector4D.hpp @@ -178,7 +178,7 @@ namespace etk { return btSqrt(length2()); #else #if __CPP_VERSION__ >= 2011 && !defined(__TARGET_OS__MacOs) && !defined(__TARGET_OS__IOs) - return std::sqrt(length2()); + return etk::sqrt(length2()); #else return sqrt(length2()); #endif @@ -221,10 +221,10 @@ namespace etk { * @return New vector with the absolute value */ Vector4D absolute() const { - return Vector4D( std::abs(m_floats[0]), - std::abs(m_floats[1]), - std::abs(m_floats[2]), - std::abs(m_floats[3])); + return Vector4D( etk::abs(m_floats[0]), + etk::abs(m_floats[1]), + etk::abs(m_floats[2]), + etk::abs(m_floats[3])); } /** * @brief Multiply this vector by the other. diff --git a/etk/move.hpp b/etk/move.hpp index 67357d2..7e32a92 100644 --- a/etk/move.hpp +++ b/etk/move.hpp @@ -6,7 +6,6 @@ #pragma once #include -#include namespace etk { template struct RemoveReference { @@ -23,20 +22,11 @@ namespace etk { // remove rvalue reference typedef ETK_MOVE_TYPE m_type; }; - #if 0 - template inline - typename etk::RemoveReference::m_type&& move(ETK_MOVE_TYPE&& _obj) { - // forward _Arg as movable - return ((typename etk::RemoveReference::m_type&&)_obj); - } - #else - template inline - ETK_MOVE_TYPE move(const ETK_MOVE_TYPE& _obj) { - // forward _Arg as movable - return _obj; - } - #endif - + template + inline typename etk::RemoveReference::m_type&& move(ETK_MOVE_TYPE&& _obj) { + // forward _Arg as movable + return (typename etk::RemoveReference::m_type&&)_obj; + } template inline void swap(ETK_SWAP_TYPE& _obj1, ETK_SWAP_TYPE& _obj2) { diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 5b4602a..a725d60 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -8,21 +8,20 @@ #include #include #include -#include +#include #include #include #include #include #ifdef __TARGET_OS__Windows #include - #include #include #endif extern "C" { // file browsing ... #include #include - #include + #include } #ifdef HAVE_ZIP_DATA @@ -1702,7 +1701,7 @@ etk::Vector etk::FSNode::folderGetSub(bool _getFolder, bool _getFil } } } - std::sort(out.begin(), out.end()); + out.sort(0, out.size(), [](const etk::String& _left, const etk::String& _right) { return(_left<_right); }); return out; } #endif diff --git a/etk/os/Fifo.hpp b/etk/os/Fifo.hpp index e24bf72..34b083c 100644 --- a/etk/os/Fifo.hpp +++ b/etk/os/Fifo.hpp @@ -9,8 +9,8 @@ #pragma once #include +#include #include -#include namespace etk { /** @@ -21,7 +21,7 @@ namespace etk { template class Fifo { private : ethread::Mutex m_mutex; //!< protection of the internal data. - std::condition_variable m_condition; //!< Message system to send event on an other thread. + ethread::Semaphore m_semaphore; //!< protection of the internal data. etk::Vector m_data; //!< List of all message to send public : /** @@ -43,15 +43,15 @@ namespace etk { * @return false No data found or closed fifo */ bool wait(MY_TYPE &_data) { - std::unique_lock lock(m_mutex); // Check if data is not previously here while(m_data.size() == 0) { - m_condition.wait(lock); + m_semaphore.wait(); } + ethread::UniqueLock lock(m_mutex); // End Waiting message : if (m_data.size() > 0) { // copy element : - std::swap(_data, m_data[0]); + etk::swap(_data, m_data[0]); // remove element : m_data.erase(m_data.begin()); return true; @@ -66,17 +66,17 @@ namespace etk { * @return false No message found while time-out appear. */ bool wait(MY_TYPE &_data, uint32_t _timeOutInUs) { - std::unique_lock lock(m_mutex); // Check if data is not previously here while(m_data.size() == 0) { - if (m_condition.wait_for(lock, std::chrono::microseconds(_timeOutInUs)) == std::cv_status::timeout) { + if (m_semaphore.wait(_timeOutInUs) == false) { return false; } } + ethread::UniqueLock lock(m_mutex); // End Waiting message : if (m_data.size() > 0) { // copy element : - std::swap(_data, m_data[0]); + etk::swap(_data, m_data[0]); // remove element : m_data.erase(0); return true; @@ -88,7 +88,7 @@ namespace etk { * @return Number of message in the fifo. */ int32_t count() { - std::unique_lock lock(m_mutex); + ethread::UniqueLock lock(m_mutex); int32_t nbElement = m_data.size(); return nbElement; }; @@ -97,27 +97,28 @@ namespace etk { * @param[in] _data New data to add at the fifo. */ void post(MY_TYPE &_data) { - std::unique_lock lock(m_mutex); + ethread::UniqueLock lock(m_mutex); m_data.pushBack(_data); - m_condition.notify_all(); + m_semaphore.post(); }; /** * @brief Send a message at the other thread by setting a new message in the fifo. * @param[in] _data New data to add at the fifo. */ void post(const MY_TYPE &_data) { - std::unique_lock lock(m_mutex); + ethread::UniqueLock lock(m_mutex); m_data.pushBack(_data); - m_condition.notify_all(); + m_semaphore.post(); }; /** * @brief Remove all the message in the fifo. */ void clean() { - std::unique_lock lock(m_mutex); + ethread::UniqueLock lock(m_mutex); // remove data m_data.clear(); - m_condition.wait_for(lock, std::chrono::microseconds(0)); + //m_condition.wait_for(lock, echrono::microseconds(0)); + m_semaphore.post(); }; }; } diff --git a/etk/stdTools.hpp b/etk/stdTools.hpp index 11e8655..b899631 100644 --- a/etk/stdTools.hpp +++ b/etk/stdTools.hpp @@ -4,14 +4,60 @@ * @license MPL v2.0 (see license file) */ #pragma once +//#include namespace etk { + inline float cos(float _value) { + return ::cosf(_value); + } + inline float sin(float _value) { + return ::sinf(_value); + } + inline float tan(float _value) { + return ::tanf(_value); + } + inline float acos(float _value) { + return ::acosf(_value); + } + inline float asin(float _value) { + return ::asinf(_value); + } + inline float atan(float _value) { + return ::atanf(_value); + } + inline float sqrt(float _value) { + return ::sqrtf(_value); + } + inline double cos(double _value) { + return ::cos(_value); + } + inline double sin(double _value) { + return ::sin(_value); + } + inline double tan(double _value) { + return ::tan(_value); + } + inline double acos(double _value) { + return ::acos(_value); + } + inline double asin(double _value) { + return ::asin(_value); + } + inline double atan(double _value) { + return ::atan(_value); + } + inline double sqrt(double _value) { + return ::sqrt(_value); + } template const TYPE& min(const TYPE& _val1, const TYPE& _val2) { return (_val1 > _val2) ? _val2 : _val1; } template const TYPE& max(const TYPE& _val1, const TYPE& _val2) { return (_val1 > _val2) ? _val1 : _val2; } + template TYPE abs(const TYPE& _value) { + return (_value >= 0) ? _value : -_value; + } /** * @brief in std, we have min, max but not avg ==> it is missing... the Define of avg template. * @param[in] _min Minimum value of the range @@ -32,4 +78,14 @@ namespace etk { } return out; } + template + ETK_ITERATOR_TYPE_1 find(ETK_ITERATOR_TYPE_1 _start, ETK_ITERATOR_TYPE_1 _stop, const ETK_ITERATOR_TYPE_2& _value) { + while (_start != _stop) { + if (*_start == _value) { + return _start; + } + ++_start; + } + return _stop; + } } \ No newline at end of file diff --git a/etk/tool.cpp b/etk/tool.cpp index a63b918..012f0f5 100644 --- a/etk/tool.cpp +++ b/etk/tool.cpp @@ -6,11 +6,11 @@ #include #include -// for the rand ... -#include -#include - -#include +extern "C" { + #include + #include + #include +} double etk::tool::frand(double _a, double _b) { return (float)(( (double)rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a); @@ -19,6 +19,9 @@ double etk::tool::frand(double _a, double _b) { int32_t etk::tool::irand(int32_t _a, int32_t _b) { return (int32_t)(( rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a); } +uint32_t etk::tool::urand(uint32_t _a, uint32_t _b) { + return (uint32_t)(( rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a); +} void etk::tool::resetRandom() { srand(time(NULL)); diff --git a/etk/tool.hpp b/etk/tool.hpp index 5e331f7..1701df3 100644 --- a/etk/tool.hpp +++ b/etk/tool.hpp @@ -27,7 +27,8 @@ namespace etk { * @param[in] _b Bigger value of the random. * @return Random Value between [_a and _b] */ - int32_t irand(int32_t _a, int32_t _b); + int32_t irand(int32_t _a=0x80000000, int32_t _b=0x7FFFFFFF); + uint32_t urand(uint32_t _a=0, uint32_t _b=0xFFFFFFFF); /** * @brief Reset the random system with a random value (time). */ diff --git a/etk/utf8.hpp b/etk/utf8.hpp index 25cbe3c..b466ccd 100644 --- a/etk/utf8.hpp +++ b/etk/utf8.hpp @@ -66,9 +66,7 @@ namespace u32char { * @return Number of char in utf8 */ int8_t convertUtf8(char32_t _val, char _output[5]); - #if __CPP_VERSION__ >= 2011 - etk::String convertToUtf8(const etk::UString& _input); - #endif + etk::String convertToUtf8(const etk::UString& _input); char32_t toUpper(char32_t _input); char32_t toLower(char32_t _input); size_t strlen(const char32_t* _input); diff --git a/test/testQuaternion.cpp b/test/testQuaternion.cpp index 21fd2fb..eb84652 100644 --- a/test/testQuaternion.cpp +++ b/test/testQuaternion.cpp @@ -54,7 +54,7 @@ TEST(TestQuaternion, constructorMatrix) { TEST(TestQuaternion, constructorEuler) { etk::Quaternion test0(vec3(M_PI*0.5f, 0, 0)); - etk::Quaternion test01(std::sin(M_PI*0.25f), 0, 0, std::cos(M_PI*0.25f)); + etk::Quaternion test01(etk::sin(M_PI*0.25f), 0, 0, etk::cos(M_PI*0.25f)); test01.normalize(); EXPECT_FLOAT_EQ(test0.x(), test01.x()); EXPECT_FLOAT_EQ(test0.y(), test01.y()); @@ -62,7 +62,7 @@ TEST(TestQuaternion, constructorEuler) { EXPECT_FLOAT_EQ(test0.w(), test01.w()); etk::Quaternion test1(vec3(0, M_PI*0.5f, 0)); - etk::Quaternion test11(0, std::sin(M_PI*0.25f), 0, std::cos(M_PI*0.25f)); + etk::Quaternion test11(0, etk::sin(M_PI*0.25f), 0, etk::cos(M_PI*0.25f)); test11.normalize(); EXPECT_FLOAT_EQ(test1.x(), test11.x()); EXPECT_FLOAT_EQ(test1.y(), test11.y()); @@ -70,7 +70,7 @@ TEST(TestQuaternion, constructorEuler) { EXPECT_FLOAT_EQ(test1.w(), test11.w()); etk::Quaternion test2(vec3(0, 0, M_PI*0.5f)); - etk::Quaternion test21(0, 0, std::sin(M_PI*0.25f), std::cos(M_PI*0.25f)); + etk::Quaternion test21(0, 0, etk::sin(M_PI*0.25f), etk::cos(M_PI*0.25f)); test21.normalize(); EXPECT_FLOAT_EQ(test2.x(), test21.x()); EXPECT_FLOAT_EQ(test2.y(), test21.y()); diff --git a/test/testTrait.cpp b/test/testTrait.cpp index b8bd616..dd853da 100644 --- a/test/testTrait.cpp +++ b/test/testTrait.cpp @@ -10,27 +10,27 @@ #define NAME "Color" TEST(typeTrait, RemoveConstVolatile_1) { - typedef std::remove_cv::type type1; + typedef etk::RemoveConstVolatile::type type1; auto ret = etk::IsSame::value; EXPECT_EQ(ret, true); } TEST(typeTrait, RemoveConstVolatile_2) { - typedef std::remove_cv::type type1; + typedef etk::RemoveConstVolatile::type type1; auto ret = etk::IsSame::value; EXPECT_EQ(ret, true); } TEST(typeTrait, RemoveConstVolatile_3) { - typedef std::remove_cv::type type1; + typedef etk::RemoveConstVolatile::type type1; auto ret = etk::IsSame::value; EXPECT_EQ(ret, true); } TEST(typeTrait, RemoveConstVolatile_4) { - typedef std::remove_cv::type type1; + typedef etk::RemoveConstVolatile::type type1; auto ret = etk::IsSame::value; EXPECT_EQ(ret, true); } TEST(typeTrait, RemoveConstVolatile_5) { - typedef std::remove_cv::type type1; + typedef etk::RemoveConstVolatile::type type1; auto ret = etk::IsSame::value; EXPECT_EQ(ret, true); } @@ -192,3 +192,26 @@ TEST(typeTrait, IsUnion_4) { //etk::EnableIf>::value, uint32_t>::type plop = 55; etk::EnableIf::value, uint32_t>::type plop = 55; */ + +static uint32_t contructCount = 0; + +class PlopMove { + public: + PlopMove() { + contructCount ++; + } +}; + +void hello(PlopMove _val) { + contructCount += 1000; +} + +TEST(typeMove, move_1) { + contructCount = 0; + PlopMove value; + EXPECT_EQ(contructCount, 1); + hello(etk::move(value)); + EXPECT_EQ(contructCount, 1001); +} + +