diff --git a/etk/Buffer.h b/etk/Buffer.h deleted file mode 100644 index f47291f..0000000 --- a/etk/Buffer.h +++ /dev/null @@ -1,543 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#ifndef __ETK_BUFFER_H__ -#define __ETK_BUFFER_H__ - -#include - -#undef __class__ -#define __class__ "etk::Buffer" - -// minimum gapSize when allocated -#define GAP_SIZE_MIN (80) -// maximum gap that is automaticly resize -#define GAP_SIZE_MAX (GAP_SIZE_MIN*4) - -/* - ______________________________________________________________________________________ - | | - | | - | | - | | - | | - | | - | | - | | - | | - | | - | | - | | - | | - |____________________________________________________________________________________| -*/ - -namespace etk { - /** - * @brief This is an access on raw data that contain an internal gap. - * the gap size has an offset to increase an an offset to decrease. - */ - class Buffer { - private: - int8_t* m_data; //!< pointer on the curetn table of Data - int32_t m_allocated; //!< Current allocated size - // empty part of the buffer data - int32_t m_gapStart; //!< points to the first character of the gap - int32_t m_gapEnd; //!< points to the first char after the gap - public: - /** - * @brief Create an empty vector - * @param[in] _count Minimum request size of the Buffer - */ - Buffer(int32_t _count = 0) : - m_data(NULL), - m_allocated(0), - m_gapStart(0), - m_gapEnd(GAP_SIZE_MIN) { - changeAllocation(_count+GAP_SIZE_MIN); - } - /** - * @brief Re-copy constructor (copy all needed data) - * @param[in] _obj Buffer that might be copy - */ - Buffer(const etk::Buffer& _obj) : - m_data(NULL), - m_allocated(_obj.m_allocated), - m_gapStart(_obj.m_gapStart), - m_gapEnd(_obj.m_gapEnd) { - // allocate all same data - m_data = (int8_t *)malloc( m_allocated * sizeof(int8_t) ); - TK_ASSERT(NULL!=m_data, "Error in data allocation"); - // Copy all data ... - memcpy(m_data, _obj.m_data, m_allocated * sizeof(int8_t) ); - } - /** - * @brief Destructor of the current Class - */ - ~Buffer() { - if (m_data != NULL) { - free(m_data); - } - m_data = NULL; - m_allocated = 0; - m_gapStart = 0; - m_gapEnd = 0; - }; - /** - * @brief Store the selected data in the requested file. - * @param[in] _file Name of the file that might be written. - * @return true if the data corectly stored - * @return false if an error occured - */ - bool dumpIn(const std::string& _file) { - etk::FSNode file(_file); - if (false == file.fileOpenWrite()) { - return false; - } - bool ret = true; - // write Data - file.fileWrite(m_data, sizeof(int8_t), m_gapStart); - file.fileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd); - file.fileClose(); - return ret; - } - /** - * @brief Load data fron a selected file name. - * @param[in] _file Name of the file to store buffer data. - * @return true if the data corectly stored - * @return false if an error occured - */ - bool dumpFrom(const std::string& _file) { - etk::FSNode file(_file); - if (false == file.fileOpenRead()) { - return false; - } - bool ret = true; - int64_t length = file.fileSize(); - // error case ... - if (length > 2000000000) { - return false; - } - // allocate the current buffer : - changeAllocation(length + GAP_SIZE_MIN); - // insert Data - int32_t nbReadData = file.fileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length); - TK_INFO("load data : filesize=" << length << ", readData=" << nbReadData); - // check ERROR - if (nbReadData != length) { - TK_ERROR("load data pb : filesize=" << length << ", readData=" << nbReadData); - ret = false; - } - // set the gapsize at the fd ... - m_gapStart = 0; - m_gapEnd = GAP_SIZE_MIN; - file.fileClose(); - return ret; - } - - /** - * @brief Re-copy operator - * @param[in] _obj Buffer that might be copy - * @return reference on the curent copied Buffer - */ - etk::Buffer& operator=(const etk::Buffer& _obj) { - if( this == &_obj ) {// avoid copy to itself - return *this; - } - if (NULL != m_data) { - free(m_data); - m_data = NULL; - } - // Set the new value - m_allocated = _obj.m_allocated; - m_gapStart = _obj.m_gapStart; - m_gapEnd = _obj.m_gapEnd; - // allocate all same data - m_data = (int8_t *)malloc( m_allocated * sizeof(int8_t) ); - TK_ASSERT(NULL!=m_data, "Error in data allocation"); - // Copy all data ... - memcpy(m_data, _obj.m_data, m_allocated * sizeof(int8_t) ); - // Return the curent pointer - return *this; - } - /** - * @brief Get the data at the requested position (gap abstraction done). - * @param[in] _pos Position in the buffer. - * @return Element at the request pos. - */ - int8_t operator[] (int32_t _pos) const { - TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing"); - if (_pos < m_gapStart) { - return m_data[_pos]; - } - return m_data[_pos + m_gapEnd-m_gapStart]; - } - - /** - * @brief Get a current element in the vector - * @param[in] _pos Desired position read - * @return Reference on the Element - */ - int8_t& get(int32_t _pos) const { - TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing"); - if (_pos < m_gapStart) { - return m_data[_pos]; - } - return m_data[_pos + m_gapEnd-m_gapStart]; - } - /** - * @brief Get elements from a specific position. - * @param[in] _pos Position of the first element. - * @param[in] _nbElement Number of element needed. - * @return The data requested - */ - std::vector get(int32_t _pos, int32_t _nbElement) { - std::vector tmpBuffer; - tmpBuffer.clear(); - if (_pos < m_gapStart) { - if (_pos + _nbElement < m_gapStart) { - for (int32_t iii = _pos; iii<_pos+_nbElement; ++iii) { - tmpBuffer.push_back(m_data[iii]); - } - } else { - for (int32_t iii = _pos; iii size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size()); - return; - } - if( 0 == gapSize() ) { - if (false == gapResize(_pos, GAP_SIZE_MIN + 1) ) { - return; - } - } else if( _pos == m_gapStart - && _pos == m_gapEnd-1 ) - { - // mothing to do ... - } else { - if (gapMove(_pos) == false) { - return; - } - } - if(_pos == m_gapStart) { - m_data[m_gapStart] = _item; - m_gapStart++; - } else { - m_data[m_gapEnd-1] = _item; - m_gapEnd--; - } - } - /** - * @brief Insert data in the Buffer. - * @param[in] _pos Position where data might be inserted - * @param[in] _items Data that might be inserted. - */ - void insert(int32_t _pos, const std::vector& _items) { - insert(_pos, &_items[0], _items.size()); - } - /** - * @brief Insert data in the buffer - * @param[in] _pos Position where data might be inserted - * @param[in] _items Data that might be inserted. (no need of '\0') - * @param[in] _nbElement number of element to insert - */ - void insert(int32_t _pos, const int8_t* _items, int32_t _nbElement) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="< gapSize()) { - if (false == gapResize(_pos, GAP_SIZE_MIN + _nbElement) ) { - return; - } - } else { - if (false == gapMove(_pos) ) { - return; - } - } - for(int32_t iii=0; iii<_nbElement; ++iii) { - m_data[m_gapStart+iii] = _items[iii]; - } - m_gapStart += _nbElement; - } - /** - * @brief Replace one element in the buffer with an other. - * @param[in] _pos Position of the element to remove. - * @param[in] _items Element that might be inserted. - */ - void replace(int32_t _pos, const int8_t& _item) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="<& _items) { - replace(_pos, _nbRemoveElement, &_items[0], _items.size()); - } - /** - * @brief Replace a part of the buffer with the specified data. - * @param[in] _pos The first element to remove. - * @param[in] _nbRemoveElement number of element to remove. - * @param[in] _items Data that might be inserted. - * @param[in] _nbElement Number of element that might be added. - */ - void replace(int32_t _pos, int32_t _nbRemoveElement, const int8_t* _items, int32_t _nbElement) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="< size() ) { - TK_ERROR("Request remove more element than expected in the buffer pos+nbRemoveElement=" - << _pos+_nbRemoveElement << " bufferSize=" << size()); - return; - } - if (false == gapMove(_pos)) { - return; - } - // Remove elements : - m_gapEnd += _nbRemoveElement; - //Display(); - // insert elements - insert(_pos, _items, _nbElement); - // Resize buffer if needed... - gapCheckMaxSize(); - } - /** - * @brief Remove specific data in the buffer. - * @param[in] _pos The first element to remove. - * @param[in] _nbRemoveElement Number of element to remove. - */ - void remove(int32_t _pos, int32_t _nbRemoveElement = 1) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="< size() ) { - TK_ERROR("Request remove more element than expected in the buffer pos+nbRemoveElement=" - << _pos+_nbRemoveElement << " bufferSize=" << size()); - return; - } - if (gapMove(_pos) == false) { - return; - } - // Remove elements : - if (m_allocated == m_gapEnd) { - m_gapStart -= _nbRemoveElement; - } else { - m_gapEnd += _nbRemoveElement; - } - // Resize buffer if needed... - gapCheckMaxSize(); - } - /** - * @brief Remove the last element of the Buffer. - */ - void pop_back() { - if (size() > 0) { - remove( size() ); - } - } - /** - * @brief Remove all the data in the buffer. - */ - void clear() { - remove(0, size() ); - } - protected: - /** - * @brief Get a current element in the Buffer (iterator system) - * @param[in] _realElementPosition Real position in the buffer (only use in the ITERATOR) - * @return Reference on the Element - */ - int8_t& getDirect(int32_t _realElementPosition) { - return m_data[_realElementPosition]; - }; - public: - /** - * @brief Get the number of element in the vector. This does not contain the gap size. - * @return The size of the set data. - */ - int32_t size() const { - return m_allocated - gapSize(); - }; - private: - /** - * @brief Change the current allocation to the new one (depend on the current size) - * @param[in] _newSize Minimum number of element needed - */ - void changeAllocation(int32_t _newSize) { - // set the minimal size to 1 - if(_newSize <= 0) { - _newSize = 1; - } - // set the size with the corect chose type : - if (_newSize == m_allocated) { - return; - } - //TODO : use new and delete and multiple of power of 2. - TK_DEBUG("Change Allocation : " << m_allocated << " ==> " << _newSize); - // check if something is allocated : - if (m_data == NULL) { - // no data allocated ==> request an allocation (might be the first) - m_data = (int8_t *)malloc( _newSize * sizeof(int8_t) ); - } else { - // move datas - m_data = (int8_t *)realloc( m_data, _newSize* sizeof(int8_t) ); - } - // Check result with assert : - TK_ASSERT(m_data != NULL, "Error in data allocation"); - // set the new allocation size - m_allocated = _newSize; - } - /** - * @brief Move the current gap at an other position - * @param[in] _pos Position of the new Gap. - * @return false The operation can not be proccesed. - * @return true The operation done correctly. - */ - bool gapMove(int32_t _pos) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size()); - return false; - } - int32_t gapLen = m_gapEnd - m_gapStart; - if (_pos > m_gapStart) { - memmove(&m_data[m_gapStart], &m_data[m_gapEnd], _pos - m_gapStart); - } else { - memmove(&m_data[_pos + gapLen], &m_data[_pos], m_gapStart - _pos); - } - m_gapEnd += _pos - m_gapStart; - m_gapStart += _pos - m_gapStart; - return true; - } - /** - * @brief Change The gap position and size - * @param[in] _pos Position of the new Gap. - * @param[in] _newGapLen Size of the new gap (can be bigger than GAP_SIZE_MAX). - * @return false The operation can not be done. - * @return true The operation done correctly. - */ - bool gapResize(int32_t _pos, int32_t _newGapLen) { - if( _pos > size() - || _pos < 0 ) { - TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size()); - return false; - } - int32_t previousSize = size(); - if (_newGapLen == gapSize() ) { - // nothing to do ... - return true; - } else { - if (_newGapLen > gapSize() ) { - // reallocation - changeAllocation( previousSize + _newGapLen); - } - // move Data - if (_pos <= m_gapStart) { - // just move the end of the gap - memmove(&m_data[m_gapStart + _newGapLen], &m_data[m_gapEnd], previousSize - m_gapStart); - // update gap end position - m_gapEnd = m_gapStart + _newGapLen; - if (_pos < m_gapStart) { - if (false == gapMove(_pos)) { - return false; - } - } - } else { - if (false == gapMove(_pos) ) { - return false; - } - memmove(&m_data[m_gapStart + _newGapLen], &m_data[m_gapEnd], previousSize - m_gapStart); - } - if (_newGapLen < gapSize() ) { - // rellocation - changeAllocation(previousSize + _newGapLen); - } - } - // update gap position - m_gapStart = _pos; - m_gapEnd = _pos + _newGapLen; - return true; - } - /** - * @brief Get the current gap size. - * @return The number of element in the gap. - */ - int32_t gapSize() const { - return m_gapEnd - m_gapStart; - } - /** - * @brief Control if the writing gap is not too big (automatic call when resize the buffer). - */ - void gapCheckMaxSize() { - if(gapSize() > GAP_SIZE_MAX) { - int32_t currentSize = size(); - // Change the gap Size - if (false == gapResize(m_gapStart, GAP_SIZE_MAX) ) { - return; - } - // remove deprecated elements at the end of the buffer ... - changeAllocation(currentSize + GAP_SIZE_MAX); - } - } - }; -}; - -#undef __class__ -#define __class__ NULL - - -#endif diff --git a/etk/Color_16_bits.cxx b/etk/Color_16_bits.cxx index abe95e0..3379f2a 100644 --- a/etk/Color_16_bits.cxx +++ b/etk/Color_16_bits.cxx @@ -385,72 +385,80 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_32_bits.cxx b/etk/Color_32_bits.cxx index 649666e..e84a63b 100644 --- a/etk/Color_32_bits.cxx +++ b/etk/Color_32_bits.cxx @@ -385,70 +385,74 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_8_bits.cxx b/etk/Color_8_bits.cxx index 02b8cbc..3674e91 100644 --- a/etk/Color_8_bits.cxx +++ b/etk/Color_8_bits.cxx @@ -384,18 +384,19 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } @@ -403,53 +404,56 @@ template<> bool from_string>(Color& _variableRet, -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_double.cxx b/etk/Color_double.cxx index 5fa2168..ff02d17 100644 --- a/etk/Color_double.cxx +++ b/etk/Color_double.cxx @@ -385,18 +385,19 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } @@ -404,18 +405,19 @@ template<> bool from_string>(Color& _variableRet, co -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } @@ -423,36 +425,38 @@ template<> bool from_string>(Color& _variableRet, co -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_float.cxx b/etk/Color_float.cxx index ed68d25..3a46231 100644 --- a/etk/Color_float.cxx +++ b/etk/Color_float.cxx @@ -383,69 +383,73 @@ template<> template<> Color::Color(const Color& _obj) { } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string>(const Color& _val) { +template<> std::string to_string >(const Color& _val) { return _val.getString(); } -template<> std::u32string to_u32string>(const Color& _val) { - return to_u32string(_val.getString()); -} - -template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { - _variableRet = Color(to_string(_value)); - return true; -} -template<> bool from_string>(Color& _variableRet, const std::string& _value) { +#if __cplusplus >= 201103L + template<> std::u32string to_u32string>(const Color& _val) { + return to_u32string(_val.getString()); + } + template<> bool from_string>(Color& _variableRet, const std::u32string& _value) { + _variableRet = Color(to_string(_value)); + return true; + } +#endif +template<> bool from_string >(Color& _variableRet, const std::string& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/archive/Archive.cpp b/etk/archive/Archive.cpp index ec91728..182e141 100644 --- a/etk/archive/Archive.cpp +++ b/etk/archive/Archive.cpp @@ -5,6 +5,7 @@ * * @license APACHE v2.0 (see license file) */ +#ifdef ETK_BUILD_MINIZIP #include #include @@ -100,3 +101,5 @@ void etk::Archive::close(const std::string& _key) { it->second.decreaseRef(); } } + +#endif \ No newline at end of file diff --git a/etk/archive/Archive.h b/etk/archive/Archive.h index 02de257..dd30da7 100644 --- a/etk/archive/Archive.h +++ b/etk/archive/Archive.h @@ -5,6 +5,7 @@ * * @license APACHE v2.0 (see license file) */ +#ifdef ETK_BUILD_MINIZIP #include @@ -139,3 +140,4 @@ namespace etk { }; #endif +#endif \ No newline at end of file diff --git a/etk/archive/Zip.cpp b/etk/archive/Zip.cpp index 973b20f..a2e54b0 100644 --- a/etk/archive/Zip.cpp +++ b/etk/archive/Zip.cpp @@ -6,25 +6,11 @@ * @license APACHE v2.0 (see license file) */ +#ifdef ETK_BUILD_MINIZIP + #include #include -#ifndef ETK_BUILD_MINIZIP -etk::archive::Zip::Zip(const std::string& _fileName) : - etk::Archive(_fileName) { - TK_WARNING("No archive interface (not compiled with) minizip lib"); - return; -} - -etk::archive::Zip::~Zip() { - return; -} - -void etk::archive::Zip::loadFile(const std::map::iterator& it) { - TK_ERROR("Can not load File with no Archive interface"); - return; -} -#else etk::archive::Zip::Zip(const std::string& _fileName) : etk::Archive(_fileName), m_ctx(nullptr) { diff --git a/etk/archive/Zip.h b/etk/archive/Zip.h index bb31c76..b24559c 100644 --- a/etk/archive/Zip.h +++ b/etk/archive/Zip.h @@ -14,24 +14,22 @@ extern "C" { #include } -#endif - -namespace etk { - namespace archive { - class Zip : public etk::Archive { - #ifdef ETK_BUILD_MINIZIP + namespace etk { + namespace archive { + class Zip : public etk::Archive { private: unzFile m_ctx; //!< mini zip context unz_global_info m_info; //!< global information of the Zip - #endif - public: - Zip(const std::string& _fileName); - virtual ~Zip(); - protected: // herited functions : - virtual void loadFile(const std::map::iterator& it); + public: + Zip(const std::string& _fileName); + virtual ~Zip(); + protected: // herited functions : + virtual void loadFile(const std::map::iterator& it); + }; }; }; -}; + +#endif #endif diff --git a/etk/boost_to_std/etk/chrono.h b/etk/boost_to_std/etk/chrono.h new file mode 100644 index 0000000..1e119b1 --- /dev/null +++ b/etk/boost_to_std/etk/chrono.h @@ -0,0 +1,7 @@ + +#ifndef __ETK_CHRONO_FROM_BOOST_H__ +#define __ETK_CHRONO_FROM_BOOST_H__ + +#include + +#endif diff --git a/etk/boost_to_std/etk/condition_variable.h b/etk/boost_to_std/etk/condition_variable.h new file mode 100644 index 0000000..49088bf --- /dev/null +++ b/etk/boost_to_std/etk/condition_variable.h @@ -0,0 +1,7 @@ + +#ifndef __ETK_CONDITION_VARIABLE_FROM_BOOST_H__ +#define __ETK_CONDITION_VARIABLE_FROM_BOOST_H__ + +#include + +#endif diff --git a/etk/boost_to_std/etk/functional.h b/etk/boost_to_std/etk/functional.h new file mode 100644 index 0000000..9db78fa --- /dev/null +++ b/etk/boost_to_std/etk/functional.h @@ -0,0 +1,10 @@ + +#ifndef __ETK_FUNCTIONNAL_FROM_BOOST_H__ +#define __ETK_FUNCTIONNAL_FROM_BOOST_H__ + +#include +#include +#include + + +#endif diff --git a/etk/boost_to_std/etk/memory.h b/etk/boost_to_std/etk/memory.h new file mode 100644 index 0000000..42837f2 --- /dev/null +++ b/etk/boost_to_std/etk/memory.h @@ -0,0 +1,11 @@ + +#ifndef __ETK_MEMORY_FROM_BOOST_H__ +#define __ETK_MEMORY_FROM_BOOST_H__ + +#include +#include +#include +#include + + +#endif diff --git a/etk/boost_to_std/etk/mutex.h b/etk/boost_to_std/etk/mutex.h new file mode 100644 index 0000000..aead315 --- /dev/null +++ b/etk/boost_to_std/etk/mutex.h @@ -0,0 +1,8 @@ + +#ifndef __ETK_MUTEX_FROM_BOOST_H__ +#define __ETK_MUTEX_FROM_BOOST_H__ + +#include +#include + +#endif diff --git a/etk/boost_to_std/etk/thread.h b/etk/boost_to_std/etk/thread.h new file mode 100644 index 0000000..d306e3e --- /dev/null +++ b/etk/boost_to_std/etk/thread.h @@ -0,0 +1,7 @@ + +#ifndef __ETK_THREAD_FROM_BOOST_H__ +#define __ETK_THREAD_FROM_BOOST_H__ + +#include + +#endif diff --git a/etk/log.cpp b/etk/log.cpp index 1262ea6..a13d2c6 100644 --- a/etk/log.cpp +++ b/etk/log.cpp @@ -8,8 +8,12 @@ #include #include -#include -#include +#if __cplusplus >= 201103L + #include + #include +#else + #include +#endif #include #include @@ -89,8 +93,8 @@ int32_t& getsizeLog() { static int32_t g_val = 5; return g_val; } -static std::vector>& getList() { - static std::vector> g_val; +static std::vector >& getList() { + static std::vector > g_val; return g_val; } @@ -224,52 +228,62 @@ static std::map& getThreadList() { } std::string etk::log::getThreadName() { - std::map& list = getThreadList(); - uint32_t threadID = getThreadID(); - std::string out; - static std::mutex g_lock; - g_lock.lock(); - auto it = list.find(threadID); - if (it != list.end()) { - out = it->second; - } - g_lock.unlock(); - return out; + #if __cplusplus >= 201103L + std::map& list = getThreadList(); + uint32_t threadID = getThreadID(); + std::string out; + static std11::mutex g_lock; + g_lock.lock(); + auto it = list.find(threadID); + if (it != list.end()) { + out = it->second; + } + g_lock.unlock(); + return out; + #else + return ""; + #endif } void etk::log::setThreadName(const std::string& _name) { - std::map& list = getThreadList(); - uint32_t threadID = getThreadID(); - static std::mutex g_lock; - g_lock.lock(); - auto it = list.find(threadID); - if (it == list.end()) { - list.insert(std::pair(threadID,_name)); - } else { - it->second = _name; - } - g_lock.unlock(); + #if __cplusplus >= 201103L + std::map& list = getThreadList(); + uint32_t threadID = getThreadID(); + static std11::mutex g_lock; + g_lock.lock();-Wc++0x-compat + auto it = list.find(threadID); + if (it == list.end()) { + list.insert(std::pair(threadID,_name)); + } else { + it->second = _name; + } + g_lock.unlock(); + #endif } uint32_t etk::log::getThreadID() { - uint32_t out = 0; - std::thread::id this_id = std::this_thread::get_id(); - uint64_t iddd = std::hash()(this_id); - static std::mutex g_lock; - g_lock.lock(); - static std::map g_list; - auto it = g_list.find(iddd); - if (it == g_list.end()) { - // attribute new ID : - static uint32_t tmpId = 0; - g_list.insert(std::pair(iddd,tmpId)); - out = tmpId; - tmpId++; - } else { - out = it->second; - } - g_lock.unlock(); - return out; + #if __cplusplus >= 201103L + uint32_t out = 0; + std::thread::id this_id = std::this_thread::get_id(); + uint64_t iddd = std::hash()(this_id); + static std11::mutex g_lock; + g_lock.lock(); + static std::map g_list; + auto it = g_list.find(iddd); + if (it == g_list.end()) { + // attribute new ID : + static uint32_t tmpId = 0; + g_list.insert(std::pair(iddd,tmpId)); + out = tmpId; + tmpId++; + } else { + out = it->second; + } + g_lock.unlock(); + return out; + #else + return 0; + #endif } static void getDisplayTime(char* data) { @@ -320,7 +334,7 @@ static void getDisplayTime(char* data) { void etk::log::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _className, const char* _funcName, const char* _log) { - static std::mutex g_lock; + static std11::mutex g_lock; char handle[1024] = ""; memset(handle, ' ', 1024); handle[0] = '\0'; @@ -393,30 +407,32 @@ void etk::log::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* *pointer++ = ' '; *pointer = '\0'; } - if(getThreadId() == true) { - // display thread ID - uint32_t iddd = etk::log::getThreadID(); - sprintf(pointer, "%3d", iddd); - pointer = handle+strlen(handle); - *pointer++ = ' '; - *pointer++ = '|'; - *pointer++ = ' '; - *pointer = '\0'; - } - if(getThreadNameEnable() == true) { - // display thread ID - std::string name = etk::log::getThreadName(); - int32_t len = strlen(handle); - snprintf(pointer, 20, "%s", name.c_str()); - pointer = handle+strlen(handle); - while (strlen(handle) - len < 20) { + #if __cplusplus >= 201103L + if(getThreadId() == true) { + // display thread ID + uint32_t iddd = etk::log::getThreadID(); + sprintf(pointer, "%3d", iddd); + pointer = handle+strlen(handle); + *pointer++ = ' '; + *pointer++ = '|'; *pointer++ = ' '; *pointer = '\0'; } - *pointer++ = '|'; - *pointer++ = ' '; - *pointer = '\0'; - } + if(getThreadNameEnable() == true) { + // display thread ID + std::string name = etk::log::getThreadName(); + int32_t len = strlen(handle); + snprintf(pointer, 20, "%s", name.c_str()); + pointer = handle+strlen(handle); + while (strlen(handle) - len < 20) { + *pointer++ = ' '; + *pointer = '\0'; + } + *pointer++ = '|'; + *pointer++ = ' '; + *pointer = '\0'; + } + #endif if(getLine() == true) { if (_ligne >= 0) { sprintf(pointer, "(l=%5d)", _ligne); diff --git a/etk/math/Vector2D.cpp b/etk/math/Vector2D.cpp index 910aea4..1caabce 100644 --- a/etk/math/Vector2D.cpp +++ b/etk/math/Vector2D.cpp @@ -87,7 +87,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector& _ob vec2 vec2rotate(const vec2& _val, const vec2& _point, float _angle) { vec2 out = _val; - #if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs)) + #if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs) || __cplusplus < 201103L) float sinAngle = sin(_angle); float cosAngle = cos(_angle); #else @@ -118,15 +118,17 @@ namespace etk { str += ")"; return str; } - template<> Vector2D::operator std::u32string() const { - std::u32string str; - str = U"("; - str += etk::to_u32string(x()); - str += U","; - str += etk::to_u32string(y()); - str += U")"; - return str; - } + #if __cplusplus >= 201103L + template<> Vector2D::operator std::u32string() const { + std::u32string str; + str = U"("; + str += etk::to_u32string(x()); + str += U","; + str += etk::to_u32string(y()); + str += U")"; + return str; + } + #endif template<> Vector2D::Vector2D(const std::string& _str) { m_floats[0] = false; @@ -152,30 +154,32 @@ namespace etk { } TK_VERBOSE("Parse : '" << _str << "' ==> " << *this); } - template<> Vector2D::Vector2D(const std::u32string& _str) { - m_floats[0] = false; - m_floats[1] = false; - // copy to permit to modify it : - std::u32string tmpStr = _str; - if (tmpStr[0] == '(') { - tmpStr.erase(tmpStr.begin()); + #if __cplusplus >= 201103L + template<> Vector2D::Vector2D(const std::u32string& _str) { + m_floats[0] = false; + m_floats[1] = false; + // copy to permit to modify it : + std::u32string tmpStr = _str; + if (tmpStr[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (tmpStr[tmpStr.size()-1] == ')') { + tmpStr.erase(tmpStr.end()-1); + } + size_t posComa = tmpStr.find(','); + if (posComa == std::string::npos) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = etk::string_to_bool(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = etk::string_to_bool(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0, posComa+1); + m_floats[1] = etk::string_to_bool(tmpStr); + } + TK_VERBOSE("Parse : '" << _str << "' ==> " << *this); } - if (tmpStr[tmpStr.size()-1] == ')') { - tmpStr.erase(tmpStr.end()-1); - } - size_t posComa = tmpStr.find(','); - if (posComa == std::string::npos) { - // no coma ... - // in every case, we parse the first element : - m_floats[0] = etk::string_to_bool(tmpStr); - m_floats[1] = m_floats[0]; - } else { - m_floats[0] = etk::string_to_bool(std::u32string(tmpStr, 0, posComa)); - tmpStr.erase(0, posComa+1); - m_floats[1] = etk::string_to_bool(tmpStr); - } - TK_VERBOSE("Parse : '" << _str << "' ==> " << *this); - } + #endif template<> Vector2D::operator std::string() const { std::string str; @@ -186,15 +190,17 @@ namespace etk { str += ")"; return str; } - template<> Vector2D::operator std::u32string() const { - std::u32string str; - str = U"("; - str += etk::to_u32string(x()); - str += U","; - str += etk::to_u32string(y()); - str += U")"; - return str; - } + #if __cplusplus >= 201103L + template<> Vector2D::operator std::u32string() const { + std::u32string str; + str = U"("; + str += etk::to_u32string(x()); + str += U","; + str += etk::to_u32string(y()); + str += U")"; + return str; + } + #endif template<> Vector2D::Vector2D(const std::string& _str) { m_floats[0] = 0; @@ -221,31 +227,33 @@ namespace etk { } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::Vector2D(const std::u32string& _str) { - m_floats[0] = 0; - m_floats[1] = 0; - // copy to permit to modify it : - std::u32string tmpStr = _str; - if (tmpStr[0] == '(') { - tmpStr.erase(tmpStr.begin()); + #if __cplusplus >= 201103L + template<> Vector2D::Vector2D(const std::u32string& _str) { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::u32string tmpStr = _str; + if (tmpStr[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (tmpStr[tmpStr.size()-1] == ')') { + tmpStr.erase(tmpStr.end()-1); + } + + size_t posComa = tmpStr.find(','); + if (posComa == 0) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = etk::string_to_int32_t(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = etk::string_to_int32_t(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - if (tmpStr[tmpStr.size()-1] == ')') { - tmpStr.erase(tmpStr.end()-1); - } - - size_t posComa = tmpStr.find(','); - if (posComa == 0) { - // no coma ... - // in every case, we parse the first element : - m_floats[0] = etk::string_to_int32_t(tmpStr); - m_floats[1] = m_floats[0]; - } else { - m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); - tmpStr.erase(0,posComa+1); - m_floats[1] = etk::string_to_int32_t(tmpStr); - } - TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); - } + #endif template<> Vector2D::operator std::string() const { std::string str; @@ -256,16 +264,17 @@ namespace etk { str += ")"; return str; } - - template<> Vector2D::operator std::u32string() const { - std::u32string str; - str = U"("; - str += etk::to_u32string(x()); - str += U","; - str += etk::to_u32string(y()); - str += U")"; - return str; - } + #if __cplusplus >= 201103L + template<> Vector2D::operator std::u32string() const { + std::u32string str; + str = U"("; + str += etk::to_u32string(x()); + str += U","; + str += etk::to_u32string(y()); + str += U")"; + return str; + } + #endif template<> Vector2D::Vector2D(const std::string& _str) { m_floats[0] = 0; @@ -291,31 +300,32 @@ namespace etk { } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::Vector2D(const std::u32string& _str) - { - m_floats[0] = 0; - m_floats[1] = 0; - // copy to permit to modify it : - std::u32string tmpStr = _str; - if (tmpStr[0] == '(') { - tmpStr.erase(tmpStr.begin()); + #if __cplusplus >= 201103L + template<> Vector2D::Vector2D(const std::u32string& _str) { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::u32string tmpStr = _str; + if (tmpStr[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (tmpStr[tmpStr.size()-1] == ')') { + tmpStr.erase(tmpStr.end()-1); + } + size_t posComa = tmpStr.find(','); + if (posComa == std::string::npos) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = etk::string_to_int32_t(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = etk::string_to_int32_t(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - if (tmpStr[tmpStr.size()-1] == ')') { - tmpStr.erase(tmpStr.end()-1); - } - size_t posComa = tmpStr.find(','); - if (posComa == std::string::npos) { - // no coma ... - // in every case, we parse the first element : - m_floats[0] = etk::string_to_int32_t(tmpStr); - m_floats[1] = m_floats[0]; - } else { - m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); - tmpStr.erase(0,posComa+1); - m_floats[1] = etk::string_to_int32_t(tmpStr); - } - TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); - } + #endif template<> Vector2D::operator std::string() const { std::string str; @@ -326,15 +336,17 @@ namespace etk { str += ")"; return str; } - template<> Vector2D::operator std::u32string() const { - std::u32string str; - str = U"("; - str += etk::to_u32string(x()); - str += U","; - str += etk::to_u32string(y()); - str += U")"; - return str; - } + #if __cplusplus >= 201103L + template<> Vector2D::operator std::u32string() const { + std::u32string str; + str = U"("; + str += etk::to_u32string(x()); + str += U","; + str += etk::to_u32string(y()); + str += U")"; + return str; + } + #endif template<> Vector2D::Vector2D(const std::string& _str) { m_floats[0] = 0; @@ -360,30 +372,32 @@ namespace etk { } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::Vector2D(const std::u32string& _str) { - m_floats[0] = 0; - m_floats[1] = 0; - // copy to permit to modify it : - std::u32string tmpStr = _str; - if (tmpStr[0] == '(') { - tmpStr.erase(tmpStr.begin()); + #if __cplusplus >= 201103L + template<> Vector2D::Vector2D(const std::u32string& _str) { + m_floats[0] = 0; + m_floats[1] = 0; + // copy to permit to modify it : + std::u32string tmpStr = _str; + if (tmpStr[0] == '(') { + tmpStr.erase(tmpStr.begin()); + } + if (tmpStr[tmpStr.size()-1] == ')') { + tmpStr.erase(tmpStr.end()-1); + } + size_t posComa = tmpStr.find(','); + if (posComa == std::string::npos) { + // no coma ... + // in every case, we parse the first element : + m_floats[0] = etk::string_to_float(tmpStr); + m_floats[1] = m_floats[0]; + } else { + m_floats[0] = etk::string_to_float(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = etk::string_to_float(tmpStr); + } + TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - if (tmpStr[tmpStr.size()-1] == ')') { - tmpStr.erase(tmpStr.end()-1); - } - size_t posComa = tmpStr.find(','); - if (posComa == std::string::npos) { - // no coma ... - // in every case, we parse the first element : - m_floats[0] = etk::string_to_float(tmpStr); - m_floats[1] = m_floats[0]; - } else { - m_floats[0] = etk::string_to_float(std::u32string(tmpStr, 0, posComa)); - tmpStr.erase(0,posComa+1); - m_floats[1] = etk::string_to_float(tmpStr); - } - TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); - } + #endif template<> std::string to_string(const vec2& _obj) { std::string str; @@ -394,9 +408,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const vec2& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const vec2& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const ivec2& _obj) { std::string str; @@ -407,9 +423,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const ivec2& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const ivec2& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const uivec2& _obj) { std::string str; @@ -420,9 +438,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const uivec2& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const uivec2& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const bvec2& _obj) { std::string str; @@ -433,39 +453,49 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const bvec2& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const bvec2& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> bool from_string(vec2& _variableRet, const std::string& _value) { _variableRet = vec2(_value); return true; } - template<> bool from_string(vec2& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(vec2& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(ivec2& _variableRet, const std::string& _value) { _variableRet = ivec2(_value); return true; } - template<> bool from_string(ivec2& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(ivec2& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(uivec2& _variableRet, const std::string& _value) { _variableRet = uivec2(_value); return true; } - template<> bool from_string(uivec2& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(uivec2& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(bvec2& _variableRet, const std::string& _value) { _variableRet = bvec2(_value); return true; } - template<> bool from_string(bvec2& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(bvec2& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif }; diff --git a/etk/math/Vector2D.h b/etk/math/Vector2D.h index 5501c6a..e4128ac 100644 --- a/etk/math/Vector2D.h +++ b/etk/math/Vector2D.h @@ -48,7 +48,9 @@ namespace etk { m_floats[1] = (T)_obj.y(); }; Vector2D(const std::string& _str); - Vector2D(const std::u32string& _str); + #if __cplusplus >= 201103L + Vector2D(const std::u32string& _str); + #endif ~Vector2D() { }; /* **************************************************** * = assigment @@ -371,7 +373,9 @@ namespace etk { } //!< string cast : operator std::string() const; - operator std::u32string() const; + #if __cplusplus >= 201103L + operator std::u32string() const; + #endif }; /** * @brief Debug operator To display the curent element in a Human redeable information diff --git a/etk/math/Vector3D.cpp b/etk/math/Vector3D.cpp index 3d59a69..6ac7040 100644 --- a/etk/math/Vector3D.cpp +++ b/etk/math/Vector3D.cpp @@ -124,9 +124,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const vec3& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const vec3& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const ivec3& _obj) { std::string str; @@ -139,9 +141,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const ivec3& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const ivec3& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const uivec3& _obj) { std::string str; @@ -154,9 +158,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const uivec3& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const uivec3& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> std::string to_string(const bvec3& _obj) { std::string str; @@ -169,9 +175,11 @@ namespace etk { str += ")"; return str; } - template<> std::u32string to_u32string(const bvec3& _obj) { - return etk::to_u32string(etk::to_string(_obj)); - } + #if __cplusplus >= 201103L + template<> std::u32string to_u32string(const bvec3& _obj) { + return etk::to_u32string(etk::to_string(_obj)); + } + #endif template<> bool from_string(vec3& _variableRet, const std::string& _value) { float floats[3]; @@ -212,9 +220,11 @@ namespace etk { TK_VERBOSE("Parse : '" << _value << "' ==> " << _variableRet); return true; } - template<> bool from_string(vec3& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(vec3& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(ivec3& _variableRet, const std::string& _value) { int32_t floats[3]; @@ -255,9 +265,11 @@ namespace etk { TK_VERBOSE("Parse : '" << _value << "' ==> " << _variableRet); return true; } - template<> bool from_string(ivec3& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(ivec3& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(uivec3& _variableRet, const std::string& _value) { uint32_t floats[3]; @@ -298,9 +310,11 @@ namespace etk { TK_VERBOSE("Parse : '" << _value << "' ==> " << _variableRet); return true; } - template<> bool from_string(uivec3& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(uivec3& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif template<> bool from_string(bvec3& _variableRet, const std::string& _value) { bool floats[3]; @@ -341,7 +355,9 @@ namespace etk { TK_VERBOSE("Parse : '" << _value << "' ==> " << _variableRet); return true; } - template<> bool from_string(bvec3& _variableRet, const std::u32string& _value) { - return from_string(_variableRet, etk::to_string(_value)); - } + #if __cplusplus >= 201103L + template<> bool from_string(bvec3& _variableRet, const std::u32string& _value) { + return from_string(_variableRet, etk::to_string(_value)); + } + #endif }; diff --git a/etk/math/Vector3D.h b/etk/math/Vector3D.h index 5023cc0..9cc6bce 100644 --- a/etk/math/Vector3D.h +++ b/etk/math/Vector3D.h @@ -159,7 +159,11 @@ namespace etk { #ifdef ETK_BUILD_LINEARMATH return btSqrt(length2()); #else - return std::sqrt(length2()); + #if __cplusplus >= 201103L + return std::sqrt(length2()); + #else + return sqrt(length2()); + #endif #endif } diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 558d03d..42cd4e6 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -276,9 +276,11 @@ std::string getApplicationPath() { TK_INFO("Binary name : " << binaryName); return binaryName; } -std::u32string getUApplicationPath() { - return etk::to_u32string(getApplicationPath()); -} +#if __cplusplus >= 201103L + std::u32string getUApplicationPath() { + return etk::to_u32string(getApplicationPath()); + } +#endif void etk::initDefaultFolder(const char* _applName) { baseApplName = _applName; @@ -388,16 +390,20 @@ void etk::initDefaultFolder(const char* _applName) { std::string etk::getUserHomeFolder() { return baseFolderHome; } -std::u32string etk::getUUserHomeFolder() { - return etk::to_u32string(baseFolderHome); -} +#if __cplusplus >= 201103L + std::u32string etk::getUUserHomeFolder() { + return etk::to_u32string(baseFolderHome); + } +#endif std::string etk::getUserRunFolder() { return baseRunPath; } -std::u32string etk::getUUserRunFolder() { - return etk::to_u32string(baseRunPath); -} +#if __cplusplus >= 201103L + std::u32string etk::getUUserRunFolder() { + return etk::to_u32string(baseRunPath); + } +#endif #ifdef __TARGET_OS__Android @@ -484,22 +490,23 @@ etk::FSNode::FSNode(const std::string& _nodeName) : { privateSetName(_nodeName); } - -etk::FSNode::FSNode(const std::u32string& _nodeName) : - m_userFileName(""), - m_type(etk::FSN_TYPE_UNKNOW), - m_typeNode(etk::FSN_UNKNOW), - m_PointerFile(NULL), - m_timeCreate(0), - m_timeModify(0), - m_timeAccess(0) -#ifdef __TARGET_OS__Android - , m_zipContent(NULL), - m_zipReadingOffset(-1) +#if __cplusplus >= 201103L + etk::FSNode::FSNode(const std::u32string& _nodeName) : + m_userFileName(""), + m_type(etk::FSN_TYPE_UNKNOW), + m_typeNode(etk::FSN_UNKNOW), + m_PointerFile(NULL), + m_timeCreate(0), + m_timeModify(0), + m_timeAccess(0) + #ifdef __TARGET_OS__Android + , m_zipContent(NULL), + m_zipReadingOffset(-1) + #endif + { + privateSetName(_nodeName); + } #endif -{ - privateSetName(_nodeName); -} etk::FSNode::~FSNode() { @@ -702,9 +709,11 @@ void etk::FSNode::privateSetName(const std::string& _newName) { updateFileSystemProperty(); TK_DBG_MODE("6 : type : [" << m_typeNode << "] right :" << m_rights); } -void etk::FSNode::privateSetName(const std::u32string& _newName) { - privateSetName(etk::to_string(_newName)); -} +#if __cplusplus >= 201103L + void etk::FSNode::privateSetName(const std::u32string& _newName) { + privateSetName(etk::to_string(_newName)); + } +#endif bool directCheckFile(std::string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { #ifdef __TARGET_OS__Android @@ -723,9 +732,11 @@ bool directCheckFile(std::string _tmpFileNameDirect, bool _checkInAPKIfNeeded = } return true; } -bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { - return directCheckFile(etk::to_string(_tmpFileNameDirect)); -} +#if __cplusplus >= 201103L + bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { + return directCheckFile(etk::to_string(_tmpFileNameDirect)); + } +#endif // Now we generate the real FS path: void etk::FSNode::generateFileSystemPath() { switch (m_type) { @@ -916,9 +927,11 @@ bool etk::FSNode::setRight(etk::FSNodeRight _newRight) { void etk::FSNode::setName(const std::string& _newName) { privateSetName(_newName); } -void etk::FSNode::setName(const std::u32string& _newName) { - privateSetName(_newName); -} +#if __cplusplus >= 201103L + void etk::FSNode::setName(const std::u32string& _newName) { + privateSetName(_newName); + } +#endif std::string etk::FSNode::getNameFolder() const { size_t lastPos = m_systemFileName.rfind('/'); @@ -927,16 +940,20 @@ std::string etk::FSNode::getNameFolder() const { } return ""; } -std::u32string etk::FSNode::getUNameFolder() const { - return etk::to_u32string(getNameFolder()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::getUNameFolder() const { + return etk::to_u32string(getNameFolder()); + } +#endif std::string etk::FSNode::getFileSystemName() const { return m_systemFileName; } -std::u32string etk::FSNode::getUFileSystemName() const { - return etk::to_u32string(getFileSystemName()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::getUFileSystemName() const { + return etk::to_u32string(getFileSystemName()); + } +#endif std::string etk::FSNode::getName() const { std::string output; @@ -971,9 +988,11 @@ std::string etk::FSNode::getName() const { output += m_userFileName; return output; } -std::u32string etk::FSNode::getUName() const { - return etk::to_u32string(getName()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::getUName() const { + return etk::to_u32string(getName()); + } +#endif std::string etk::FSNode::getNameFile() const { size_t lastPos = m_systemFileName.rfind('/'); @@ -982,9 +1001,11 @@ std::string etk::FSNode::getNameFile() const { } return ""; } -std::u32string etk::FSNode::getUNameFile() const { - return etk::to_u32string(getNameFile()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::getUNameFile() const { + return etk::to_u32string(getNameFile()); + } +#endif std::string etk::FSNode::getRelativeFolder() const { std::string tmppp = getName(); @@ -1024,9 +1045,11 @@ std::string etk::FSNode::getRelativeFolder() const { TK_DBG_MODE(" ==> : ''" ); return ""; } -std::u32string etk::FSNode::getURelativeFolder() const { - return etk::to_u32string(getRelativeFolder()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::getURelativeFolder() const { + return etk::to_u32string(getRelativeFolder()); + } +#endif bool etk::FSNode::touch() { @@ -1054,9 +1077,11 @@ bool etk::FSNode::move(const std::string& _path) { return true; } } -bool etk::FSNode::move(const std::u32string& _path) { - return move(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + bool etk::FSNode::move(const std::u32string& _path) { + return move(etk::to_string(_path)); + } +#endif bool etk::FSNode::remove() { if (getNodeType()==etk::FSN_FOLDER) { @@ -1089,9 +1114,11 @@ std::string etk::FSNode::timeCreatedString() const { } return tmpTime; } -std::u32string etk::FSNode::timeUCreatedString() const { - return etk::to_u32string(timeCreatedString()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::timeUCreatedString() const { + return etk::to_u32string(timeCreatedString()); + } +#endif uint64_t etk::FSNode::timeModified() const { return m_timeModify; @@ -1105,9 +1132,11 @@ std::string etk::FSNode::timeModifiedString() const { } return tmpTime; } -std::u32string etk::FSNode::timeUModifiedString() const { - return etk::to_u32string(timeModifiedString()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::timeUModifiedString() const { + return etk::to_u32string(timeModifiedString()); + } +#endif uint64_t etk::FSNode::timeAccessed() const { return m_timeAccess; @@ -1121,9 +1150,11 @@ std::string etk::FSNode::timeAccessedString() const { } return tmpTime; } -std::u32string etk::FSNode::timeUAccessedString() const { - return etk::to_u32string(timeAccessedString()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNode::timeUAccessedString() const { + return etk::to_u32string(timeAccessedString()); + } +#endif /* Operator : */ @@ -1437,14 +1468,16 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, boo } return; } -void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { - _output.clear(); - std::vector tmpVal; - folderGetRecursiveFiles(tmpVal, _recursiveEnable); - for (size_t iii=0; iii= 201103L + void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { + _output.clear(); + std::vector tmpVal; + folderGetRecursiveFiles(tmpVal, _recursiveEnable); + for (size_t iii=0; iii= 201103L + std::u32string etk::FSNode::fileUGetExtention() { + return etk::to_u32string(fileGetExtention()); + } +#endif uint64_t etk::FSNode::fileSize() { if (etk::FSN_FILE != m_typeNode) { @@ -1823,66 +1858,99 @@ static std::map g_listTheme; void etk::theme::setName(const std::string& _refName, const std::string& _folderName) { TK_WARNING("Change theme : '" << _refName << "' : '" << _folderName << "'"); - auto it = g_listTheme.find(_refName); + #if __cplusplus >= 201103L + auto it = g_listTheme.find(_refName); + #else + std::map::iterator it = g_listTheme.find(_refName); + #endif if (it != g_listTheme.end()) { it->second = _folderName; return; } g_listTheme.insert(std::pair(_refName, _folderName)); } -void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) { - setName(etk::to_string(_refName), etk::to_string(_folderName)); -} +#if __cplusplus >= 201103L + void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) { + setName(etk::to_string(_refName), etk::to_string(_folderName)); + } +#endif std::string etk::theme::getName(const std::string& _refName) { - auto it=g_listTheme.find(_refName); + #if __cplusplus >= 201103L + auto it = g_listTheme.find(_refName); + #else + std::map::iterator it = g_listTheme.find(_refName); + #endif if (it != g_listTheme.end()) { return it->second; } return _refName; } -std::u32string etk::theme::getName(const std::u32string& _refName) { - return etk::to_u32string(getName(etk::to_string(_refName))); -} +#if __cplusplus >= 201103L + std::u32string etk::theme::getName(const std::u32string& _refName) { + return etk::to_u32string(getName(etk::to_string(_refName))); + } +#endif // get the list of all the theme folder availlable in the user Home/appl std::vector etk::theme::list() { std::vector keys; - for (auto &it : g_listTheme) { - keys.push_back(it.first); - } + #if __cplusplus >= 201103L + for (auto &it : g_listTheme) { + keys.push_back(it.first); + } + #else + for (std::map::iterator it(g_listTheme.begin()); it != g_listTheme.end(); ++it) { + keys.push_back(it->first); + } + #endif return keys; } -std::vector etk::theme::listU() { - std::vector keys; - for (auto &it : g_listTheme) { - keys.push_back(etk::to_u32string(it.first)); +#if __cplusplus >= 201103L + std::vector etk::theme::listU() { + std::vector keys; + for (auto &it : g_listTheme) { + keys.push_back(etk::to_u32string(it.first)); + } + return keys; } - return keys; -} +#endif static std::map g_listThemeDefault; void etk::theme::setNameDefault(const std::string& _refName, const std::string& _folderName) { - auto it = g_listThemeDefault.find(_refName); + #if __cplusplus >= 201103L + auto it = g_listThemeDefault.find(_refName); + #else + std::map::iterator it = g_listThemeDefault.find(_refName); + #endif if (it != g_listThemeDefault.end()) { it->second = _folderName; return; } g_listThemeDefault.insert(std::pair(_refName, _folderName)); } -void etk::theme::setNameDefault(const std::u32string& _refName, const std::u32string& _folderName) { - setNameDefault(etk::to_string(_refName), etk::to_string(_folderName)); -} +#if __cplusplus >= 201103L + void etk::theme::setNameDefault(const std::u32string& _refName, const std::u32string& _folderName) { + setNameDefault(etk::to_string(_refName), etk::to_string(_folderName)); + } +#endif + std::string etk::theme::getNameDefault(const std::string& _refName) { - auto it=g_listThemeDefault.find(_refName); + #if __cplusplus >= 201103L + auto it=g_listThemeDefault.find(_refName); + #else + std::map::iterator it = g_listThemeDefault.find(_refName); + #endif if (it != g_listThemeDefault.end()) { return it->second; } return "default"; } -std::u32string etk::theme::getNameDefault(const std::u32string& _refName) { - return etk::to_u32string(getNameDefault(etk::to_string(_refName))); -} +#if __cplusplus >= 201103L + std::u32string etk::theme::getNameDefault(const std::u32string& _refName) { + return etk::to_u32string(getNameDefault(etk::to_string(_refName))); + } +#endif @@ -1898,9 +1966,11 @@ bool etk::FSNodeRemove(const std::string& _path) { } return tmpNode.remove(); } -bool etk::FSNodeRemove(const std::u32string& _path) { - return FSNodeRemove(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeRemove(const std::u32string& _path) { + return FSNodeRemove(etk::to_string(_path)); + } +#endif int64_t etk::FSNodeGetCount(const std::string& _path) { etk::FSNode tmpNode(_path); @@ -1909,25 +1979,31 @@ int64_t etk::FSNodeGetCount(const std::string& _path) { } return tmpNode.folderCount(); } -int64_t etk::FSNodeGetCount(const std::u32string& _path) { - return FSNodeGetCount(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + int64_t etk::FSNodeGetCount(const std::u32string& _path) { + return FSNodeGetCount(etk::to_string(_path)); + } +#endif bool etk::FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { // TODO : return false; } -bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { - return FSNodeCreate(etk::to_string(_path), _right, _type); -} +#if __cplusplus >= 201103L + bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { + return FSNodeCreate(etk::to_string(_path), _right, _type); + } +#endif bool etk::FSNodeExist(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.exist(); } -bool etk::FSNodeExist(const std::u32string& _path) { - return FSNodeExist(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeExist(const std::u32string& _path) { + return FSNodeExist(etk::to_string(_path)); + } +#endif bool etk::FSNodeMove(const std::string& _path1, const std::string& _path2) { etk::FSNode tmpNode(_path1); @@ -1940,57 +2016,71 @@ bool etk::FSNodeMove(const std::string& _path1, const std::string& _path2) { //move the node return tmpNode.move(_path2); } -bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) { - return FSNodeMove(etk::to_string(_path1), etk::to_string(_path2)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) { + return FSNodeMove(etk::to_string(_path1), etk::to_string(_path2)); + } +#endif etk::FSNodeRight etk::FSNodeGetRight(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getRight(); } -etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) { - return FSNodeGetRight(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) { + return FSNodeGetRight(etk::to_string(_path)); + } +#endif enum etk::typeNode etk::FSNodeGetType(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getNodeType(); } -enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) { - return FSNodeGetType(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) { + return FSNodeGetType(etk::to_string(_path)); + } +#endif uint64_t etk::FSNodeGetTimeCreated(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeCreated(); } -uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) { - return FSNodeGetTimeCreated(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) { + return FSNodeGetTimeCreated(etk::to_string(_path)); + } +#endif uint64_t etk::FSNodeGetTimeModified(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeModified(); } -uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) { - return FSNodeGetTimeModified(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) { + return FSNodeGetTimeModified(etk::to_string(_path)); + } +#endif uint64_t etk::FSNodeGetTimeAccessed(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeAccessed(); } -uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) { - return FSNodeGetTimeAccessed(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) { + return FSNodeGetTimeAccessed(etk::to_string(_path)); + } +#endif bool etk::FSNodeTouch(const std::string& _path) { etk::FSNode tmpNode(_path); return tmpNode.touch(); } -bool etk::FSNodeTouch(const std::u32string& _path) { - return FSNodeTouch(etk::to_string(_path)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeTouch(const std::u32string& _path) { + return FSNodeTouch(etk::to_string(_path)); + } +#endif bool etk::FSNodeEcho(const std::string& _path, const std::string& _dataTowrite) { etk::FSNode tmpNode(_path); @@ -2010,9 +2100,11 @@ bool etk::FSNodeEcho(const std::string& _path, const std::string& _dataTowrite) } return tmpNode.fileClose(); } -bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) { - return FSNodeEcho(etk::to_string(_path), etk::to_string(_dataTowrite)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) { + return FSNodeEcho(etk::to_string(_path), etk::to_string(_dataTowrite)); + } +#endif bool etk::FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrite) { etk::FSNode tmpNode(_path); @@ -2032,9 +2124,11 @@ bool etk::FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrit } return tmpNode.fileClose(); } -bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) { - return FSNodeEchoAdd(etk::to_string(_path), etk::to_string(_dataTowrite)); -} +#if __cplusplus >= 201103L + bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) { + return FSNodeEchoAdd(etk::to_string(_path), etk::to_string(_dataTowrite)); + } +#endif void etk::FSNodeHistory(const std::string& _path, int32_t _historyCount) { // step 1 : Move the file to prevent writing error @@ -2048,9 +2142,11 @@ void etk::FSNodeHistory(const std::string& _path, int32_t _historyCount) { etk::FSNodeMove(_path, _path + "-1"); } } -void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { - return FSNodeHistory(etk::to_string(_path), _historyCount); -} +#if __cplusplus >= 201103L + void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { + return FSNodeHistory(etk::to_string(_path), _historyCount); + } +#endif std::string etk::FSNodeReadAllData(const std::string& _path) { std::string output; diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index dbcd182..df1dc95 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -141,7 +141,9 @@ namespace etk { * @param[in] _path Path of the curent file /folder ... */ FSNode(const std::string& _path = "~"); - FSNode(const std::u32string& _path); + #if __cplusplus >= 201103L + FSNode(const std::u32string& _path); + #endif /** * @brief Destructor * @note you will have some warning if you did not close your files @@ -161,7 +163,9 @@ namespace etk { * @param[in] _newName Name of the Node */ void privateSetName(const std::string& _newName); - void privateSetName(const std::u32string& _newName); + #if __cplusplus >= 201103L + void privateSetName(const std::u32string& _newName); + #endif private: #ifdef __TARGET_OS__Android /** @@ -210,40 +214,52 @@ namespace etk { * @return false : action not done */ void setName(const std::string& _newName); - void setName(const std::u32string& _newName); + #if __cplusplus >= 201103L + void setName(const std::u32string& _newName); + #endif /** * @brief Get the Generate FileSystem name * @return the requested filename */ std::string getFileSystemName() const; - std::u32string getUFileSystemName() const; + #if __cplusplus >= 201103L + std::u32string getUFileSystemName() const; + #endif /** * @brief Get the current folder of the Node. (file system name) * @return the common name define (like /xxxxx/xxxxx/ or c:/xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ std::string getNameFolder() const; - std::u32string getUNameFolder() const; + #if __cplusplus >= 201103L + std::u32string getUNameFolder() const; + #endif /** * @brief Get the current compleate node name (file system name) * @return All the user name definition (like /xxxxx/xxxxx/myFile.kkk or c:/xxxxx/xxxxx/myFile.kkk) * @note Auto remove of ../../../ and // */ std::string getName() const; - std::u32string getUName() const; + #if __cplusplus >= 201103L + std::u32string getUName() const; + #endif /** * @brief Get the file or current file name (if it was a file) * @return the name of the node (like myFile.kkk) */ std::string getNameFile() const; - std::u32string getUNameFile() const; + #if __cplusplus >= 201103L + std::u32string getUNameFile() const; + #endif /** * @brief Get the current folder of the Node. * @return the common name define (like DATA:xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ std::string getRelativeFolder() const; - std::u32string getURelativeFolder() const; + #if __cplusplus >= 201103L + std::u32string getURelativeFolder() const; + #endif /** * @brief update the Time of the file with the current time * @return true : action done @@ -257,7 +273,9 @@ namespace etk { * @return false : action not done */ bool move(const std::string& _path); - bool move(const std::u32string& _path); + #if __cplusplus >= 201103L + bool move(const std::u32string& _path); + #endif /** * @brief Get the node type (DATA/DIRECT...) * @return the requested type @@ -281,7 +299,9 @@ namespace etk { * @return The time requested (in string) */ std::string timeCreatedString() const; - std::u32string timeUCreatedString() const; + #if __cplusplus >= 201103L + std::u32string timeUCreatedString() const; + #endif /** * @brief Get the modifying time of the File * @return The time requested @@ -292,7 +312,9 @@ namespace etk { * @return The time requested (in string) */ std::string timeModifiedString() const; - std::u32string timeUModifiedString() const; + #if __cplusplus >= 201103L + std::u32string timeUModifiedString() const; + #endif /** * @brief Get the Accessed time of the File * @return The time requested @@ -303,7 +325,9 @@ namespace etk { * @return The time requested (in string) */ std::string timeAccessedString() const; - std::u32string timeUAccessedString() const; + #if __cplusplus >= 201103L + std::u32string timeUAccessedString() const; + #endif /** * @brief copy the other FSnode ==> for vector * @param[in] _obj input node @@ -359,7 +383,9 @@ namespace etk { * @param[in] _recursiveEnable Activate the recursive mode (enable by default) */ void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); - void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); + #if __cplusplus >= 201103L + void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); + #endif /** * @brief Check if the file have an extention ( ***.ccc) * @return true The file have an extention. @@ -371,7 +397,9 @@ namespace etk { * @return the requested extention */ std::string fileGetExtention(); - std::u32string fileUGetExtention(); + #if __cplusplus >= 201103L + std::u32string fileUGetExtention(); + #endif /** * @brief Get the File size * @return the requested size @@ -496,9 +524,11 @@ namespace etk { fileRead(&value[0], sizeof(char), fileSize()/sizeof(char)); return value; } + #if __cplusplus >= 201103L std::u32string fileReadAllU32String() { return utf8::convertUnicode(fileReadAllString()); } + #endif /** * @brief Write all the vector in a file */ @@ -508,9 +538,11 @@ namespace etk { void fileWriteAll(const std::string& _value) { fileWrite(static_cast(&(_value[0])), sizeof(char), _value.size()/sizeof(char)); } - void fileWriteAll(const std::u32string& _value) { - fileWriteAll(u32char::convertToUtf8(_value)); - } + #if __cplusplus >= 201103L + void fileWriteAll(const std::u32string& _value) { + fileWriteAll(u32char::convertToUtf8(_value)); + } + #endif private: /** * @brief Order the list of subnode the folder first and the alphabetical order @@ -546,13 +578,17 @@ namespace etk { * @return the home folder : like : "/home/machin/" */ std::string getUserHomeFolder(); - std::u32string getUUserHomeFolder(); + #if __cplusplus >= 201103L + std::u32string getUUserHomeFolder(); + #endif /** * @brief Get the folder of the Program is running * @return the basic folder name (ex : run ./appl in the pwd=/home/machin/sousFolder ==> this return the pwd folder) */ std::string getUserRunFolder(); - std::u32string getUUserRunFolder(); + #if __cplusplus >= 201103L + std::u32string getUUserRunFolder(); + #endif namespace theme { // TODO : Add an INIT ... @@ -562,40 +598,49 @@ namespace etk { * @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/") */ void setName(const std::string& _refName, const std::string& _folderName); - //! @previous - void setName(const std::u32string& _refName, const std::u32string& _folderName); + #if __cplusplus >= 201103L + //! @previous + void setName(const std::u32string& _refName, const std::u32string& _folderName); + #endif /** * @brief get the folder from a Reference theme * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @return the path of the theme */ std::string getName(const std::string& _refName); - //! @previous - std::u32string getName(const std::u32string& _refName); - + #if __cplusplus >= 201103L + //! @previous + std::u32string getName(const std::u32string& _refName); + #endif /** * @brief Set the default folder of a subset of a theme ... * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @param[in] _folderName The associated default folder of the Theme (like "myTheme/color/default/") */ void setNameDefault(const std::string& _refName, const std::string& _folderName); - //! @previous - void setNameDefault(const std::u32string& _refName, const std::u32string& _folderName); + #if __cplusplus >= 201103L + //! @previous + void setNameDefault(const std::u32string& _refName, const std::u32string& _folderName); + #endif /** * @brief get the default folder from a Reference theme * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @return the path of the theme */ std::string getNameDefault(const std::string& _refName); - //! @previous - std::u32string getNameDefault(const std::u32string& _refName); + #if __cplusplus >= 201103L + //! @previous + std::u32string getNameDefault(const std::u32string& _refName); + #endif /** * @brief Get the list of all the theme folder availlable in the user Home/appl * @return The list of elements */ std::vector list(); - //! @previous - std::vector listU(); + #if __cplusplus >= 201103L + //! @previous + std::vector listU(); + #endif }; /** @@ -605,7 +650,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeRemove(const std::string& _path); - bool FSNodeRemove(const std::u32string& _path); + #if __cplusplus >= 201103L + bool FSNodeRemove(const std::u32string& _path); + #endif /** * @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1) * @param[in] _path Folder/File/Pipe path of the node @@ -613,7 +660,9 @@ namespace etk { * @return -1 : An error occured */ int64_t FSNodeGetCount(const std::string& _path); - int64_t FSNodeGetCount(const std::u32string& _path); + #if __cplusplus >= 201103L + int64_t FSNodeGetCount(const std::u32string& _path); + #endif /** * @brief Simple access for : Create a file or a folder depending of the request * @param[in] _path Folder/File/Pipe path of the node @@ -623,7 +672,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); - bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); + #if __cplusplus >= 201103L + bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); + #endif /** * @brief Simple access for : chexk the exestance of an element * @param[in] _path Folder/File/Pipe path of the node @@ -631,7 +682,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeExist(const std::string& _path); - bool FSNodeExist(const std::u32string& _path); + #if __cplusplus >= 201103L + bool FSNodeExist(const std::u32string& _path); + #endif /** * @brief Simple access for : chexk the exestance of an element * @param[in] _path1 Folder/File/Pipe path of the node sources @@ -640,7 +693,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeMove(const std::string& _path1, const std::string& _path2); - bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); + #if __cplusplus >= 201103L + bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); + #endif /** * @brief Simple access for : Get right of the current Node * @param[in] _path Folder/File/Pipe path of the node @@ -648,7 +703,9 @@ namespace etk { * @return false : An error occured */ etk::FSNodeRight FSNodeGetRight(const std::string& _path); - etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); + #if __cplusplus >= 201103L + etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); + #endif /** * @brief Simple access for : Get type of the current node * @param[in] _path Folder/File/Pipe path of the node @@ -656,7 +713,9 @@ namespace etk { * @return false : An error occured */ enum etk::typeNode FSNodeGetType(const std::string& _path); - enum etk::typeNode FSNodeGetType(const std::u32string& _path); + #if __cplusplus >= 201103L + enum etk::typeNode FSNodeGetType(const std::u32string& _path); + #endif /** * @brief Simple access for : Getting creation time of the current node * @param[in] _path Folder/File/Pipe path of the node @@ -664,7 +723,9 @@ namespace etk { * @return false : An error occured */ uint64_t FSNodeGetTimeCreated(const std::string& _path); - uint64_t FSNodeGetTimeCreated(const std::u32string& _path); + #if __cplusplus >= 201103L + uint64_t FSNodeGetTimeCreated(const std::u32string& _path); + #endif /** * @brief Simple access for : Getting Modification time of the current node * @param[in] _path Folder/File/Pipe path of the node @@ -672,7 +733,9 @@ namespace etk { * @return false : An error occured */ uint64_t FSNodeGetTimeModified(const std::string& _path); - uint64_t FSNodeGetTimeModified(const std::u32string& _path); + #if __cplusplus >= 201103L + uint64_t FSNodeGetTimeModified(const std::u32string& _path); + #endif /** * @brief Simple access for : Getting Accessing time of the current node * @param[in] _path Folder/File/Pipe path of the node @@ -680,7 +743,9 @@ namespace etk { * @return false : An error occured */ uint64_t FSNodeGetTimeAccessed(const std::string& _path); - uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); + #if __cplusplus >= 201103L + uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); + #endif /** * @brief Simple access for : Update Modification time with the current time of the node (>) * @param[in] _path Folder/File/Pipe path of the node @@ -688,7 +753,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeTouch(const std::string& _path); - bool FSNodeTouch(const std::u32string& _path); + #if __cplusplus >= 201103L + bool FSNodeTouch(const std::u32string& _path); + #endif /** * @brief Simple access for : Basic write on the node (like console echo) * @param[in] _path Folder/File/Pipe path of the node @@ -697,7 +764,9 @@ namespace etk { * @return false : An error occured */ bool FSNodeEcho(const std::string& _path, const std::string& _dataTowrite); - bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); + #if __cplusplus >= 201103L + bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); + #endif /** * @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>) * @param[in] _path Folder/File/Pipe path of the node @@ -706,14 +775,18 @@ namespace etk { * @return false : An error occured */ bool FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrite); - bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); + #if __cplusplus >= 201103L + bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); + #endif /** * @brief move file to generate an history of the current file * @param[in] _path Folder/File/Pipe path of the node * @param[in] _historyCount number of saved file in the history (-xxx) */ void FSNodeHistory(const std::string& _path, int32_t _historyCount); - void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); + #if __cplusplus >= 201103L + void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); + #endif /** * @brief Read all the data from a file * @param[in] _path Folder/File/Pipe path of the node diff --git a/etk/os/FSNodeRight.cpp b/etk/os/FSNodeRight.cpp index d3af577..ce027c9 100644 --- a/etk/os/FSNodeRight.cpp +++ b/etk/os/FSNodeRight.cpp @@ -174,10 +174,11 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus) m_rights |= RIGHT_OTHER_EXECUTE; } } - -std::u32string etk::FSNodeRight::getURight() const { - return etk::to_u32string(getRight()); -} +#if __cplusplus >= 201103L + std::u32string etk::FSNodeRight::getURight() const { + return etk::to_u32string(getRight()); + } +#endif std::string etk::FSNodeRight::getRight() const { std::string tmp; diff --git a/etk/os/FSNodeRight.h b/etk/os/FSNodeRight.h index e313599..a51abc5 100644 --- a/etk/os/FSNodeRight.h +++ b/etk/os/FSNodeRight.h @@ -48,8 +48,9 @@ namespace etk { void setOtherReadable(bool _newStatus); void setOtherWritable(bool _newStatus); void setOtherRunable(bool _newStatus); - - std::u32string getURight() const; + #if __cplusplus >= 201103L + std::u32string getURight() const; + #endif std::string getRight() const; }; std::ostream& operator <<(std::ostream &_os, const etk::FSNodeRight &_obj); diff --git a/etk/stdTools.cpp b/etk/stdTools.cpp index ed814fe..cb64aa3 100644 --- a/etk/stdTools.cpp +++ b/etk/stdTools.cpp @@ -130,12 +130,12 @@ int8_t u32char::convertUtf8(char32_t _val, char _output[5]) { return 4; } } - -std::string u32char::convertToUtf8(const std::u32string& _input) { - TK_TODO("implement this function ..."); - return "TODO ... std::string u32char::convertToUtf8(const std::u32string& _input)"; -} - +#if __cplusplus >= 201103L + std::string u32char::convertToUtf8(const std::u32string& _input) { + TK_TODO("implement this function ..."); + return "TODO ... std::string u32char::convertToUtf8(const std::u32string& _input)"; + } +#endif #undef __class__ #define __class__ "utf8" @@ -231,11 +231,12 @@ bool utf8::theoricFirst(const char _input) { } return false; } - -std::u32string utf8::convertUnicode(const std::string& _input) { - TK_TODO("implement this function ..."); - return U"TODO ... std::u32string utf8::convertUnicode(const std::string& _input)"; -} +#if __cplusplus >= 201103L + std::u32string utf8::convertUnicode(const std::string& _input) { + TK_TODO("implement this function ..."); + return U"TODO ... std::u32string utf8::convertUnicode(const std::string& _input)"; + } +#endif utf8::iterator& utf8::iterator::operator++ () { m_value = u32char::Null; @@ -311,22 +312,24 @@ char32_t utf8::iterator::operator* () { #undef __class__ #define __class__ "etk" namespace etk { - template<> std::string to_string(const std::u32string& _input) { - std::string out; - for (size_t iii=0; iii<_input.size(); ++iii) { - char output[10]; - u32char::convertUtf8(_input[iii], output); - out += output; + #if __cplusplus >= 201103L + template<> std::string to_string(const std::u32string& _input) { + std::string out; + for (size_t iii=0; iii<_input.size(); ++iii) { + char output[10]; + u32char::convertUtf8(_input[iii], output); + out += output; + } + return out; } - return out; - } - template<> std::string to_string(const char32_t& _input) { - std::string out; - char output[10]; - u32char::convertUtf8(_input, output); - out += output; - return out; - } + template<> std::string to_string(const char32_t& _input) { + std::string out; + char output[10]; + u32char::convertUtf8(_input, output); + out += output; + return out; + } + #endif template<> std::string to_string(const std::string& _val) { return _val; @@ -415,171 +418,180 @@ namespace etk { } }; -static std::u32string transform_to_u32string(const char* _input) { - if (_input == NULL) { - return U""; - } - std::u32string out; - char tmpData[20]; - int64_t pos = 0; - int64_t inputLen = strlen(_input); - while (pos < inputLen) { - int32_t lenMax = inputLen - pos; - //4 case - if ( 1<=lenMax - && 0x00 == (_input[pos+0] & 0x80) ) { - tmpData[0] = _input[pos+0]; - tmpData[1] = '\0'; - pos += 1; - } else if ( 2<=lenMax - && 0xC0 == (_input[pos+0] & 0xE0) - && 0x80 == (_input[pos+1] & 0xC0) ) { - tmpData[0] = _input[pos+0]; - tmpData[1] = _input[pos+1]; - tmpData[2] = '\0'; - pos += 2; - } else if ( 3<=lenMax - && 0xE0 == (_input[pos+0] & 0xF0) - && 0x80 == (_input[pos+1] & 0xC0) - && 0x80 == (_input[pos+2] & 0xC0)) { - tmpData[0] = _input[pos+0]; - tmpData[1] = _input[pos+1]; - tmpData[2] = _input[pos+2]; - tmpData[3] = '\0'; - pos += 3; - } else if ( 4<=lenMax - && 0xF0 == (_input[pos+0] & 0xF8) - && 0x80 == (_input[pos+1] & 0xC0) - && 0x80 == (_input[pos+2] & 0xC0) - && 0x80 == (_input[pos+3] & 0xC0)) { - tmpData[0] = _input[pos+0]; - tmpData[1] = _input[pos+1]; - tmpData[2] = _input[pos+2]; - tmpData[3] = _input[pos+3]; - tmpData[4] = '\0'; - pos += 4; - } else { - tmpData[0] = '\0'; - pos += 1; +#if __cplusplus >= 201103L + static std::u32string transform_to_u32string(const char* _input) { + if (_input == NULL) { + return U""; } - out += utf8::convertChar32(tmpData); - } - return out; -} - -namespace etk { - template<> std::u32string to_u32string(char* const & _input) { - return transform_to_u32string(_input); - } - template<> std::u32string to_u32string(const std::string& _input) { - return transform_to_u32string(_input.c_str()); - } - template<> std::u32string to_u32string(const int8_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const int16_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const int32_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const int64_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const uint8_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const uint16_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const uint32_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const uint64_t& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const float& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const double& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const long double& _val) { - return etk::to_u32string(etk::to_string(_val)); - }; - template<> std::u32string to_u32string(const bool& _val) { - if (_val == true) { - return U"true"; + std::u32string out; + char tmpData[20]; + int64_t pos = 0; + int64_t inputLen = strlen(_input); + while (pos < inputLen) { + int32_t lenMax = inputLen - pos; + //4 case + if ( 1<=lenMax + && 0x00 == (_input[pos+0] & 0x80) ) { + tmpData[0] = _input[pos+0]; + tmpData[1] = '\0'; + pos += 1; + } else if ( 2<=lenMax + && 0xC0 == (_input[pos+0] & 0xE0) + && 0x80 == (_input[pos+1] & 0xC0) ) { + tmpData[0] = _input[pos+0]; + tmpData[1] = _input[pos+1]; + tmpData[2] = '\0'; + pos += 2; + } else if ( 3<=lenMax + && 0xE0 == (_input[pos+0] & 0xF0) + && 0x80 == (_input[pos+1] & 0xC0) + && 0x80 == (_input[pos+2] & 0xC0)) { + tmpData[0] = _input[pos+0]; + tmpData[1] = _input[pos+1]; + tmpData[2] = _input[pos+2]; + tmpData[3] = '\0'; + pos += 3; + } else if ( 4<=lenMax + && 0xF0 == (_input[pos+0] & 0xF8) + && 0x80 == (_input[pos+1] & 0xC0) + && 0x80 == (_input[pos+2] & 0xC0) + && 0x80 == (_input[pos+3] & 0xC0)) { + tmpData[0] = _input[pos+0]; + tmpData[1] = _input[pos+1]; + tmpData[2] = _input[pos+2]; + tmpData[3] = _input[pos+3]; + tmpData[4] = '\0'; + pos += 4; + } else { + tmpData[0] = '\0'; + pos += 1; + } + out += utf8::convertChar32(tmpData); } - return U"false"; + return out; } -}; - -bool etk::string_to_bool(const std::u32string& _str) { - if( true == compare_no_case(_str, U"true") - || true == compare_no_case(_str, U"enable") - || true == compare_no_case(_str, U"yes") - || _str == U"1") { - return true; +#endif +#if __cplusplus >= 201103L + namespace etk { + template<> std::u32string to_u32string(char* const & _input) { + return transform_to_u32string(_input); + } + template<> std::u32string to_u32string(const std::string& _input) { + return transform_to_u32string(_input.c_str()); + } + template<> std::u32string to_u32string(const int8_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const int16_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const int32_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const int64_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const uint8_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const uint16_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const uint32_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const uint64_t& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const float& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const double& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const long double& _val) { + return etk::to_u32string(etk::to_string(_val)); + }; + template<> std::u32string to_u32string(const bool& _val) { + if (_val == true) { + return U"true"; + } + return U"false"; + } + }; + + bool etk::string_to_bool(const std::u32string& _str) { + if( true == compare_no_case(_str, U"true") + || true == compare_no_case(_str, U"enable") + || true == compare_no_case(_str, U"yes") + || _str == U"1") { + return true; + } + return false; } - return false; -} - -double etk::string_to_double(const std::u32string& _str) { - return std::stod(etk::to_string(_str)); -} -long double etk::string_to_long_double(const std::u32string& _str) { - return std::stold(etk::to_string(_str)); -} -float etk::string_to_float(const std::u32string& _str) { - return std::stof(etk::to_string(_str)); -} -int8_t etk::string_to_int8_t(const std::u32string& _str, int _base) { - return std::stoi(etk::to_string(_str), 0, _base); -} -int16_t etk::string_to_int16_t(const std::u32string& _str, int _base) { - return std::stoi(etk::to_string(_str), 0, _base); -} -int32_t etk::string_to_int32_t(const std::u32string& _str, int _base) { - return std::stoi(etk::to_string(_str), 0, _base); -} -int64_t etk::string_to_int64_t(const std::u32string& _str, int _base) { - return std::stoll(etk::to_string(_str), 0, _base); -} -uint8_t etk::string_to_uint8_t(const std::u32string& _str, int _base) { - return std::stoul(etk::to_string(_str), 0, _base); -} -uint16_t etk::string_to_uint16_t(const std::u32string& _str, int _base) { - return std::stoul(etk::to_string(_str), 0, _base); -} -uint32_t etk::string_to_uint32_t(const std::u32string& _str, int _base) { - return std::stoul(etk::to_string(_str), 0, _base); -} -uint64_t etk::string_to_uint64_t(const std::u32string& _str, int _base) { - return std::stoull(etk::to_string(_str), 0, _base); -} + + double etk::string_to_double(const std::u32string& _str) { + return std::stod(etk::to_string(_str)); + } + long double etk::string_to_long_double(const std::u32string& _str) { + return std::stold(etk::to_string(_str)); + } + float etk::string_to_float(const std::u32string& _str) { + return std::stof(etk::to_string(_str)); + } + int8_t etk::string_to_int8_t(const std::u32string& _str, int _base) { + return std::stoi(etk::to_string(_str), 0, _base); + } + int16_t etk::string_to_int16_t(const std::u32string& _str, int _base) { + return std::stoi(etk::to_string(_str), 0, _base); + } + int32_t etk::string_to_int32_t(const std::u32string& _str, int _base) { + return std::stoi(etk::to_string(_str), 0, _base); + } + int64_t etk::string_to_int64_t(const std::u32string& _str, int _base) { + return std::stoll(etk::to_string(_str), 0, _base); + } + uint8_t etk::string_to_uint8_t(const std::u32string& _str, int _base) { + return std::stoul(etk::to_string(_str), 0, _base); + } + uint16_t etk::string_to_uint16_t(const std::u32string& _str, int _base) { + return std::stoul(etk::to_string(_str), 0, _base); + } + uint32_t etk::string_to_uint32_t(const std::u32string& _str, int _base) { + return std::stoul(etk::to_string(_str), 0, _base); + } + uint64_t etk::string_to_uint64_t(const std::u32string& _str, int _base) { + return std::stoull(etk::to_string(_str), 0, _base); + } +#endif bool etk::string_to_bool(const std::string& _str) { if( true == compare_no_case(_str, "true") || true == compare_no_case(_str, "enable") || true == compare_no_case(_str, "yes") - || _str == u8"1") { + #if __cplusplus >= 201103L + || _str == u8"1" + #else + || _str == "1" + #endif + ) { return true; } return false; } - -bool etk::compare_no_case(const std::u32string& _obj, const std::u32string& _val) { - if (_val.size() != _obj.size()) { - return false; - } - for(size_t iii=0; iii<_val.size(); ++iii) { - if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) { +#if __cplusplus >= 201103L + bool etk::compare_no_case(const std::u32string& _obj, const std::u32string& _val) { + if (_val.size() != _obj.size()) { return false; } + for(size_t iii=0; iii<_val.size(); ++iii) { + if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) { + return false; + } + } + return true; } - return true; -} +#endif bool etk::compare_no_case(const std::string& _obj, const std::string& _val) { if (_val.size() != _obj.size()) { @@ -598,6 +610,7 @@ struct doublette { char32_t upper; }; struct doublette convertionTable[] = { +#if __cplusplus >= 201103L {U'ç', U'Ç'}, {U'á', U'Á'}, {U'à', U'À'}, {U'ä', U'Ä'}, {U'â', U'Â'}, {U'å', U'Å'}, {U'ã', U'Ã'}, @@ -618,6 +631,7 @@ struct doublette convertionTable[] = { {U'æ', U'Æ'}, {U'ð', U'Ð'}, {U'ø', U'Ø'} +#endif }; size_t convertionTableSize = sizeof(convertionTable)/sizeof(struct doublette); @@ -652,12 +666,14 @@ std::string etk::tolower(std::string _obj) { } return _obj; } -std::u32string etk::tolower(std::u32string _obj) { - for(size_t iii=0 ; iii<_obj.size() ; iii++) { - _obj[iii] = localToLower(_obj[iii]); +#if __cplusplus >= 201103L + std::u32string etk::tolower(std::u32string _obj) { + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + _obj[iii] = localToLower(_obj[iii]); + } + return _obj; } - return _obj; -} +#endif std::string etk::toupper(std::string _obj) { for(size_t iii=0 ; iii<_obj.size() ; iii++) { @@ -665,13 +681,14 @@ std::string etk::toupper(std::string _obj) { } return _obj; } - -std::u32string etk::toupper(std::u32string _obj) { - for(size_t iii=0 ; iii<_obj.size() ; iii++) { - _obj[iii] = localToUpper(_obj[iii]); +#if __cplusplus >= 201103L + std::u32string etk::toupper(std::u32string _obj) { + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + _obj[iii] = localToUpper(_obj[iii]); + } + return _obj; } - return _obj; -} +#endif bool etk::end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) { if (_val.size() == 0) { @@ -699,33 +716,34 @@ bool etk::end_with(const std::string& _obj, const std::string& _val, bool _caseS } return true; } - -bool etk::end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { - if (_val.size() == 0) { - return false; - } - if (_val.size() > _obj.size()) { - return false; - } - if (true == _caseSensitive) { +#if __cplusplus >= 201103L + bool etk::end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (_obj[jjj] != _val[iii]) { + return false; + } + } + return true; + } for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; iii>=0 && jjj>=0; iii--, jjj--) { - if (_obj[jjj] != _val[iii]) { + if (std::tolower(_val[iii]) != std::tolower(_obj[jjj])) { return false; } } return true; } - for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; - iii>=0 && jjj>=0; - iii--, jjj--) { - if (std::tolower(_val[iii]) != std::tolower(_obj[jjj])) { - return false; - } - } - return true; -} +#endif bool etk::start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) { if (_val.size() == 0) { @@ -753,45 +771,46 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas } return true; } - -bool etk::start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { - if (_val.size() == 0) { - return false; - } - if (_val.size() > _obj.size()) { - return false; - } - if (true == _caseSensitive) { +#if __cplusplus >= 201103L + bool etk::start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( size_t iii = 0; + iii < _val.size(); + iii++) { + if (_obj[iii] != _val[iii]) { + return false; + } + } + return true; + } for( size_t iii = 0; iii < _val.size(); iii++) { - if (_obj[iii] != _val[iii]) { + if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) { return false; } } return true; } - for( size_t iii = 0; - iii < _val.size(); - iii++) { - if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) { - return false; + + std::u32string etk::replace(const std::u32string& _obj, char32_t _val, char32_t _replace) { + std::u32string copy(_obj); + for( size_t iii = 0; + iii < copy.size(); + iii++) { + if (copy[iii] == _val) { + copy[iii] = _replace; + } } + return copy; } - return true; -} - -std::u32string etk::replace(const std::u32string& _obj, char32_t _val, char32_t _replace) { - std::u32string copy(_obj); - for( size_t iii = 0; - iii < copy.size(); - iii++) { - if (copy[iii] == _val) { - copy[iii] = _replace; - } - } - return copy; -} +#endif std::string etk::replace(const std::string& _obj, char _val, char _replace) { std::string copy(_obj); @@ -833,35 +852,36 @@ std::string etk::extract_line(const std::string& _obj, int32_t _pos) { } return std::string(_obj, startPos, stopPos - startPos); } - -std::u32string etk::extract_line(const std::u32string& _obj, int32_t _pos) { - // search back : '\n' - size_t startPos = _obj.rfind('\n', _pos); - if ((int64_t)startPos == _pos) { - startPos = 0; - } else { - startPos++; - } - // search forward : '\n' - size_t stopPos = _pos; - if (_obj[_pos] != '\n') { - stopPos = _obj.find('\n', _pos); - if ((int64_t)stopPos == _pos) { +#if __cplusplus >= 201103L + std::u32string etk::extract_line(const std::u32string& _obj, int32_t _pos) { + // search back : '\n' + size_t startPos = _obj.rfind('\n', _pos); + if ((int64_t)startPos == _pos) { + startPos = 0; + } else { + startPos++; + } + // search forward : '\n' + size_t stopPos = _pos; + if (_obj[_pos] != '\n') { + stopPos = _obj.find('\n', _pos); + if ((int64_t)stopPos == _pos) { + stopPos = _obj.size(); + } + } + if (startPos == std::string::npos) { + startPos = 0; + } else if (startPos >= _obj.size() ) { + return U""; + } + if (stopPos == std::string::npos) { + return U""; + } else if (stopPos >= _obj.size() ) { stopPos = _obj.size(); } + return std::u32string(_obj, startPos, stopPos - startPos); } - if (startPos == std::string::npos) { - startPos = 0; - } else if (startPos >= _obj.size() ) { - return U""; - } - if (stopPos == std::string::npos) { - return U""; - } else if (stopPos >= _obj.size() ) { - stopPos = _obj.size(); - } - return std::u32string(_obj, startPos, stopPos - startPos); -} +#endif std::vector etk::split(const std::string& _input, char _val) { std::vector list; @@ -878,20 +898,22 @@ std::vector etk::split(const std::string& _input, char _val) { return list; } -std::vector etk::split(const std::u32string& _input, char32_t _val) { - std::vector list; - size_t lastStartPos = 0; - for(size_t iii=0; iii<_input.size(); iii++) { - if (_input[iii]==_val) { - list.push_back(std::u32string(_input, lastStartPos, iii - lastStartPos)); - lastStartPos = iii+1; +#if __cplusplus >= 201103L + std::vector etk::split(const std::u32string& _input, char32_t _val) { + std::vector list; + size_t lastStartPos = 0; + for(size_t iii=0; iii<_input.size(); iii++) { + if (_input[iii]==_val) { + list.push_back(std::u32string(_input, lastStartPos, iii - lastStartPos)); + lastStartPos = iii+1; + } } + if (lastStartPos<_input.size()) { + list.push_back(std::u32string(_input, lastStartPos)); + } + return list; } - if (lastStartPos<_input.size()) { - list.push_back(std::u32string(_input, lastStartPos)); - } - return list; -} +#endif long double etk::string_to_long_double(const std::string& _str) { long double ret = 0; @@ -981,27 +1003,31 @@ void etk::sort(std::vector &_list) { _list.insert(_list.begin()+findPos, tmpList[iii]); } } - -void etk::sort(std::vector &_list) { - std::vector tmpList(_list); - _list.clear(); - for(size_t iii=0; iii *_list[jjj]) { - findPos = jjj+1; +#if __cplusplus >= 201103L + void etk::sort(std::vector &_list) { + std::vector tmpList(_list); + _list.clear(); + for(size_t iii=0; iii *_list[jjj]) { + findPos = jjj+1; + } } + //EWOL_DEBUG("position="<& _obj) { - _os << "{"; - for (size_t iii=0; iii< _obj.size(); iii++) { - if (iii>0) { - _os << " ~ "; - } - _os << _obj[iii]; +#if __cplusplus >= 201103L + std::ostream& std::operator <<(std::ostream& _os, const std::u32string& _obj) { + _os << etk::to_string(_obj).c_str(); + return _os; } - _os << "}"; - return _os; -} + + std::ostream& std::operator <<(std::ostream& _os, const std::vector& _obj) { + _os << "{"; + for (size_t iii=0; iii< _obj.size(); iii++) { + if (iii>0) { + _os << " ~ "; + } + _os << _obj[iii]; + } + _os << "}"; + return _os; + } +#endif std::ostream& std::operator <<(std::ostream& _os, const std::vector& _obj) { _os << "{"; diff --git a/etk/stdTools.h b/etk/stdTools.h index 271c41b..07fb40d 100644 --- a/etk/stdTools.h +++ b/etk/stdTools.h @@ -41,7 +41,9 @@ namespace u32char { char32_t changeOrder(char32_t _val); int8_t convertUtf8(char32_t _val, char _output[5]); - std::string convertToUtf8(const std::u32string& _input); + #if __cplusplus >= 201103L + std::string convertToUtf8(const std::u32string& _input); + #endif }; namespace utf8 { @@ -59,8 +61,9 @@ namespace utf8 { bool theoricFirst(const char _input); char32_t convertChar32(const char* _input); - std::u32string convertUnicode(const std::string& _input); - + #if __cplusplus >= 201103L + std::u32string convertUnicode(const std::string& _input); + #endif class iterator { private: char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data @@ -384,88 +387,134 @@ namespace std { namespace etk { // these declaration is to prevent some under template declaration of unknown type template std::string to_string(const TYPE& _variable); - template std::u32string to_u32string(const TYPE& _variable); - + #if __cplusplus >= 201103L + template std::u32string to_u32string(const TYPE& _variable); + #endif // these declaration is to prevent some under template declaration of unknown type template bool from_string(TYPE& _variableRet, const std::string& _value); - template bool from_string(TYPE& _variableRet, const std::u32string& _value); + #if __cplusplus >= 201103L + template bool from_string(TYPE& _variableRet, const std::u32string& _value); + #endif // TODO : Change this in : // TODO : template TYPE string_to(const std::u32string& _value); ==> check exceptions ... long double string_to_long_double(const std::string& _str); - long double string_to_long_double(const std::u32string& _str); + #if __cplusplus >= 201103L + long double string_to_long_double(const std::u32string& _str); + #endif double string_to_double(const std::string& _str); - double string_to_double(const std::u32string& _str); + #if __cplusplus >= 201103L + double string_to_double(const std::u32string& _str); + #endif float string_to_float(const std::string& _str); - float string_to_float(const std::u32string& _str); + #if __cplusplus >= 201103L + float string_to_float(const std::u32string& _str); + #endif int8_t string_to_int8_t(const std::string& _str, int _base = 10); - int8_t string_to_int8_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + int8_t string_to_int8_t(const std::u32string& _str, int _base = 10); + #endif int16_t string_to_int16_t(const std::string& _str, int _base = 10); - int16_t string_to_int16_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + int16_t string_to_int16_t(const std::u32string& _str, int _base = 10); + #endif int32_t string_to_int32_t(const std::string& _str, int _base = 10); - int32_t string_to_int32_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + int32_t string_to_int32_t(const std::u32string& _str, int _base = 10); + #endif int64_t string_to_int64_t(const std::string& _str, int _base = 10); - int64_t string_to_int64_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + int64_t string_to_int64_t(const std::u32string& _str, int _base = 10); + #endif uint8_t string_to_uint8_t(const std::string& _str, int _base = 10); - uint8_t string_to_uint8_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + uint8_t string_to_uint8_t(const std::u32string& _str, int _base = 10); + #endif uint16_t string_to_uint16_t(const std::string& _str, int _base = 10); - uint16_t string_to_uint16_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + uint16_t string_to_uint16_t(const std::u32string& _str, int _base = 10); + #endif uint32_t string_to_uint32_t(const std::string& _str, int _base = 10); - uint32_t string_to_uint32_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + uint32_t string_to_uint32_t(const std::u32string& _str, int _base = 10); + #endif uint64_t string_to_uint64_t(const std::string& _str, int _base = 10); - uint64_t string_to_uint64_t(const std::u32string& _str, int _base = 10); + #if __cplusplus >= 201103L + uint64_t string_to_uint64_t(const std::u32string& _str, int _base = 10); + #endif bool string_to_bool(const std::string& _str); - bool string_to_bool(const std::u32string& _str); + #if __cplusplus >= 201103L + bool string_to_bool(const std::u32string& _str); + #endif std::string tolower(std::string _obj); - //! @previous - std::u32string tolower(std::u32string _obj); + #if __cplusplus >= 201103L + //! @previous + std::u32string tolower(std::u32string _obj); + #endif + std::string toupper(std::string _obj); - //! @previous - std::u32string toupper(std::u32string _obj); + #if __cplusplus >= 201103L + //! @previous + std::u32string toupper(std::u32string _obj); + #endif bool compare_no_case(const std::string& _obj, const std::string& _val); - //! @previous - bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); + #if __cplusplus >= 201103L + //! @previous + bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); + #endif bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true); - //! @previous - bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); + #if __cplusplus >= 201103L + //! @previous + bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); + #endif bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true); - //! @previous - bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); + #if __cplusplus >= 201103L + //! @previous + bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); + #endif std::string replace(const std::string& _obj, char _val, char _replace); - //! @previous - std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace); + #if __cplusplus >= 201103L + //! @previous + std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace); + #endif std::string extract_line(const std::string& _obj, int32_t _pos); - //! @previous - std::u32string extract_line(const std::u32string& _obj, int32_t _pos); + #if __cplusplus >= 201103L + //! @previous + std::u32string extract_line(const std::u32string& _obj, int32_t _pos); + #endif std::vector split(const std::string& _input, char _val); - //! @previous - std::vector split(const std::u32string& _input, char32_t _val); + #if __cplusplus >= 201103L + //! @previous + std::vector split(const std::u32string& _input, char32_t _val); + #endif - void sort(std::vector& _list); - //! @previous void sort(std::vector& _list); + #if __cplusplus >= 201103L + //! @previous + void sort(std::vector& _list); + #endif template bool isIn(const T& _val, const std::vector& _list) { - for (auto &it : _list) { - if (it == _val) { + for (size_t iii=0; iii<_list.size(); ++iii) { + if (_list[iii] == _val) { return true; } } @@ -482,8 +531,10 @@ namespace std { namespace std { std::ostream& operator <<(std::ostream& _os, const std::string& _obj); std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); - std::ostream& operator <<(std::ostream& _os, const std::u32string& _obj); - std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); + #if __cplusplus >= 201103L + std::ostream& operator <<(std::ostream& _os, const std::u32string& _obj); + std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); + #endif std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); std::ostream& operator <<(std::ostream& _os, const std::vector& _obj); diff --git a/etk/types.h b/etk/types.h index c98c68a..235c1ef 100644 --- a/etk/types.h +++ b/etk/types.h @@ -41,8 +41,15 @@ #endif #endif -#ifdef ETK_ENABLE_NULLPTR +#if __cplusplus <= 201103L #define nullptr NULL + typedef uint32_t char32_t; + namespace boost { + // just define + } + namespace std11 = boost; +#else + namespace std11 = std; #endif diff --git a/lutin_etk.py b/lutin_etk.py index de054c5..4243af1 100644 --- a/lutin_etk.py +++ b/lutin_etk.py @@ -30,10 +30,17 @@ def create(target): if target.name=="IOs": myModule.add_src_file('etk/logIOs.m') - - # name of the dependency - myModule.add_optionnal_module_depend('linearmath', "ETK_BUILD_LINEARMATH", export=True) - myModule.add_optionnal_module_depend('minizip', "ETK_BUILD_MINIZIP") + + # force old version of C++ + target.xx_version = 4005000 + + if target.config["compilator"] == "gcc" \ + and target.xx_version < 4007000: + pass + else: + # name of the dependency + myModule.add_optionnal_module_depend('linearmath', "ETK_BUILD_LINEARMATH", export=True) + myModule.add_optionnal_module_depend('minizip', "ETK_BUILD_MINIZIP") if target.config["mode"] == "release": # TODO : The other way is to remove this ... @@ -48,8 +55,8 @@ def create(target): if target.config["compilator"] == "gcc" \ and target.xx_version < 4007000: - myModule.add_export_flag_CC("-DETK_ENABLE_NULLPTR") - + myModule.add_optionnal_module_depend('boost', "ETK_BUILD_BOOST", export=True) + myModule.add_export_path(tools.get_current_path(__file__) + "/etk/boost_to_std") if target.name=="Windows": None