[DEV] continue removing stl

This commit is contained in:
Edouard DUPIN 2017-08-28 00:02:11 +02:00
parent 40a9aaba66
commit 1d99aa0112
54 changed files with 1536 additions and 1033 deletions

View File

@ -93,7 +93,7 @@ namespace etk {
* @return true if the data correctly stored
* @return false if an error occurred
*/
bool dumpIn(const std::string& _file) {
bool dumpIn(const etk::String& _file) {
etk::FSNode file(_file);
if (false == file.fileOpenWrite()) {
return false;
@ -111,7 +111,7 @@ namespace etk {
* @return true if the data correctly stored
* @return false if an error occurred
*/
bool dumpFrom(const std::string& _file) {
bool dumpFrom(const etk::String& _file) {
etk::FSNode file(_file);
if (false == file.fileOpenRead()) {
return false;
@ -195,27 +195,27 @@ namespace etk {
* @param[in] _nbElement Number of element needed.
* @return The data requested
*/
std::vector<int8_t> get(int32_t _pos, int32_t _nbElement) {
std::vector<int8_t> tmpBuffer;
etk::Vector<int8_t> get(int32_t _pos, int32_t _nbElement) {
etk::Vector<int8_t> 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]);
tmpBuffer.pushBack(m_data[iii]);
}
} else {
for (int32_t iii = _pos; iii<m_gapStart; ++iii) {
tmpBuffer.push_back(m_data[iii]);
tmpBuffer.pushBack(m_data[iii]);
}
for (int32_t iii = m_gapEnd; iii<m_gapEnd - (_nbElement - (m_gapStart - _pos)); ++iii) {
tmpBuffer.push_back(m_data[iii]);
tmpBuffer.pushBack(m_data[iii]);
}
}
} else {
for (int32_t iii = _pos+(m_gapEnd-m_gapStart);
iii<_pos+(m_gapEnd-m_gapStart)+_nbElement;
++iii) {
tmpBuffer.push_back(m_data[iii]);
tmpBuffer.pushBack(m_data[iii]);
}
}
return tmpBuffer;
@ -224,7 +224,7 @@ namespace etk {
* @brief Add at the Last position of the Buffer.
* @param[in] _item Element to add.
*/
void push_back(const int8_t& _item) {
void pushBack(const int8_t& _item) {
insert(size(), _item);
}
/**
@ -264,7 +264,7 @@ namespace etk {
* @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<int8_t>& _items) {
void insert(int32_t _pos, const etk::Vector<int8_t>& _items) {
insert(_pos, &_items[0], _items.size());
}
/**
@ -317,7 +317,7 @@ namespace etk {
* @param[in] _nbRemoveElement number of element to remove.
* @param[in] _items Data that will be inserted.
*/
void replace(int32_t _pos, int32_t _nbRemoveElement, const std::vector<int8_t>& _items) {
void replace(int32_t _pos, int32_t _nbRemoveElement, const etk::Vector<int8_t>& _items) {
replace(_pos, _nbRemoveElement, &_items[0], _items.size());
}
/**
@ -380,7 +380,7 @@ namespace etk {
/**
* @brief Remove the last element of the Buffer.
*/
void pop_back() {
void popBack() {
if (size() > 0) {
remove( size() );
}

View File

@ -79,23 +79,23 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const etk::String& _input
int32_t red=0, green=0, blue=0, alpha=0;
float float_red=0, float_green=0, float_blue=0, float_alpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
float_red = etk::avg(0.0f, float_red, 1.0f);
float_green = etk::avg(0.0f, float_green, 1.0f);
@ -133,23 +133,23 @@ etk::Color<double, 4> etk::parseStringStartWithRGB(const etk::String& _input) {
outputValue.setG(float_green);
outputValue.setB(float_blue);
} else if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setA(etk::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setA(etk::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
}
@ -178,14 +178,14 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const etk::String
outputValue.setG(green);
outputValue.setB(blue);
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint32_t)(std::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, float_blue)*0xFFFFFFFF));
outputValue.setA((uint32_t)(std::min(1.0, float_alpha)*0xFFFFFFFF));
outputValue.setR((uint32_t)(etk::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(etk::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(etk::min(1.0, float_blue)*0xFFFFFFFF));
outputValue.setA((uint32_t)(etk::min(1.0, float_alpha)*0xFFFFFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint32_t)(std::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, float_blue)*0xFFFFFFFF));
outputValue.setR((uint32_t)(etk::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(etk::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(etk::min(1.0, float_blue)*0xFFFFFFFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
}
@ -197,32 +197,32 @@ etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const etk::String
int32_t red=0, green=0, blue=0, alpha=0;
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setA(std::min(0xFFFF, alpha));
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
outputValue.setA(etk::min(0xFFFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setA(std::min(0xFFFF, alpha));
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
outputValue.setA(etk::min(0xFFFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint16_t)(std::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, float_blue)*0xFFFF));
outputValue.setA((uint16_t)(std::min(1.0, float_alpha)*0xFFFF));
outputValue.setR((uint16_t)(etk::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(etk::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(etk::min(1.0, float_blue)*0xFFFF));
outputValue.setA((uint16_t)(etk::min(1.0, float_alpha)*0xFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint16_t)(std::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, float_blue)*0xFFFF));
outputValue.setR((uint16_t)(etk::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(etk::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(etk::min(1.0, float_blue)*0xFFFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
}
@ -234,32 +234,32 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const etk::String&
int32_t red=0, green=0, blue=0, alpha=0;
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint8_t)(std::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, float_blue)*0xFF));
outputValue.setA((uint8_t)(std::min(1.0, float_alpha)*0xFF));
outputValue.setR((uint8_t)(etk::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(etk::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(etk::min(1.0, float_blue)*0xFF));
outputValue.setA((uint8_t)(etk::min(1.0, float_alpha)*0xFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint8_t)(std::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, float_blue)*0xFF));
outputValue.setR((uint8_t)(etk::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(etk::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(etk::min(1.0, float_blue)*0xFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
}

View File

@ -214,18 +214,34 @@ namespace etk {
* @return The formatted string
*/
etk::String getHexString() const {
std::ostringstream os;
os << "0x" << std::setw(8) << std::setfill('0') << std::hex << get();
return os.str();
etk::String out = "0x";
uint32_t value = get();
for (size_t iii=0; iii<8; ++iii) {
uint32_t tmp = (value >> (4*(7-iii))) & 0x0F;
if (tmp < 10) {
out += ('0'+tmp);
} else {
out += ('A'+tmp);
}
}
return out;
};
/**
* @brief Convert the color in an generic string value ("#FEDCBA98")
* @return The formatted string
*/
etk::String getString() const {
std::ostringstream os;
os << "#" << std::setw(8) << std::setfill('0') << std::hex << get();
return os.str();
etk::String out = "#";
uint32_t value = get();
for (size_t iii=0; iii<8; ++iii) {
uint32_t tmp = (value >> (4*(7-iii))) & 0x0F;
if (tmp < 10) {
out += ('0'+tmp);
} else {
out += ('A'+tmp);
}
}
return out;
};
/**
* @brief Get red color.
@ -507,7 +523,9 @@ namespace etk {
//! @not_in_doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint8_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
template<int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const Color<uint8_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
// TODO: set it back !!!!
/*
std::ostringstream os;
if (MY_TYPE_SIZE >= 3) {
_os << "#";
@ -536,12 +554,11 @@ namespace etk {
}
_os << os.str();
_os << ")";
}
}*/
return _os;
}
//! @not_in_doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint16_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
std::ostringstream os;
template<int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const Color<uint16_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
@ -552,6 +569,8 @@ namespace etk {
_os << "Mono";
}
_os << "[U16](";
// TODO: set it back !!!!
/*
os << "0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.g();
@ -563,11 +582,12 @@ namespace etk {
os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.a();
}
_os << os.str() << ")";
*/
return _os;
}
//! @not_in_doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint32_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
std::ostringstream os;
template<int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const Color<uint32_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
//std::ostringstream os;
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
@ -578,6 +598,8 @@ namespace etk {
_os << "Mono";
}
_os << "[U32](";
// TODO: set it back !!!!
/*
os << "0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.g();
@ -589,10 +611,11 @@ namespace etk {
os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.a();
}
_os << os.str() << ")";
*/
return _os;
}
//! @not_in_doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<float, MY_TYPE_SIZE>& _obj) { // RGB float & RGBA float
template<int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const Color<float, MY_TYPE_SIZE>& _obj) { // RGB float & RGBA float
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
@ -620,7 +643,7 @@ namespace etk {
return _os;
}
//! @not_in_doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<double, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
template<int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const Color<double, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
@ -648,7 +671,7 @@ namespace etk {
return _os;
}
//! @not_in_doc
template<typename MY_TYPE, int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const std::vector<Color<MY_TYPE, MY_TYPE_SIZE> >& _obj) {
template<typename MY_TYPE, int MY_TYPE_SIZE> etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<Color<MY_TYPE, MY_TYPE_SIZE> >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";

View File

@ -39,7 +39,7 @@ namespace etk {
*
* @note The name is unique and the value is what you want
*
* @todo check if something else exist in the generic library. (not the std::map and the std::unordered_map
* @todo check if something else exist in the generic library. (not the etk::Map and the std::unordered_map
*
* @note The index are all time available since they are created. The order is the the one created
*

View File

@ -57,7 +57,7 @@ namespace etk {
void pushBack(ETK_LIST_TYPE _element);
void pop_back();
void popBack();
void push_front(ETK_LIST_TYPE _element);
void pop_front();

View File

@ -0,0 +1,498 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#pragma once
#include <etk/String.hpp>
namespace etk {
/**
* @brief Map table template is a simple classical Map interface.
* A Map table is a equivalent of the dictionary in python, this is a
* simple interface between a name and a value:
* - "name" : 19
* - "name 2" : 99
*
* @note The name is unique and the value is what you want
*
* @todo check if something else exist in the generic library. (not the etk::Map and the std::unordered_map
*
* @note The index are all time available since they are created. The order is the the one created
*
* A simple example of use:
* @code{.cpp}
* // Create a integer Map table
* Map<int> myValue;
* // add some element (note add and set is the same function)
* myValue.add("example", 98837);
* myValue.add("plop", 88);
* // Display an element:
* printf("my value is : %d", myValue["example"]);
* // Change value of an element:
* myValue.set("example", 99);
* // Remove an element:
* myValue.remove("plop");
* //Clean all the table:
* myValue.clear();
* @endcode
*/
template<class ETK_MAP_TYPE_KEY, class ETK_MAP_TYPE_DATA> class Map {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the vector
Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* m_map; //!< Pointer on the current element of the vectorBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::Vector
*/
Iterator():
m_current(0),
m_map(nullptr) {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etkVector.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_map(_obj.m_map) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_map = _obj.m_map;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_map = nullptr;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etkVector size
*/
operator bool () {
return (m_current < m_map->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_map != nullptr
&& m_current < m_map->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_map != nullptr
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int64_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int64_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int64_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int64_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
ETK_MAP_TYPE_DATA& operator-> () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return &m_map->get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
ETK_MAP_TYPE_DATA& operator* () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->get(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
const ETK_MAP_TYPE_KEY& getKey () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getKey(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
const ETK_MAP_TYPE_DATA& getValue () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getValue(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
ETK_MAP_TYPE_DATA& getValue () {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getValue(m_current);
}
private:
Iterator(const etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA> * _obj, int32_t _pos):
m_current(_pos),
m_map(const_cast<etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA> *>(_obj)) {
// nothing to do ...
}
friend class Map;
};
private:
etk::Vector<etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>*> m_data; //!< Data of the Map ==> the Map table is composed of pointer, this permit to have high speed when resize the vector ...
public:
/**
* @brief Constructor of the Map table.
* @param[in] _count Number of basic element in the table.
*/
Map(int32_t _count = 0) :
m_data(_count) {
// nothing to do
}
/**
* @brief Destructor of the Map table (clear all element in the table)
*/
~Map() {
clear();
}
/**
* @brief Remove all entry in the Map table.
* @note It does not delete pointer if your value is a pointer type...
*/
void clear() {
for (auto &it : m_data) {
if (it != nullptr) {
delete(it);
it=nullptr;
}
}
m_data.clear();
}
/**
* @brief Get a current element ID in the Map table
* @param[in] _key Name of the Map requested
* @return Id of the element in the table or -1 of it does not existed
*/
int64_t getId(const ETK_MAP_TYPE_KEY& _key) const {
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != nullptr) {
//TK_INFO("Compare key : '" << m_data[iii]->m_key << "' with '" << _key << "'" );
if (m_data[iii]->first == _key) {
return iii;
}
}
}
//TK_ERROR(" ==> not fund key '" << _key << "'" );
return -1;
}
/**
* @brief Check if an element exist or not
* @param[in] _name Name of the Map requested
* @return true if the element exist
*/
bool exist(const ETK_MAP_TYPE_KEY& _name) const {
int64_t elementId = getId(_name);
//TK_INFO(" Exist ? '" << _name << "' id=" << elementId );
if (elementId<0) {
//TK_INFO(" ==> return false" );
return false;
}
//TK_INFO(" ==> return true" );
return true;
}
/**
* @brief Get a current element in the Map table, with his name.
* @param[in] _key Name of the Map requested
* @return Reference on the Element
*/
ETK_MAP_TYPE_DATA& get(const ETK_MAP_TYPE_KEY& _key) const {
static ETK_MAP_TYPE_DATA g_error;
int64_t elementId = getId(_key);
if (elementId<0) {
//TK_ERROR("try to access at an inexistent Map element : " << _key);
return g_error;
}
return m_data[elementId]->m_value;
}
/**
* @brief Get an copy Element an a special position
* @param[in] _key Name of the Map requested
* @return An reference on the copy of selected element
*/
ETK_MAP_TYPE_DATA& operator[] (const ETK_MAP_TYPE_KEY& _key) {
return get(_key);
}
/**
* @brief Get an copy Element an a special position
* @param[in] _key Name of the Map requested
* @return An reference on the copy of selected element
*/
const ETK_MAP_TYPE_DATA& operator[] (const ETK_MAP_TYPE_KEY& _key) const {
return get(_key);
}
/**
* @brief Add an element OR set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Map table.
* @param[in] _value Value to set in the Map table.
*/
void add(const ETK_MAP_TYPE_KEY& _key, const ETK_MAP_TYPE_DATA& _value) {
int64_t elementId = getId(_key);
if (elementId <0) {
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* tmp = new etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>(etk::move(_key), etk::move(_value));
if (tmp == nullptr) {
//TK_ERROR("allocation error in Map table : '" << _key << "'");
return;
}
m_data.pushBack(tmp);
return;
}
m_data[elementId]->second = _value;
}
/**
* @brief Set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Map table.
* @param[in] _value Value to set in the Map table.
*/
void set(const ETK_MAP_TYPE_KEY& _key, const ETK_MAP_TYPE_DATA& _value) {
add(etk::move(_key), etk::move(_value));
}
/**
* @brief Remove an element in the Map table.
* @param[in] _key Name of the element to remove.
*/
void remove(const ETK_MAP_TYPE_KEY& _key) {
int64_t elementId = getId(_key);
if (elementId <0) {
//nothing to do ==> not existed
return;
}
delete(m_data[elementId]);
m_data[elementId] = nullptr;
m_data.erase(m_data.begin()+elementId);
}
/**
* @brief Get the number of element in the Map table
* @return number of elements
*/
size_t size() const {
return m_data.size();
}
/**
* @brief get an element with his id.
* @param[in] _pos Position on the element in the Map table.
* @return requested element at this position.
* @note this is a dangerous use of the Map table. Maybe you will use a simple vector.
*/
ETK_MAP_TYPE_DATA& operator[] (size_t _pos) {
return getValue(_pos);
}
/**
* @brief get an element with his id.
* @param[in] _pos Position on the element in the Map table.
* @return requested element at this position.
* @note this is a dangerous use of the Map table. Maybe you will use a simple vector.
*/
const ETK_MAP_TYPE_DATA& operator[] (size_t _pos) const {
return getValue(_pos);
}
/**
* @brief Get the name of the element at a specific position.
* @param[in] _pos Position of the element in the Map table.
* @return name of the element (key).
*/
const ETK_MAP_TYPE_KEY& getKey(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->m_key;
}
/**
* @brief Get all the element name (keys).
* @return a vector of all name (key).
*/
etk::Vector<ETK_MAP_TYPE_KEY> getKeys() const {
etk::Vector<ETK_MAP_TYPE_KEY> keys;
for (auto &it : m_data) {
if (it != nullptr) {
keys.pushBack(it->m_key);
}
}
return etk::move(keys);
}
/**
* @brief Get a value of the Map table at a specific position.
* @param[in] _pos of the element in the Map table.
* @return Value available at this position.
*/
const ETK_MAP_TYPE_DATA& getValue(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->second;
}
/**
* @copydoc getValue (size_t)
*/
ETK_MAP_TYPE_DATA& getValue(size_t _pos) {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->second;
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the vector
* @return The Iterator
*/
Iterator position(size_t _pos) {
return Iterator(this, _pos);
}
const Iterator position(size_t _pos) const {
return Iterator(this, _pos);
}
/**
* @brief Get an Iterator on the start position of the Vector
* @return The Iterator
*/
Iterator begin() {
return position(0);
}
const Iterator begin() const {
return position(0);
}
/**
* @brief Get an Iterator on the end position of the Vector
* @return The Iterator
*/
Iterator end() {
return position(size()-1);
}
const Iterator end() const {
return position(size()-1);
}
Iterator find(const ETK_MAP_TYPE_KEY& _key) {
int64_t elementId = getId(_key);
if (elementId <0) {
return end();
}
position(elementId);
}
const Iterator find(const ETK_MAP_TYPE_KEY& _key) const {
int64_t elementId = getId(_key);
if (elementId <0) {
return end();
}
position(elementId);
}
};
}

View File

@ -18,7 +18,7 @@ namespace etk {
*/
class BaseNoise {
private:
std::vector<float> m_data; //!< basic interface date
etk::Vector<float> m_data; //!< basic interface date
ivec2 m_size; //!< Size of the noise data
public:
/**
@ -56,7 +56,7 @@ namespace etk {
*/
class Noise {
private:
std::vector<float> m_data; //!< Internal data generated
etk::Vector<float> m_data; //!< Internal data generated
ivec2 m_size; //!< Size of the noise
enum noiseType m_type; //!< Type of the noise
/**

38
etk/Pair.hpp Normal file
View File

@ -0,0 +1,38 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
namespace etk {
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
class Pair {
public:
ETK_PAIR_TYPE_1 first;
ETK_PAIR_TYPE_1 second;
Pair():
first(),
second() {
}
Pair(const ETK_PAIR_TYPE_1& _obj1, const ETK_PAIR_TYPE_2& _obj2):
first(_obj1),
second(_obj2) {
}
template<class ETK_PAIR_UNDER_TYPE_1, class ETK_PAIR_UNDER_TYPE_2>
Pair(const Pair<ETK_PAIR_UNDER_TYPE_1, ETK_PAIR_UNDER_TYPE_2>& _pair):
first(_pair.first),
second(_pair.second) {
}
};
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2> makePair(ETK_PAIR_TYPE_1 _obj1, ETK_PAIR_TYPE_2 _obj2) {
return etk::Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(_obj1, _obj2);
}
};

View File

@ -70,16 +70,16 @@ static const char* parseStatusTable[] = {
"parseStatusPartial",
"parseStatusFull"
};
std::ostream& etk::regex::operator <<(std::ostream& _os, enum etk::regex::parseStatus _obj) {
etk::Stream& etk::regex::operator <<(etk::Stream& _os, enum etk::regex::parseStatus _obj) {
_os << parseStatusTable[_obj];
return _os;
}
std::ostream& etk::regex::operator <<(std::ostream& _os, const etk::regex::FindProperty& _obj) {
etk::Stream& etk::regex::operator <<(etk::Stream& _os, const etk::regex::FindProperty& _obj) {
_os << "property([" << _obj.getPositionStart() << "," << _obj.getPositionStop() << "]*" << _obj.getMultiplicity() << " " << _obj.getStatus() << ")";
return _os;
}
etk::String etk::regex::createString(const std::vector<char32_t>& _data, int64_t _start, int64_t _stop) {
etk::String etk::regex::createString(const etk::Vector<char32_t>& _data, int64_t _start, int64_t _stop) {
etk::String output(ETK_BASH_COLOR_NORMAL);
for (int64_t iii=_start; iii<(int64_t)_data.size() && iii<_stop ; iii++) {
switch(_data[iii]) {
@ -129,7 +129,7 @@ char* etk::regex::levelSpace(uint32_t _level) {
}
int64_t etk::regex::getLenOfPTheseElement(const std::vector<char32_t>& _data, int64_t _startPos) {
int64_t etk::regex::getLenOfPTheseElement(const etk::Vector<char32_t>& _data, int64_t _startPos) {
if (_startPos>=(int64_t)_data.size()){
return 0;
}
@ -169,7 +169,7 @@ int64_t etk::regex::getLenOfPTheseElement(const std::vector<char32_t>& _data, in
return pos - _startPos;
}
int64_t etk::regex::getLenOfPThese(const std::vector<char32_t>& _data, int64_t _startPos) {
int64_t etk::regex::getLenOfPThese(const etk::Vector<char32_t>& _data, int64_t _startPos) {
int64_t pos = _startPos;
int32_t nbOpen = 0;
// special case of the (...) or | ==> we search '|' or ')'
@ -210,7 +210,7 @@ int64_t etk::regex::getLenOfPThese(const std::vector<char32_t>& _data, int64_t _
}
int64_t etk::regex::getLenOfBracket(const std::vector<char32_t>& _data, int64_t _startPos) {
int64_t etk::regex::getLenOfBracket(const etk::Vector<char32_t>& _data, int64_t _startPos) {
int64_t pos = _startPos;
// special case of the (...) or | ==> we search '|' or ')'
if(_data[pos]==regexOpcodeBracketOut) {
@ -263,7 +263,7 @@ int64_t etk::regex::getLenOfBracket(const std::vector<char32_t>& _data, int64_t
}
int64_t etk::regex::getLenOfBrace(const std::vector<char32_t>& _data, int64_t _startPos) {
int64_t etk::regex::getLenOfBrace(const etk::Vector<char32_t>& _data, int64_t _startPos) {
int32_t pos = _startPos;
// special case of the (...) or | ==> we search '|' or ')'
if(_data[pos]==regexOpcodeBraceOut) {
@ -297,7 +297,7 @@ int64_t etk::regex::getLenOfBrace(const std::vector<char32_t>& _data, int64_t _s
}
int64_t etk::regex::getLenOfNormal(const std::vector<char32_t>& _data, int64_t _startPos) {
int64_t etk::regex::getLenOfNormal(const etk::Vector<char32_t>& _data, int64_t _startPos) {
int64_t pos = _startPos;
// find size ...
while (pos < (int64_t)_data.size() ) {
@ -346,7 +346,7 @@ int64_t etk::regex::getLenOfNormal(const std::vector<char32_t>& _data, int64_t _
}
bool etk::regex::parseBrace(const std::vector<char32_t>& _data, uint32_t& _min, uint32_t& _max) {
bool etk::regex::parseBrace(const etk::Vector<char32_t>& _data, uint32_t& _min, uint32_t& _max) {
int64_t k=0;
int32_t firstElement = 0;
int32_t SecondElement = 0;

View File

@ -147,27 +147,27 @@ enum parseStatus {
parseStatusFull //!< can not parse more elements
};
//! @not-in-doc
std::ostream& operator <<(std::ostream& _os, enum parseStatus _obj);
etk::Stream& operator <<(etk::Stream& _os, enum parseStatus _obj);
//! @not-in-doc
extern const struct conversionTable constConversionTable[];
//! @not-in-doc
extern const int64_t constConversionTableSize;
//! @not-in-doc
etk::String createString(const std::vector<char32_t>& _data, int64_t _start=0, int64_t _stop=0x7FFFFFFF);
etk::String createString(const etk::Vector<char32_t>& _data, int64_t _start=0, int64_t _stop=0x7FFFFFFF);
//! @not-in-doc
char * levelSpace(uint32_t _level);
//! @not-in-doc
int64_t getLenOfPTheseElement(const std::vector<char32_t>& _data, int64_t _startPos);
int64_t getLenOfPTheseElement(const etk::Vector<char32_t>& _data, int64_t _startPos);
//! @not-in-doc
int64_t getLenOfPThese(const std::vector<char32_t>& _data, int64_t _startPos);
int64_t getLenOfPThese(const etk::Vector<char32_t>& _data, int64_t _startPos);
//! @not-in-doc
int64_t getLenOfBracket(const std::vector<char32_t>& _data, int64_t _startPos);
int64_t getLenOfBracket(const etk::Vector<char32_t>& _data, int64_t _startPos);
//! @not-in-doc
int64_t getLenOfBrace(const std::vector<char32_t>& _data, int64_t _startPos);
int64_t getLenOfBrace(const etk::Vector<char32_t>& _data, int64_t _startPos);
//! @not-in-doc
int64_t getLenOfNormal(const std::vector<char32_t>& _data, int64_t _startPos);
int64_t getLenOfNormal(const etk::Vector<char32_t>& _data, int64_t _startPos);
//! @not-in-doc
bool parseBrace(const std::vector<char32_t>& _data, uint32_t& _min, uint32_t& _max);
bool parseBrace(const etk::Vector<char32_t>& _data, uint32_t& _min, uint32_t& _max);
//! @not-in-doc
etk::String autoStr(const etk::String& _data);
etk::String autoStr(char _data);
@ -185,7 +185,7 @@ class FindProperty {
enum parseStatus m_status; //!< current status of parsing
int32_t m_subIndex; //!< under index int the upper list ... for (...)
public:
std::vector<FindProperty> m_subProperty; //!< list of all sub elements
etk::Vector<FindProperty> m_subProperty; //!< list of all sub elements
public:
FindProperty() :
m_positionStart(-1),
@ -276,7 +276,7 @@ class FindProperty {
}
};
std::ostream& operator <<(std::ostream& _os, const FindProperty& _obj);
etk::Stream& operator <<(etk::Stream& _os, const FindProperty& _obj);
/**
* @brief Node Elements for every-one
@ -285,7 +285,7 @@ std::ostream& operator <<(std::ostream& _os, const FindProperty& _obj);
template<class CLASS_TYPE> class Node {
protected :
// Data Section ... (can have no data...)
std::vector<char32_t> m_regExData; //!< data to parse and compare in some case ...
etk::Vector<char32_t> m_regExData; //!< data to parse and compare in some case ...
int32_t m_nodeLevel;
public :
/**
@ -310,7 +310,7 @@ template<class CLASS_TYPE> class Node {
* @param[in] _level Node level in the tree
* @return the number of element used
*/
virtual int32_t generate(const std::vector<char32_t>& _data) {
virtual int32_t generate(const etk::Vector<char32_t>& _data) {
return 0;
};
/**
@ -366,8 +366,8 @@ template<class CLASS_TYPE> class Node {
TK_WARNING("can not set multiplicity ...");
return;
}
m_multipleMin = std::max(_min, (uint32_t)0);
m_multipleMax = std::max(_max, (uint32_t)1);
m_multipleMin = etk::max(_min, (uint32_t)0);
m_multipleMax = etk::max(_max, (uint32_t)1);
}
protected:
/**
@ -407,23 +407,23 @@ template<class CLASS_TYPE> class Node {
template<class CLASS_TYPE> class NodeValue : public Node<CLASS_TYPE> {
protected :
// SubNodes :
std::vector<char32_t> m_data;
etk::Vector<char32_t> m_data;
public :
/**
* @brief Constructor
*/
NodeValue(int32_t _level) : Node<CLASS_TYPE>::Node(_level) { };
NodeValue(const std::vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
NodeValue(const etk::Vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
generate(_data);
};
int32_t generate(const std::vector<char32_t>& _data) {
int32_t generate(const etk::Vector<char32_t>& _data) {
Node<CLASS_TYPE>::m_regExData = _data;
TK_REG_DEBUG("Request Parse \"Value\" data=" << createString(Node<CLASS_TYPE>::m_regExData) );
m_data.clear();
for (int32_t i=0; i<(int64_t)Node<CLASS_TYPE>::m_regExData.size(); i++) {
m_data.push_back(Node<CLASS_TYPE>::m_regExData[i]);
m_data.pushBack(Node<CLASS_TYPE>::m_regExData[i]);
}
return _data.size();
};
@ -503,8 +503,8 @@ template<class CLASS_TYPE> class NodeValue : public Node<CLASS_TYPE> {
*/
template<class CLASS_TYPE> class NodeRangeValue : public Node<CLASS_TYPE> {
private:
std::vector<std::pair<char32_t, char32_t>> m_rangeList;
std::vector<char32_t> m_dataList;
etk::Vector<etk::Pair<char32_t, char32_t>> m_rangeList;
etk::Vector<char32_t> m_dataList;
bool m_invert;
const char *m_typeName;
public :
@ -522,10 +522,10 @@ template<class CLASS_TYPE> class NodeRangeValue : public Node<CLASS_TYPE> {
*/
virtual ~NodeRangeValue() { };
void addRange(char32_t _start, char32_t _stop) {
m_rangeList.push_back(std::make_pair(_start, _stop));
m_rangeList.pushBack(etk::makePair(_start, _stop));
}
void addValue(char32_t _value) {
m_dataList.push_back(_value);
m_dataList.pushBack(_value);
}
void setInvert(bool _newVal) {
m_invert = _newVal;
@ -648,10 +648,10 @@ template<class CLASS_TYPE> class NodeBracket : public NodeRangeValue<CLASS_TYPE>
NodeBracket(int32_t _level) : NodeRangeValue<CLASS_TYPE>::NodeRangeValue(_level) {
NodeRangeValue<CLASS_TYPE>::setDescriptiveName("[...]");
};
NodeBracket(const std::vector<char32_t>& _data, int32_t _level) : NodeRangeValue<CLASS_TYPE>::NodeRangeValue(_level) {
NodeBracket(const etk::Vector<char32_t>& _data, int32_t _level) : NodeRangeValue<CLASS_TYPE>::NodeRangeValue(_level) {
generate(_data);
};
int32_t generate(const std::vector<char32_t>& _data) {
int32_t generate(const etk::Vector<char32_t>& _data) {
Node<CLASS_TYPE>::m_regExData = _data;
TK_REG_DEBUG("Request Parse [...] data=" << createString(Node<CLASS_TYPE>::m_regExData) );
@ -776,13 +776,13 @@ template<class CLASS_TYPE> class NodePThese;
template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
protected :
// SubNodes :
std::vector<Node<CLASS_TYPE>*> m_subNode;
etk::Vector<Node<CLASS_TYPE>*> m_subNode;
public :
/**
* @brief Constructor
*/
NodePTheseElement(int32_t _level) : Node<CLASS_TYPE>::Node(_level) { };
NodePTheseElement(const std::vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
NodePTheseElement(const etk::Vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
generate(_data);
};
/**
@ -797,22 +797,22 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
*/
m_subNode.clear();
};
int32_t generate(const std::vector<char32_t>& _data) {
int32_t generate(const etk::Vector<char32_t>& _data) {
Node<CLASS_TYPE>::m_regExData = _data;
TK_REG_DEBUG("Request Parse (element) data=" << createString(Node<CLASS_TYPE>::m_regExData) );
int64_t pos = 0;
int64_t elementSize = 0;
std::vector<char32_t> tmpData;
etk::Vector<char32_t> tmpData;
while (pos < (int64_t)Node<CLASS_TYPE>::m_regExData.size()) {
tmpData.clear();
switch (Node<CLASS_TYPE>::m_regExData[pos]) {
case regexOpcodePTheseIn:{
elementSize=getLenOfPThese(Node<CLASS_TYPE>::m_regExData, pos);
for (int64_t kkk=pos+1; kkk<pos+elementSize+1; ++kkk) {
tmpData.push_back(Node<CLASS_TYPE>::m_regExData[kkk]);
tmpData.pushBack(Node<CLASS_TYPE>::m_regExData[kkk]);
}
// add to the under-node list :
m_subNode.push_back(new NodePThese<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
m_subNode.pushBack(new NodePThese<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
// move current position ...
pos += elementSize+1;
}
@ -823,10 +823,10 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
case regexOpcodeBracketIn: {
elementSize=getLenOfBracket(Node<CLASS_TYPE>::m_regExData, pos);
for (int64_t kkk=pos+1; kkk<pos+elementSize+1; ++kkk) {
tmpData.push_back(Node<CLASS_TYPE>::m_regExData[kkk]);
tmpData.pushBack(Node<CLASS_TYPE>::m_regExData[kkk]);
}
// add to the under-node list :
m_subNode.push_back(new NodeBracket<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
m_subNode.pushBack(new NodeBracket<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
// move current position ...
pos += elementSize+1;
}
@ -837,7 +837,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
case regexOpcodeBraceIn: {
elementSize = getLenOfBrace(Node<CLASS_TYPE>::m_regExData, pos);
for (int64_t kkk=pos+1; kkk<pos+elementSize+1; ++kkk) {
tmpData.push_back(Node<CLASS_TYPE>::m_regExData[kkk]);
tmpData.pushBack(Node<CLASS_TYPE>::m_regExData[kkk]);
}
uint32_t min = 0;
uint32_t max = 0;
@ -873,7 +873,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addValue('\0');
tmpNode->setCountOutput(false);
tmpNode->setMultiplicityAbility(false);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeDot:
@ -882,18 +882,18 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->setDescriptiveName("dot");
tmpNode->addValue('\0');
tmpNode->setInvert(true);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeStartOfLine:
m_subNode.push_back(new NodeSOL<CLASS_TYPE>(Node<CLASS_TYPE>::m_nodeLevel+1));
m_subNode.pushBack(new NodeSOL<CLASS_TYPE>(Node<CLASS_TYPE>::m_nodeLevel+1));
break;
case regexOpcodeEndOfLine:
{
NodeRangeValue<CLASS_TYPE>* tmpNode = new NodeRangeValue<CLASS_TYPE>(Node<CLASS_TYPE>::m_nodeLevel+1);
tmpNode->setDescriptiveName("EOL");
tmpNode->addValue('\n');
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeDigit:
@ -901,7 +901,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
NodeRangeValue<CLASS_TYPE>* tmpNode = new NodeRangeValue<CLASS_TYPE>(Node<CLASS_TYPE>::m_nodeLevel+1);
tmpNode->setDescriptiveName("digit");
tmpNode->addRange('0', '9');
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeDigitNot:
@ -910,7 +910,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->setDescriptiveName("digit-not");
tmpNode->addRange('0', '9');
tmpNode->setInvert(true);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeLetter:
@ -919,7 +919,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->setDescriptiveName("letter");
tmpNode->addRange('a', 'z');
tmpNode->addRange('A', 'Z');
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeLetterNot:
@ -929,7 +929,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addRange('a', 'z');
tmpNode->addRange('A', 'Z');
tmpNode->setInvert(true);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeSpace:
@ -942,7 +942,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addValue('\r');
tmpNode->addValue('\f');
tmpNode->addValue('\v');
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeSpaceNot:
@ -956,7 +956,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addValue('\f');
tmpNode->addValue('\v');
tmpNode->setInvert(true);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeWord:
@ -966,7 +966,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addRange('a', 'z');
tmpNode->addRange('A', 'Z');
tmpNode->addRange('0', '9');
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
case regexOpcodeWordNot:
@ -977,16 +977,16 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
tmpNode->addRange('A', 'Z');
tmpNode->addRange('0', '9');
tmpNode->setInvert(true);
m_subNode.push_back(tmpNode);
m_subNode.pushBack(tmpNode);
}
break;
default: {
elementSize = getLenOfNormal(Node<CLASS_TYPE>::m_regExData, pos);
for (int64_t kkk=pos; kkk<pos+elementSize; kkk++) {
tmpData.push_back(Node<CLASS_TYPE>::m_regExData[kkk]);
tmpData.pushBack(Node<CLASS_TYPE>::m_regExData[kkk]);
}
// add to the under-node list :
m_subNode.push_back(new NodeValue<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
m_subNode.pushBack(new NodeValue<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
// move current position ...
pos += elementSize-1;
}
@ -1070,7 +1070,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
TK_CRITICAL("Very bad case ... : " << prop);
}
tmpCurrentPos = prop.getPositionStop();
_property.m_subProperty.push_back(prop);
_property.m_subProperty.pushBack(prop);
TK_REG_DEBUG(" " << levelSpace(Node<CLASS_TYPE>::m_nodeLevel) << " (element=" << iii << "/" << m_subNode.size() << ") === OK === find : " << prop);
prop.reset();
prop.setPositionStart(tmpCurrentPos);
@ -1126,13 +1126,13 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
*/
template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
protected :
std::vector<Node<CLASS_TYPE>*> m_subNode; //!< Under-node list
etk::Vector<Node<CLASS_TYPE>*> m_subNode; //!< Under-node list
public :
/**
* @brief Constructor
*/
NodePThese(int32_t _level=0) : Node<CLASS_TYPE>::Node(_level) { };
NodePThese(const std::vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
NodePThese(const etk::Vector<char32_t>& _data, int32_t _level) : Node<CLASS_TYPE>::Node(_level) {
generate(_data);
};
/**
@ -1147,7 +1147,7 @@ template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
*/
m_subNode.clear();
}
int32_t generate(const std::vector<char32_t>& _data) {
int32_t generate(const etk::Vector<char32_t>& _data) {
Node<CLASS_TYPE>::m_regExData = _data;
TK_REG_DEBUG("Request Parse (...) data=" << createString(Node<CLASS_TYPE>::m_regExData) );
//Find all the '|' in the string (and at the good level ...)
@ -1156,12 +1156,12 @@ template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
// generate all the "elementTypePTheseElement" of the Node
while (elementSize>0) {
// Generate output data ...
std::vector<char32_t> tmpData;
etk::Vector<char32_t> tmpData;
for (int64_t kkk=pos; kkk<pos+elementSize; kkk++) {
tmpData.push_back(Node<CLASS_TYPE>::m_regExData[kkk]);
tmpData.pushBack(Node<CLASS_TYPE>::m_regExData[kkk]);
}
// add to the under-node list :
m_subNode.push_back(new NodePTheseElement<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
m_subNode.pushBack(new NodePTheseElement<CLASS_TYPE>(tmpData, Node<CLASS_TYPE>::m_nodeLevel+1));
pos += elementSize+1;
TK_REG_DEBUG("plop=" << createString(Node<CLASS_TYPE>::m_regExData, pos, pos+1) );
elementSize = getLenOfPTheseElement(Node<CLASS_TYPE>::m_regExData, pos);
@ -1249,7 +1249,7 @@ template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
if (prop.getPositionStart() > prop.getPositionStop()) {
TK_CRITICAL("Very bad case ... : " << prop);
}
_property.m_subProperty.push_back(prop);
_property.m_subProperty.pushBack(prop);
break;
}
for (size_t iii=iiiStartPos; iii<m_subNode.size() && tmpCurrentPos+offset<_lenMax; ++iii) {
@ -1265,7 +1265,7 @@ template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
if (prop.getPositionStart() > prop.getPositionStop()) {
TK_CRITICAL("Very bad case ... : " << prop);
}
_property.m_subProperty.push_back(prop);
_property.m_subProperty.pushBack(prop);
tmpFind = true;
prop.reset();
prop.setPositionStart(tmpCurrentPos+offset);
@ -1448,7 +1448,7 @@ template<class CLASS_TYPE> class RegEx {
*/
void compile(const etk::UString &_expression) {
m_expressionRequested = _expression;
std::vector<char32_t> tmpExpression;
etk::Vector<char32_t> tmpExpression;
TK_REG_DEBUG("---------------------------------------------------------------------");
TK_REG_DEBUG("Parse RegEx : (" << m_expressionRequested << ")" );
@ -1478,9 +1478,9 @@ template<class CLASS_TYPE> class RegEx {
if ( regex::constConversionTable[jjj].haveBackSlash == true
&& _expression[iii+1] == (char32_t)regex::constConversionTable[jjj].inputValue) {
if (regex::constConversionTable[jjj].newValue == 0) {
tmpExpression.push_back(regex::constConversionTable[jjj].specialChar);
tmpExpression.pushBack(regex::constConversionTable[jjj].specialChar);
} else {
tmpExpression.push_back(regex::constConversionTable[jjj].newValue);
tmpExpression.pushBack(regex::constConversionTable[jjj].newValue);
}
break;
}
@ -1515,9 +1515,9 @@ template<class CLASS_TYPE> class RegEx {
&& _expression[iii] == (char32_t)regex::constConversionTable[jjj].inputValue)
{
if (regex::constConversionTable[jjj].newValue == 0) {
tmpExpression.push_back(regex::constConversionTable[jjj].specialChar);
tmpExpression.pushBack(regex::constConversionTable[jjj].specialChar);
} else {
tmpExpression.push_back(regex::constConversionTable[jjj].newValue);
tmpExpression.pushBack(regex::constConversionTable[jjj].newValue);
}
break;
}
@ -1525,7 +1525,7 @@ template<class CLASS_TYPE> class RegEx {
// not find : normal element
if (jjj == regex::constConversionTableSize) {
//TK_REG_DEBUG("parse : '" << _regex[iii] << "'" );
tmpExpression.push_back(_expression[iii]);
tmpExpression.pushBack(_expression[iii]);
}
}
}
@ -1817,7 +1817,7 @@ template<class CLASS_TYPE> class RegEx {
* @return true The current node is correct.
* @return false An error in parsing has appeared.
*/
bool checkGoodPosition(const std::vector<char32_t>& _tmpExpression, int64_t& _pos) {
bool checkGoodPosition(const etk::Vector<char32_t>& _tmpExpression, int64_t& _pos) {
char32_t currentCode = _tmpExpression[_pos];
char32_t endCode = regexOpcodePTheseOut;
const char *input = "(...)";
@ -1933,7 +1933,7 @@ template<class CLASS_TYPE> class RegEx {
* @return true The regular expression is correct.
* @return false an error occurred in the regular expression.
*/
bool checkGoodPosition(const std::vector<char32_t>& _tmpExpression) {
bool checkGoodPosition(const etk::Vector<char32_t>& _tmpExpression) {
int64_t pos = 0;
while (pos < (int64_t)_tmpExpression.size()) {
//TK_DEBUG("check : " << tmpExpression[pos]);

75
etk/Stream.cpp Normal file
View File

@ -0,0 +1,75 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#include <etk/Stream.hpp>
#include <etk/String.hpp>
etk::Stream::Stream(size_t _basicSize) :
m_data(new etk::String) {
}
etk::Stream::~Stream() {
delete m_data;
m_data = nullptr;
}
etk::Stream& etk::Stream::operator<< (const char* _data) {
*m_data += _data;
return *this;
}
etk::Stream& etk::Stream::operator<< (const bool _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int8_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int16_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int32_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int64_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint8_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint16_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint32_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint64_t _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const float _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const double _data) {
*m_data += etk::toString(_data);
return *this;
}
const char* etk::Stream::c_str() const {
return m_data->c_str();
}
const size_t etk::Stream::size() const {
return m_data->size();
}

54
etk/Stream.hpp Normal file
View File

@ -0,0 +1,54 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
namespace etk {
class String;
/**
* @brief string class ...
*/
class Stream {
private:
// remove dependency of std::string and vector
etk::String* m_data;
public:
Stream(size_t _basicSize=0);
~Stream();
Stream& operator<< (const char* _data);
Stream& operator<< (bool _data);
Stream& operator<< (int8_t _data);
Stream& operator<< (int16_t _data);
Stream& operator<< (int32_t _data);
Stream& operator<< (int64_t _data);
Stream& operator<< (uint8_t _data);
Stream& operator<< (uint16_t _data);
Stream& operator<< (uint32_t _data);
Stream& operator<< (uint64_t _data);
Stream& operator<< (float _data);
Stream& operator<< (double _data);
const char* c_str() const;
const size_t size() const;
};
// TODO: This is not a good place ...
/*
//! @not_in_doc
template<class ETK_VECTOR_TYPE>
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
_os << "{";
for (size_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) {
_os << ";";
}
_os << _obj[iii];
}
_os << "}";
return _os;
}
*/
}

View File

@ -1,6 +1,7 @@
#include <etk/String.hpp>
#include <etk/UString.hpp>
etk::String::String():
m_data() {
@ -39,13 +40,14 @@ etk::String::String(const char* _obj) {
m_data[iii] = _obj[iii];
}
}
/*
etk::String::String(const std::string _obj) {
resize(_obj.size());
for (size_t iii=0; iii<_obj.size(); ++iii) {
m_data[iii] = _obj[iii];
}
}
*/
etk::String::String(const char* _obj, size_t _size) {
if ( _obj == nullptr
@ -80,7 +82,7 @@ etk::String::String(Iterator _start, Iterator _stop) {
}
etk::String::String(etk::String&& _obj) noexcept {
m_data = std::move(_obj.m_data);
m_data = etk::move(_obj.m_data);
}
etk::String::String(char _value) {
@ -176,7 +178,7 @@ void etk::String::pushBack(const char _item) {
if (idElement < size()) {
m_data[idElement] = _item;
} else {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
}
}
@ -187,7 +189,7 @@ void etk::String::pushBack(const char* _item, size_t _nbElement) {
size_t idElement = size();
resize(size()+_nbElement);
if (idElement > size()) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
for (size_t iii=0; iii<_nbElement; iii++) {
@ -207,7 +209,7 @@ void etk::String::clear() {
void etk::String::insert(size_t _pos, const char* _item, size_t _nbElement) {
if (_pos>size()) {
TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
//TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
@ -215,7 +217,7 @@ void etk::String::insert(size_t _pos, const char* _item, size_t _nbElement) {
// Request resize of the current buffer
resize(size()+_nbElement);
if (idElement>=size()) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
// move current data (after the position)
@ -241,7 +243,7 @@ void etk::String::insert(size_t _pos, const etk::String& _value) {
void etk::String::erase(size_t _pos, size_t _nbElement) {
if (_pos>size()) {
TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
//TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
return;
}
if (_pos+_nbElement>size()) {
@ -261,7 +263,7 @@ void etk::String::erase(size_t _pos, size_t _nbElement) {
void etk::String::eraseRange(size_t _pos, size_t _posEnd) {
if (_pos>size()) {
TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
//TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
return;
}
if (_posEnd > size()) {
@ -564,7 +566,7 @@ bool etk::String::to<bool>() const {
return false;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::String& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::String& _obj) {
_os << _obj.c_str();
return _os;
}
@ -686,7 +688,7 @@ etk::String etk::toString(const int32_t& _val) {
template<>
etk::String etk::toString(const int64_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%lld", _val);
sprintf(tmpVal, "%ld", _val);
return tmpVal;
}
template<>
@ -710,15 +712,17 @@ etk::String etk::toString(const uint32_t& _val) {
template<>
etk::String etk::toString(const uint64_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%llu", _val);
sprintf(tmpVal, "%lu", _val);
return tmpVal;
}
/*
template<>
etk::String etk::toString(const size_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%zu", _val);
return tmpVal;
}
*/
template<>
etk::String etk::toString(const float& _val) {
@ -739,6 +743,23 @@ etk::String etk::toString(const long double& _val) {
return tmpVal;
}
template<> etk::String etk::toString(const etk::UString& _input) {
etk::String out;
for (size_t iii=0; iii<_input.size(); ++iii) {
char output[10];
u32char::convertUtf8(_input[iii], output);
out += output;
}
return out;
}
template<> etk::String etk::toString(const char32_t& _input) {
etk::String out;
char output[10];
u32char::convertUtf8(_input, output);
out += output;
return out;
}
size_t etk::String::find(char _value, size_t _pos) const {
for (size_t iii=_pos; iii<m_data.size(); ++iii) {
if (_value == m_data[iii]) {

View File

@ -6,9 +6,9 @@
#pragma once
#include <etk/types.hpp>
#include <etk/debug.hpp>
//#include <etk/debug.hpp>
#include <etk/Vector.hpp>
#include <etk/stdTools.hpp>
namespace etk {
/**
@ -145,7 +145,7 @@ namespace etk {
* @return the reference on the current Element
*/
char operator* () const {
TK_ASSERT(m_current < m_string->size(), "out of range");
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/**
@ -153,7 +153,7 @@ namespace etk {
* @return the reference on the current Element
*/
char& operator* () {
TK_ASSERT(m_current < m_string->size(), "out of range");
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/*****************************************************
@ -222,7 +222,7 @@ namespace etk {
*/
String(const char* _obj);
// TODO : remove this when ready
String(const std::string _obj);
//////// String(const std::string _obj);
/**
* @brief Partial copy of the null-terminated C string.
* @param[in] _obj String that might be copyC string that might be copy (end by '\0')
@ -472,7 +472,7 @@ namespace etk {
template <class TYPE>
etk::String toString(const TYPE& _variable);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::String& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::String& _obj);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value

View File

@ -34,7 +34,7 @@ etk::UString::UString(const char32_t* _obj) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
uint32_t size = u32char::strlen(_obj);
resize(size);
for (size_t iii=0; iii<size; ++iii) {
m_data[iii] = _obj[iii];
@ -47,7 +47,7 @@ etk::UString::UString(const char32_t* _obj, size_t _size) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
uint32_t size = u32char::strlen(_obj);
if (_size < size) {
size = _size;
}
@ -74,7 +74,7 @@ etk::UString::UString(Iterator _start, Iterator _stop) {
}
etk::UString::UString(etk::UString&& _obj) noexcept {
m_data = std::move(_obj.m_data);
m_data = etk::move(_obj.m_data);
}
etk::UString::UString(char32_t _value) {
@ -106,7 +106,7 @@ etk::UString& etk::UString::operator=(const char32_t* _obj) {
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
size_t numberElement = u32char::strlen(_obj);
resize(numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
m_data[iii] = _obj[iii];
@ -137,7 +137,7 @@ etk::UString& etk::UString::operator+= (const char32_t* _obj) {
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
size_t numberElement = u32char::strlen(_obj);
size_t idElement = size();
resize(size() + numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
@ -170,7 +170,7 @@ void etk::UString::pushBack(const char32_t _item) {
if (idElement < size()) {
m_data[idElement] = _item;
} else {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
}
}
@ -181,7 +181,7 @@ void etk::UString::pushBack(const char32_t* _item, size_t _nbElement) {
size_t idElement = size();
resize(size()+_nbElement);
if (idElement > size()) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
for (size_t iii=0; iii<_nbElement; iii++) {
@ -201,7 +201,7 @@ void etk::UString::clear() {
void etk::UString::insert(size_t _pos, const char32_t* _item, size_t _nbElement) {
if (_pos>size()) {
TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
//TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
@ -209,7 +209,7 @@ void etk::UString::insert(size_t _pos, const char32_t* _item, size_t _nbElement)
// Request resize of the current buffer
resize(size()+_nbElement);
if (idElement>=size()) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
// move current data (after the position)
@ -235,7 +235,7 @@ void etk::UString::insert(size_t _pos, const etk::UString& _value) {
void etk::UString::erase(size_t _pos, size_t _nbElement) {
if (_pos>size()) {
TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
//TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
return;
}
if (_pos+_nbElement>size()) {
@ -255,7 +255,7 @@ void etk::UString::erase(size_t _pos, size_t _nbElement) {
void etk::UString::eraseRange(size_t _pos, size_t _posEnd) {
if (_pos>size()) {
TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
//TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
return;
}
if (_posEnd > size()) {
@ -357,33 +357,17 @@ bool etk::UString::operator!= (const etk::UString& _obj) const {
}
char32_t etk::toLower(char32_t _value) {
if ( _value >= 'A'
&& _value <= 'Z') {
return _value + ('a' - 'A');
}
return _value;
}
char32_t etk::toUpper(char32_t _value) {
if ( _value >= 'a'
&& _value <= 'z') {
return _value + ('A' - 'z');
}
return _value;
}
etk::UString etk::UString::toLower() const {
etk::UString tmp(*this);
for (auto &it: tmp) {
it = etk::toLower(it);
it = u32char::toLower(it);
}
return tmp;
}
etk::UString& etk::UString::lower() {
for (auto &it: m_data) {
it = etk::toLower(it);
it = u32char::toLower(it);
}
return *this;
}
@ -391,14 +375,14 @@ etk::UString& etk::UString::lower() {
etk::UString etk::UString::toUpper() const {
etk::UString tmp(*this);
for (auto &it: tmp) {
it = etk::toUpper(it);
it = u32char::toUpper(it);
}
return tmp;
}
etk::UString& etk::UString::upper() {
for (auto &it: m_data) {
it = etk::toUpper(it);
it = u32char::toUpper(it);
}
return *this;
}
@ -423,7 +407,7 @@ bool etk::UString::endWith(const etk::UString& _val, bool _caseSensitive) const
for( int64_t iii=_val.size()-1, jjj=size()-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[jjj])) {
if (u32char::toLower(_val[iii]) != u32char::toLower(m_data[jjj])) {
return false;
}
}
@ -450,7 +434,7 @@ bool etk::UString::startWith(const etk::UString& _val, bool _caseSensitive) cons
for( size_t iii = 0;
iii < _val.size();
iii++) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
if (u32char::toLower(_val[iii]) != u32char::toLower(m_data[iii])) {
return false;
}
}
@ -459,68 +443,57 @@ bool etk::UString::startWith(const etk::UString& _val, bool _caseSensitive) cons
template <>
long double etk::UString::to<long double>() const {
etk::Number value(*this);
return value.getDouble();
return etk::toString(*this).to<long double>();
}
template <>
double etk::UString::to<double>() const {
etk::Number value(*this);
return value.getDouble();
return etk::toString(*this).to<double>();
}
template <>
float etk::UString::to<float>() const {
etk::Number value(*this);
return value.getDouble();
return etk::toString(*this).to<float>();
}
template <>
int8_t etk::UString::to<int8_t>() const {
etk::Number value(*this);
return value.getI64();
return etk::toString(*this).to<int8_t>();
}
template <>
int16_t etk::UString::to<int16_t>() const {
etk::Number value(*this);
return value.getI64();
return etk::toString(*this).to<int16_t>();
}
template <>
int32_t etk::UString::to<int32_t>() const {
etk::Number value(*this);
return value.getI64();
return etk::toString(*this).to<int32_t>();
}
template <>
int64_t etk::UString::to<int64_t>() const {
etk::Number value(*this);
return value.getI64();
return etk::toString(*this).to<int64_t>();
}
template <>
uint8_t etk::UString::to<uint8_t>() const {
etk::Number value(*this);
return value.getU64();
return etk::toString(*this).to<uint8_t>();
}
template <>
uint16_t etk::UString::to<uint16_t>() const {
etk::Number value(*this);
return value.getU64();
return etk::toString(*this).to<uint16_t>();
}
template <>
uint32_t etk::UString::to<uint32_t>() const {
etk::Number value(*this);
return value.getU64();
return etk::toString(*this).to<uint32_t>();
}
template <>
uint64_t etk::UString::to<uint64_t>() const {
etk::Number value(*this);
return value.getU64();
return etk::toString(*this).to<uint64_t>();
}
template <>
@ -534,7 +507,7 @@ bool etk::UString::to<bool>() const {
return false;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::UString& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::UString& _obj) {
_os << _obj.c_str();
return _os;
}
@ -628,6 +601,14 @@ namespace etk {
}
}
template<>
etk::UString etk::toUString<char*>(char* const & _input) {
return utf8::convertUnicode(_input);
}
template<>
etk::UString etk::toUString<etk::String>(const etk::String& _input) {
return utf8::convertUnicode(_input);
}
template<>
etk::UString etk::toUString(const bool& _val) {
return utf8::convertUnicode(etk::toString(_val));
@ -664,11 +645,12 @@ template<>
etk::UString etk::toUString(const uint64_t& _val) {
return utf8::convertUnicode(etk::toString(_val));
}
/*
template<>
etk::UString etk::toUString(const size_t& _val) {
return utf8::convertUnicode(etk::toString(_val));
}
*/
template<>
etk::UString etk::toUString(const float& _val) {
return utf8::convertUnicode(etk::toString(_val));
@ -817,7 +799,7 @@ bool etk::UString::compare(const etk::UString& _val, bool _caseSensitive) const
return true;
}
for(size_t iii=0; iii<_val.size(); ++iii) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
if (u32char::toLower(_val[iii]) != u32char::toLower(m_data[iii])) {
return false;
}
}

View File

@ -6,7 +6,7 @@
#pragma once
#include <etk/types.hpp>
#include <etk/debug.hpp>
//#include <etk/debug.hpp>
#include <etk/Vector.hpp>
#include <etk/utf8.hpp>
#include <etk/stdTools.hpp>
@ -146,7 +146,7 @@ namespace etk {
* @return the reference on the current Element
*/
char32_t operator* () const {
TK_ASSERT(m_current < m_string->size(), "out of range");
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/**
@ -154,7 +154,7 @@ namespace etk {
* @return the reference on the current Element
*/
char32_t& operator* () {
TK_ASSERT(m_current < m_string->size(), "out of range");
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/*****************************************************
@ -471,7 +471,7 @@ namespace etk {
template <class TYPE>
etk::UString toUString(const TYPE& _variable);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::UString& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::UString& _obj);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value

View File

@ -6,9 +6,10 @@
#pragma once
#include <etk/types.hpp>
#include <etk/debug.hpp>
//#include <etk/debug.hpp>
namespace etk {
class Stream;
/**
* @brief Vector class ...
*
@ -42,6 +43,7 @@ namespace etk {
*/
template<class ETK_VECTOR_TYPE> class Vector {
public:
static const size_t npos = size_t(-1);
class Iterator {
private:
size_t m_current; //!< current Id on the vector
@ -138,6 +140,15 @@ namespace etk {
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int64_t _offset) {
m_current -= _offset;
return *this;
@ -156,6 +167,15 @@ namespace etk {
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int64_t _offset) {
m_current += _offset;
return *this;
@ -170,7 +190,7 @@ namespace etk {
* @return the reference on the current Element
*/
ETK_VECTOR_TYPE & operator-> () const {
TK_CHECK_INOUT(m_current < m_vector->size());
//TK_CHECK_INOUT(m_current < m_vector->size());
return &m_vector->get(m_current);
}
/**
@ -178,7 +198,7 @@ namespace etk {
* @return the reference on the current Element
*/
ETK_VECTOR_TYPE & operator* () const {
TK_CHECK_INOUT(m_current < m_vector->size());
//TK_CHECK_INOUT(m_current < m_vector->size());
return m_vector->get(m_current);
}
private:
@ -216,7 +236,7 @@ namespace etk {
// allocate all same data
m_data = new ETK_VECTOR_TYPE[m_allocated];
if (m_data == nullptr) {
TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
//TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
return;
}
// Copy all data ...
@ -272,7 +292,7 @@ namespace etk {
// allocate all same data
m_data = new ETK_VECTOR_TYPE[m_allocated];
if (m_data == nullptr) {
TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
//TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
return *this;
}
for(size_t iii=0; iii<m_allocated; iii++) {
@ -293,12 +313,12 @@ namespace etk {
size_t idElement = m_size;
resize(m_size+numberElement);
if (m_size<=idElement) {
TK_CRITICAL("allocation error");
//TK_CRITICAL("allocation error");
return *this;
}
for(size_t iii=0; iii<numberElement; iii++) {
// copy operator ...
m_data[idElement+iii] = _obj.m_data[iii];
m_data[idElement+iii] = etk::move(_obj.m_data[iii]);
}
// Return the current pointer
return *this;
@ -310,6 +330,9 @@ namespace etk {
size_t size() const {
return m_size;
}
size_t empty() const {
return m_size == 0;
}
/**
* @brief Resize the vector with a basic element
* @param[in] _newSize New size of the vector
@ -318,7 +341,7 @@ namespace etk {
size_t idElement = m_size;
resize(_newSize);
if (m_size != _newSize) {
TK_CRITICAL("error to resize vector");
//TK_CRITICAL("error to resize vector");
return;
}
if (_newSize > idElement) {
@ -371,6 +394,26 @@ namespace etk {
#endif
return m_data[_pos];
}
/**
* @brief Get the last element of the vector
* @return An reference on the element
*/
ETK_VECTOR_TYPE& back() {
return m_data[m_size-1];
}
const ETK_VECTOR_TYPE& back() const {
return m_data[m_size-1];
}
/**
* @brief Get the first element of the vector
* @return An reference on the element
*/
ETK_VECTOR_TYPE& front() {
return m_data[0];
}
const ETK_VECTOR_TYPE& front() const {
return m_data[0];
}
/**
* @brief Add at the First position of the Vector
* @param[in] _item Element to add at the end of vector
@ -394,9 +437,9 @@ namespace etk {
size_t idElement = m_size;
resize(m_size+1);
if (idElement < m_size) {
m_data[idElement] = _item;
m_data[idElement] = etk::move(_item);
} else {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
}
}
/**
@ -411,7 +454,7 @@ namespace etk {
size_t idElement = m_size;
resize(m_size+_nbElement);
if (idElement > m_size) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
for (size_t iii=0; iii<_nbElement; iii++) {
@ -442,7 +485,7 @@ namespace etk {
*/
void insert(size_t _pos, const ETK_VECTOR_TYPE * _item, size_t _nbElement) {
if (_pos>m_size) {
TK_WARNING(" can not insert Element at this position : " << _pos << " > " << m_size << " add it at the end ... ");
//TK_WARNING(" can not insert Element at this position : " << _pos << " > " << m_size << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
@ -450,19 +493,19 @@ namespace etk {
// Request resize of the current buffer
resize(m_size+_nbElement);
if (idElement>=m_size) {
TK_ERROR("Resize does not work correctly ... not added item");
//TK_ERROR("Resize does not work correctly ... not added item");
return;
}
// move current data (after the position)
size_t sizeToMove = (idElement - _pos);
if ( 0 < sizeToMove) {
for (size_t iii=1; iii<=sizeToMove; iii++) {
m_data[m_size-iii] = m_data[idElement-iii];
m_data[m_size-iii] = etk::move(m_data[idElement-iii]);
}
}
// affectation of all input element
for (size_t iii=0; iii<_nbElement; iii++) {
m_data[_pos+iii] = _item[iii];
m_data[_pos+iii] = etk::move(_item[iii]);
}
}
/**
@ -480,7 +523,7 @@ namespace etk {
*/
void eraseLen(size_t _pos, size_t _nbElement) {
if (_pos>m_size) {
TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << m_size);
//TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << m_size);
return;
}
if (_pos+_nbElement>m_size) {
@ -491,7 +534,7 @@ namespace etk {
size_t sizeToMove = (idElement - (_pos+_nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
m_data[_pos+iii] = etk::move(m_data[_pos+_nbElement+iii]);
}
}
// Request resize of the current buffer
@ -504,6 +547,15 @@ namespace etk {
inline void erase(size_t _pos) {
eraseLen(_pos, 1);
}
/**
* @brief Remove one element
* @param[in] _it Iterator on the element to remove
* @return An iterator on the new element at this position.
*/
Iterator erase(const Iterator& _it) {
eraseLen(_it.m_current, 1);
return position(_it.m_current);
}
/**
* @brief Remove one element
* @param[in] _pos Position to remove the data
@ -518,7 +570,7 @@ namespace etk {
*/
void erase(size_t _pos, size_t _posEnd) {
if (_pos>m_size) {
TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << m_size);
//TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << m_size);
return;
}
if (_posEnd>m_size) {
@ -530,7 +582,7 @@ namespace etk {
size_t sizeToMove = (tmpSize - (_pos+nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+nbElement+iii];
m_data[_pos+iii] = etk::move(m_data[_pos+nbElement+iii]);
}
}
// Request resize of the current buffer
@ -591,7 +643,7 @@ namespace etk {
const Iterator end() const {
return position( size()-1 );
}
private:
/**
* @brief Change the current size of the vector
* @param[in] _newSize New requested size of element in the vector
@ -603,6 +655,7 @@ namespace etk {
}
m_size = _newSize;
}
private:
/**
* @brief Change the current allocation to the correct one (depend on the current size)
* @param[in] _newSize Minimum number of element needed
@ -637,7 +690,7 @@ namespace etk {
// no data allocated ==> request an allocation (might be the first)
m_data = new ETK_VECTOR_TYPE[requestSize];
if (m_data == nullptr) {
TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
m_allocated = 0;
return;
}
@ -645,14 +698,14 @@ namespace etk {
// allocate a new pool of data:
ETK_VECTOR_TYPE* m_dataTmp = new ETK_VECTOR_TYPE[requestSize];
if (m_dataTmp == nullptr) {
TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
m_allocated = 0;
return;
}
// copy data in the new pool
size_t nbElements = etk::min(requestSize, m_allocated);
for(size_t iii=0; iii<nbElements; iii++) {
m_dataTmp[iii] = std::move(m_data[iii]);
m_dataTmp[iii] = etk::move(m_data[iii]);
}
// switch pointer:
ETK_VECTOR_TYPE* m_dataTmp2 = m_data;
@ -712,20 +765,62 @@ namespace etk {
}
return false;
}
};
//! @not_in_doc
template<class ETK_VECTOR_TYPE>
std::ostream& operator <<(std::ostream& _os, const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
_os << "{";
for (size_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) {
_os << ";";
/*****************************************************
* >= operator
*****************************************************/
bool operator>= (const Vector<ETK_VECTOR_TYPE>& _obj) const {
// TODO : Later
return false;
}
_os << _obj[iii];
}
_os << "}";
return _os;
}
/*****************************************************
* > operator
*****************************************************/
bool operator> (const Vector<ETK_VECTOR_TYPE>& _obj) const {
// TODO : Later
return false;
}
/*****************************************************
* <= operator
*****************************************************/
bool operator<= (const Vector<ETK_VECTOR_TYPE>& _obj) const {
// TODO : Later
return false;
}
/*****************************************************
* > operator
*****************************************************/
bool operator< (const Vector<ETK_VECTOR_TYPE>& _obj) const {
// TODO : Later
return false;
}
void sort(size_t _start, size_t _stop, bool (*_comparator)(const ETK_VECTOR_TYPE&, const ETK_VECTOR_TYPE&)) {
if (_stop > m_size) {
_stop = m_size;
}
if (_start > m_size) {
_start = m_size;
}
if (_start > _stop) {
size_t start = _start;
_start = _stop;
_stop = _start;
}
for (size_t iii=_start; iii<_stop; ++iii) {
bool swapped = false;
for (size_t jjj=_start; jjj<_stop - (iii+1); ++jjj) {
if (_comparator(m_data[jjj], m_data[jjj+1]) == true) {
ETK_VECTOR_TYPE tmp = etk::move(m_data[jjj]);
m_data[jjj+1] = etk::move(m_data[jjj]);
m_data[jjj+1] = etk::move(tmp);
swapped = true;
}
}
if (swapped == false) {
break;
}
}
}
};
//! @not_in_doc
template<typename T, typename T2>
bool isIn(const T& _val, const etk::Vector<T2>& _list) {

View File

@ -9,7 +9,7 @@
#pragma once
#include <map>
#include <etk/Map.hpp>
#include <mutex>
#include <ememory/memory.hpp>
#include <etk/String.hpp>
@ -52,7 +52,7 @@ namespace etk {
return m_theoricSize;
}
private:
std::vector<char> m_data; //!< Data read from the zip file (if m_data.size() != m_theoricSize the data is not read)
etk::Vector<char> m_data; //!< Data read from the zip file (if m_data.size() != m_theoricSize the data is not read)
public:
/**
* @brief Basic constructor of an element
@ -81,7 +81,7 @@ namespace etk {
* @brief Get the Data Vector on the file.
* @return Vector on the data.
*/
std::vector<char>& getDataVector() {
etk::Vector<char>& getDataVector() {
return m_data;
}
};
@ -115,7 +115,7 @@ namespace etk {
return m_fileName;
};
protected:
std::map<etk::String, ArchiveContent> m_content; //!< list of element of the zip file
etk::Map<etk::String, ArchiveContent> m_content; //!< list of element of the zip file
public:
/**
* @brief Get the number of elements
@ -167,7 +167,7 @@ namespace etk {
* @brief Request the load in memory of the concerned file.
* @param[in] _it Iterator on the element.
*/
virtual void loadFile(const std::map<etk::String, ArchiveContent>::iterator& _it) { };
virtual void loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& _it) { };
public:
/**
* @brief Load an Achive with a specific name.

View File

@ -38,7 +38,7 @@ etk::archive::Zip::Zip(const etk::String& _fileName, uint64_t _offset) :
// find directory ...
} else {
TK_INFO("find file : " << tmpFileName);
m_content.insert(std::pair<etk::String, etk::ArchiveContent>(tmpFileName, etk::ArchiveContent(tmpFileInfo.uncompressed_size)));
m_content.insert(etk::Pair<etk::String, etk::ArchiveContent>(tmpFileName, etk::ArchiveContent(tmpFileInfo.uncompressed_size)));
}
/* Go the the next entry listed in the zip file. */
if((iii+1) < m_info.number_entry) {
@ -57,7 +57,7 @@ etk::archive::Zip::~Zip() {
};
}
void etk::archive::Zip::loadFile(const std::map<etk::String, ArchiveContent>::iterator& it) {
void etk::archive::Zip::loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& it) {
TK_VERBOSE("Real load file : '" << it->first << "'");
unzGoToFirstFile(m_ctx);

View File

@ -34,7 +34,7 @@
*/
virtual ~Zip();
protected:
void loadFile(const std::map<etk::String, ArchiveContent>::iterator& _it) override;
void loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& _it) override;
};
}
}

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp>
#include <etk/math/Vector2D.hpp>
#include <vector>
#include <etk/Vector.hpp>
namespace etk {
/**
@ -17,7 +17,7 @@ namespace etk {
template <typename T> class Matrix {
private:
uivec2 m_size; //!< Size of the Matrix
std::vector<T> m_data; //!< Data of the matrix
etk::Vector<T> m_data; //!< Data of the matrix
public:
/**
* @brief Contructor that create a Vector with a specific size and specific raw data
@ -141,7 +141,7 @@ namespace etk {
const Matrix<T>& operator+= (const Matrix<T>& _obj) {
if (m_size != _obj.m_size) {
//TK_CRITICAL("add 2 Matrix with différent size ... ==> generate the max size of all the 2 matrix");
etk::Matrix<T> tmpMatrix(std::max(m_size.x(),_obj.m_size.x()), std::max(m_size.y(),_obj.m_size.y()));
etk::Matrix<T> tmpMatrix(etk::max(m_size.x(),_obj.m_size.x()), etk::max(m_size.y(),_obj.m_size.y()));
for (int32_t jjj=0; jjj< m_size.y(); jjj++) {
T* tmpPointer = tmpMatrix[jjj];
T* tmpPointerIn = (*this)[jjj];
@ -195,7 +195,7 @@ namespace etk {
const Matrix<T>& operator-= (const Matrix<T>& _obj) {
if (m_size != _obj.m_size) {
//TK_CRITICAL("less 2 Matrix with different size ... ==> generate the max size of all the 2 matrix");
etk::Matrix<T> tmpMatrix(std::max(m_size.x(),_obj.m_size.x()), std::max(m_size.y(),_obj.m_size.y()));
etk::Matrix<T> tmpMatrix(etk::max(m_size.x(),_obj.m_size.x()), etk::max(m_size.y(),_obj.m_size.y()));
for (int32_t jjj=0; jjj< m_size.y; jjj++) {
T* tmpPointer = tmpMatrix[jjj];
T* tmpPointerIn = (*this)[jjj];

View File

@ -6,7 +6,7 @@
#include <etk/math/Matrix2x2.hpp>
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix2x2& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Matrix2x2& _obj) {
_os << "{";
_os << _obj.m_mat[0] << ",";
_os << _obj.m_mat[1] << ";";

View File

@ -221,7 +221,7 @@ namespace etk {
*/
Matrix2x2 mat2x2Skew(const vec2& _skew);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Matrix2x2& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Matrix2x2& _obj);
}
etk::Matrix2x2 operator-(const etk::Matrix2x2& _matrix);

View File

@ -6,7 +6,7 @@
#include <etk/math/Matrix2x3.hpp>
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix2x3& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Matrix2x3& _obj) {
_os << "{";
_os << _obj.m_mat[0] << ",";
_os << _obj.m_mat[4] << ",";

View File

@ -203,7 +203,7 @@ namespace etk {
*/
Matrix2x3 mat2x3Skew(const vec2& _skew);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Matrix2x3& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Matrix2x3& _obj);
}
// simplify using of matrix ...
using mat2x3 = etk::Matrix2x3; //!< Use simplification in upper application to use matrix like openGL shader

View File

@ -7,7 +7,7 @@
#include <etk/math/Matrix3x3.hpp>
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix3x3& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Matrix3x3& _obj) {
_os << "{";
_os << _obj.m_mat[0] << ",";
_os << _obj.m_mat[1] << ",";

View File

@ -211,7 +211,7 @@ namespace etk {
vec3 operator * (const vec3& _point) const;
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Matrix3x3& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Matrix3x3& _obj);
}
etk::Matrix3x3 operator-(const etk::Matrix3x3& _matrix);

View File

@ -372,7 +372,7 @@ etk::Matrix4x4 etk::Matrix4x4::invert() {
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Matrix4x4& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Matrix4x4& _obj) {
_os << "matrix4 : (";
for (int32_t iii=0; iii<16; iii++) {
_os << _obj.m_mat[iii];

View File

@ -250,7 +250,7 @@ namespace etk {
const vec3& _target,
const vec3& _up);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Matrix4x4& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Matrix4x4& _obj);
};

View File

@ -9,7 +9,7 @@
#pragma once
#include <etk/debug.hpp>
#include <vector>
#include <etk/Vector.hpp>
namespace etk {
/**

View File

@ -6,7 +6,7 @@
#include <etk/math/Quaternion.hpp>
std::ostream& etk::operator <<(std::ostream &_os, const etk::Quaternion& _obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::Quaternion& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";

View File

@ -434,20 +434,20 @@ namespace etk {
* @param _obj The other Vector to compare with
*/
void setMax(const Quaternion& _obj) {
std::max(m_floats[0], _obj.m_floats[0]);
std::max(m_floats[1], _obj.m_floats[1]);
std::max(m_floats[2], _obj.m_floats[2]);
std::max(m_floats[3], _obj.m_floats[3]);
etk::max(m_floats[0], _obj.m_floats[0]);
etk::max(m_floats[1], _obj.m_floats[1]);
etk::max(m_floats[2], _obj.m_floats[2]);
etk::max(m_floats[3], _obj.m_floats[3]);
}
/**
* @brief Set each element to the min of the current values and the values of another Vector
* @param _obj The other Vector to compare with
*/
void setMin(const Quaternion& _obj) {
std::min(m_floats[0], _obj.m_floats[0]);
std::min(m_floats[1], _obj.m_floats[1]);
std::min(m_floats[2], _obj.m_floats[2]);
std::min(m_floats[3], _obj.m_floats[3]);
etk::min(m_floats[0], _obj.m_floats[0]);
etk::min(m_floats[1], _obj.m_floats[1]);
etk::min(m_floats[2], _obj.m_floats[2]);
etk::min(m_floats[3], _obj.m_floats[3]);
}
/**
* @brief Set Value on the quaternion
@ -571,6 +571,6 @@ namespace etk {
void setEulerAngles(const vec3& _angles);
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Quaternion& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Quaternion& _obj);
}

View File

@ -8,7 +8,7 @@
#include <etk/stdTools.hpp>
#include <etk/debug.hpp>
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<int32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector2D<int32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -17,7 +17,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<int32_t>&
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<float>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector2D<float>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -26,7 +26,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<float>& _o
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<uint32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector2D<uint32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -35,7 +35,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<uint32_t>&
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<bool>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector2D<bool>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -44,7 +44,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector2D<bool>& _ob
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<vec2 >& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<vec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -54,7 +54,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<vec2 >& _obj
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<ivec2 >& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<ivec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -64,7 +64,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<ivec2 >& _ob
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<uivec2 >& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<uivec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -74,7 +74,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<uivec2 >& _o
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<bvec2 >& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<bvec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";

View File

@ -114,6 +114,22 @@ namespace etk {
return ( (ETK_TYPE)_obj.m_floats[0] != m_floats[0]
|| (ETK_TYPE)_obj.m_floats[1] != m_floats[1]);
}
bool operator<= (const Vector2D<ETK_TYPE>& _obj) const {
return ( m_floats[0] <= _obj.m_floats[0]
&& m_floats[1] <= _obj.m_floats[1]);
}
bool operator< (const Vector2D<ETK_TYPE>& _obj) const {
return ( m_floats[0] < _obj.m_floats[0]
&& m_floats[1] < _obj.m_floats[1]);
}
bool operator>= (const Vector2D<ETK_TYPE>& _obj) const {
return ( m_floats[0] >= _obj.m_floats[0]
&& m_floats[1] >= _obj.m_floats[1]);
}
bool operator> (const Vector2D<ETK_TYPE>& _obj) const {
return ( m_floats[0] > _obj.m_floats[0]
&& m_floats[1] > _obj.m_floats[1]);
}
/**
* @brief Operator+= Addition an other vertor with this one
* @param[in] _obj Reference on the external object
@ -497,16 +513,16 @@ namespace etk {
* @param _other The other vector to compare with
*/
void setMax(const Vector2D<ETK_TYPE>& _other) {
m_floats[0] = std::max(m_floats[0], _other.m_floats[0]);
m_floats[1] = std::max(m_floats[1], _other.m_floats[1]);
m_floats[0] = etk::max(m_floats[0], _other.m_floats[0]);
m_floats[1] = etk::max(m_floats[1], _other.m_floats[1]);
}
/**
* @brief Set each element to the min of the current values and the values of another vector
* @param _other The other vector to compare with
*/
void setMin(const Vector2D<ETK_TYPE>& _other) {
m_floats[0] = std::min(m_floats[0], _other.m_floats[0]);
m_floats[1] = std::min(m_floats[1], _other.m_floats[1]);
m_floats[0] = etk::min(m_floats[0], _other.m_floats[0]);
m_floats[1] = etk::min(m_floats[1], _other.m_floats[1]);
}
/**
* @brief Set Value on the vector
@ -557,13 +573,13 @@ namespace etk {
#endif
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector2D<int32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector2D<int32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector2D<float>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector2D<float>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector2D<uint32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector2D<uint32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector2D<bool>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector2D<bool>& _obj);
};
// To siplify the writing of the code ==> this permit to have the same name with the glsl language...
using vec2 = etk::Vector2D<float>;//!< wrapper on etk::Vector2D<float> to have the same naming has OpenGL shader
@ -600,13 +616,13 @@ vec2 vec2rotate(const vec2& _obj, const vec2& _point, float _angle);
namespace etk {
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<vec2 >& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<vec2 >& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<ivec2 >& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<ivec2 >& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<uivec2 >& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<uivec2 >& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<bvec2 >& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<bvec2 >& _obj);
}
template<class ETK_TYPE>

View File

@ -8,7 +8,7 @@
#include <etk/stdTools.hpp>
#include <etk/debug.hpp>
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<int32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector3D<int32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -20,7 +20,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<int32_t>&
}
#ifdef ETK_BUILD_LINEARMATH
std::ostream& operator <<(std::ostream& _os, const btVector3& _obj) {
etk::Stream& operator <<(etk::Stream& _os, const btVector3& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -32,7 +32,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<int32_t>&
}
#endif
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<float>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector3D<float>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -43,7 +43,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<float>& _o
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<uint32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector3D<uint32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -54,7 +54,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<uint32_t>&
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<bool>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector3D<bool>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -68,7 +68,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<bool>& _ob
#ifdef ETK_BUILD_LINEARMATH
std::ostream& operator <<(std::ostream& _os, const std::vector<btVector3>& _obj) {
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<btVector3>& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -79,7 +79,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const etk::Vector3D<bool>& _ob
}
#endif
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3D<float>>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<float>>& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -89,7 +89,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3D<int32_t>>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<int32_t>>& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -99,7 +99,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3D<uint32_t>>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<uint32_t>>& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
@ -109,7 +109,7 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3
return _os;
}
std::ostream& etk::operator <<(std::ostream& _os, const std::vector<etk::Vector3D<bool>>& _obj) {
etk::Stream& etk::operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<bool>>& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";

View File

@ -481,32 +481,32 @@ namespace etk {
* @param _obj The other Vector3D<T> to compare with
*/
void setMax(const Vector3D<T>& _obj) {
m_floats[0] = std::max(m_floats[0], _obj.m_floats[0]);
m_floats[1] = std::max(m_floats[1], _obj.m_floats[1]);
m_floats[2] = std::max(m_floats[2], _obj.m_floats[2]);
m_floats[0] = etk::max(m_floats[0], _obj.m_floats[0]);
m_floats[1] = etk::max(m_floats[1], _obj.m_floats[1]);
m_floats[2] = etk::max(m_floats[2], _obj.m_floats[2]);
}
/**
* @brief Set each element to the min of the current values and the values of another Vector3D<T>
* @param _obj The other Vector3D<T> to compare with
*/
void setMin(const Vector3D<T>& _obj) {
m_floats[0] = std::min(m_floats[0], _obj.m_floats[0]);
m_floats[1] = std::min(m_floats[1], _obj.m_floats[1]);
m_floats[2] = std::min(m_floats[2], _obj.m_floats[2]);
m_floats[0] = etk::min(m_floats[0], _obj.m_floats[0]);
m_floats[1] = etk::min(m_floats[1], _obj.m_floats[1]);
m_floats[2] = etk::min(m_floats[2], _obj.m_floats[2]);
}
/**
* @brief Get the minimum value of the vector (x, y, z)
* @return The min value
*/
T getMin() const {
return std::min(std::min(m_floats[0], m_floats[1]), m_floats[2]);
return etk::min(etk::min(m_floats[0], m_floats[1]), m_floats[2]);
}
/**
* @brief Get the maximum value of the vector (x, y, z)
* @return The max value
*/
T getMax() const {
return std::max(std::max(m_floats[0], m_floats[1]), m_floats[2]);
return etk::max(etk::max(m_floats[0], m_floats[1]), m_floats[2]);
}
/**
* @brief Set Value on the vector
@ -581,21 +581,21 @@ namespace etk {
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector3D<float>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector3D<float>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector3D<int32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector3D<int32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector3D<uint32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector3D<uint32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector3D<bool>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector3D<bool>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<etk::Vector3D<float>>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<float>>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<etk::Vector3D<int32_t>>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<int32_t>>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<etk::Vector3D<uint32_t>>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<uint32_t>>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<etk::Vector3D<bool>>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<etk::Vector3D<bool>>& _obj);
}
// To siplify the writing of the code ==> this permit to have the same name with the glsl language...
@ -611,8 +611,8 @@ using uivec3 = etk::Vector3D<uint32_t>; //!< wrapper on etk::Vector3D<uint32_t>
using bvec3 = etk::Vector3D<bool>; //!< wrapper on etk::Vector3D<bool> to have the same naming has OpenGL shader
#ifdef ETK_BUILD_LINEARMATH
std::ostream& operator <<(std::ostream& _os, const btVector3& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<btVector3>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const btVector3& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<btVector3>& _obj);
vec3 quaternionToEulerXYZ(const btQuaternion& quat);
#endif
@ -635,21 +635,21 @@ inline vec3 vec3ClipInt64(const vec3& _val) {
#ifdef ETK_BUILD_LINEARMATH
namespace etk {
inline btVector3 min(const btVector3& _val1, const btVector3& _val2) {
return btVector3(std::min(_val1.x(), _val2.x()), std::min(_val1.y(), _val2.y()), std::min(_val1.z(), _val2.z()));
return btVector3(etk::min(_val1.x(), _val2.x()), etk::min(_val1.y(), _val2.y()), etk::min(_val1.z(), _val2.z()));
}
inline btVector3 max(const btVector3& _val1, const btVector3& _val2) {
return btVector3(std::max(_val1.x(), _val2.x()), std::max(_val1.y(), _val2.y()), std::max(_val1.z(), _val2.z()));
return btVector3(etk::max(_val1.x(), _val2.x()), etk::max(_val1.y(), _val2.y()), etk::max(_val1.z(), _val2.z()));
}
}
#endif
namespace etk {
template<class ETK_TYPE>
inline etk::Vector3D<ETK_TYPE> min(const etk::Vector3D<ETK_TYPE>& _val1, const etk::Vector3D<ETK_TYPE>& _val2) {
return etk::Vector3D<ETK_TYPE>(std::min(_val1.x(), _val2.x()), std::min(_val1.y(), _val2.y()), std::min(_val1.z(), _val2.z()));
return etk::Vector3D<ETK_TYPE>(etk::min(_val1.x(), _val2.x()), etk::min(_val1.y(), _val2.y()), etk::min(_val1.z(), _val2.z()));
}
template<class ETK_TYPE>
inline etk::Vector3D<ETK_TYPE> max(const etk::Vector3D<ETK_TYPE>& _val1, const etk::Vector3D<ETK_TYPE>& _val2) {
return etk::Vector3D<ETK_TYPE>(std::max(_val1.x(), _val2.x()), std::max(_val1.y(), _val2.y()), std::max(_val1.z(), _val2.z()));
return etk::Vector3D<ETK_TYPE>(etk::max(_val1.x(), _val2.x()), etk::max(_val1.y(), _val2.y()), etk::max(_val1.z(), _val2.z()));
}
}

View File

@ -6,7 +6,7 @@
#include <etk/math/Vector4D.hpp>
std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<int32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::Vector4D<int32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -19,7 +19,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<int32_t>&
return _os;
}
std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<float>& _obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::Vector4D<float>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -32,7 +32,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<float>& _o
return _os;
}
std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<uint32_t>& _obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::Vector4D<uint32_t>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";
@ -45,7 +45,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<uint32_t>&
return _os;
}
std::ostream& etk::operator <<(std::ostream &_os, const etk::Vector4D<bool>& _obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::Vector4D<bool>& _obj) {
_os << "(";
_os << _obj.x();
_os << ",";

View File

@ -421,13 +421,13 @@ namespace etk {
}
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector4D<int32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector4D<int32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector4D<float>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector4D<float>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector4D<uint32_t>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector4D<uint32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector4D<bool>& _obj);
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector4D<bool>& _obj);
}
// To siplify the writing of the code ==> this permit to have the same name with the glsl language...

1
etk/move.hpp Normal file
View File

@ -0,0 +1 @@
https://stackoverflow.com/questions/7510182/how-does-stdmove-transfer-values-into-rvalues

View File

@ -11,7 +11,7 @@
#include <cstdlib>
#include <etk/tool.hpp>
#include <etk/debug.hpp>
#include <map>
#include <etk/Map.hpp>
#include <mutex>
#ifdef __TARGET_OS__Windows
#include <tchar.h>
@ -1510,7 +1510,7 @@ bool etk::FSNode::operator!= (const etk::FSNode& _obj ) const {
return !(*this == _obj);
}
std::ostream& etk::operator <<(std::ostream &_os, const etk::FSNode &_obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::FSNode &_obj) {
if (_obj.m_libSearch.size() != 0) {
_os << "{" << _obj.m_libSearch << "}";
}
@ -1518,7 +1518,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::FSNode &_obj) {
return _os;
}
std::ostream& etk::operator <<(std::ostream &_os, const enum etk::FSNType &_obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const enum etk::FSNType &_obj) {
switch (_obj)
{
case etk::FSNType_unknow:
@ -1555,7 +1555,7 @@ std::ostream& etk::operator <<(std::ostream &_os, const enum etk::FSNType &_obj)
return _os;
}
std::ostream& etk::operator <<(std::ostream &_os, const enum etk::typeNode &_obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const enum etk::typeNode &_obj) {
switch (_obj) {
case etk::typeNode_unknow:
_os << "typeNode_unknow";
@ -2203,14 +2203,13 @@ int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _
return fwrite(_data, _blockSize, _nbBlock, m_PointerFile);
}
/*
etk::FSNode& etk::FSNode::operator<< (const std::ostream& _data) {
etk::FSNode& etk::FSNode::operator<< (const etk::Stream& _data) {
fileWrite(_data.str().c_str(), 1, _data.str().size());
return *this;
}
*/
etk::FSNode& etk::FSNode::operator<< (const std::stringstream& _data) {
etk::String sss = _data.str();
fileWrite(sss.c_str(), 1, sss.size());
etk::FSNode& etk::FSNode::operator<< (const etk::Stream& _data) {
fileWrite(_data.c_str(), 1, _data.size());
return *this;
}
etk::FSNode& etk::FSNode::operator<< (const etk::String& _data) {
@ -2222,23 +2221,17 @@ etk::FSNode& etk::FSNode::operator<< (const char* _data) {
return *this;
}
etk::FSNode& etk::FSNode::operator<< (const int32_t _data) {
std::stringstream tmp;
tmp << _data;
etk::String sss = tmp.str();
etk::String sss = etk::toString(_data);
fileWrite(sss.c_str(), 1, sss.size());
return *this;
}
etk::FSNode& etk::FSNode::operator<< (const uint32_t _data) {
std::stringstream tmp;
tmp << _data;
etk::String sss = tmp.str();
etk::String sss = etk::toString(_data);
fileWrite(sss.c_str(), 1, sss.size());
return *this;
}
etk::FSNode& etk::FSNode::operator<< (const float _data) {
std::stringstream tmp;
tmp << _data;
etk::String sss = tmp.str();
etk::String sss = etk::toString(_data);
fileWrite(sss.c_str(), 1, sss.size());
return *this;
}
@ -2320,20 +2313,20 @@ void etk::FSNode::fileFlush() {
// TODO : Add an INIT to reset all allocated parameter :
static std::map<etk::String, etk::String> g_listTheme;
static etk::Map<etk::String, etk::String> g_listTheme;
void etk::theme::setName(const etk::String& _refName, const etk::String& _folderName) {
TK_WARNING("Change theme : '" << _refName << "' : '" << _folderName << "'");
#if __CPP_VERSION__ >= 2011
auto it = g_listTheme.find(_refName);
#else
std::map<etk::String, etk::String>::iterator it = g_listTheme.find(_refName);
etk::Map<etk::String, etk::String>::iterator it = g_listTheme.find(_refName);
#endif
if (it != g_listTheme.end()) {
it->second = _folderName;
return;
}
g_listTheme.insert(std::pair<etk::String,etk::String>(_refName, _folderName));
g_listTheme.insert(etk::Pair<etk::String,etk::String>(_refName, _folderName));
}
#if __CPP_VERSION__ >= 2011
void etk::theme::setName(const etk::UString& _refName, const etk::UString& _folderName) {
@ -2345,7 +2338,7 @@ etk::String etk::theme::getName(const etk::String& _refName) {
#if __CPP_VERSION__ >= 2011
auto it = g_listTheme.find(_refName);
#else
std::map<etk::String, etk::String>::iterator it = g_listTheme.find(_refName);
etk::Map<etk::String, etk::String>::iterator it = g_listTheme.find(_refName);
#endif
if (it != g_listTheme.end()) {
return it->second;
@ -2366,7 +2359,7 @@ etk::Vector<etk::String> etk::theme::list() {
keys.pushBack(it.first);
}
#else
for (std::map<etk::String, etk::String>::iterator it(g_listTheme.begin()); it != g_listTheme.end(); ++it) {
for (etk::Map<etk::String, etk::String>::iterator it(g_listTheme.begin()); it != g_listTheme.end(); ++it) {
keys.pushBack(it->first);
}
#endif
@ -2382,18 +2375,18 @@ etk::Vector<etk::String> etk::theme::list() {
}
#endif
static std::map<etk::String, etk::String> g_listThemeDefault;
static etk::Map<etk::String, etk::String> g_listThemeDefault;
void etk::theme::setNameDefault(const etk::String& _refName, const etk::String& _folderName) {
#if __CPP_VERSION__ >= 2011
auto it = g_listThemeDefault.find(_refName);
#else
std::map<etk::String, etk::String>::iterator it = g_listThemeDefault.find(_refName);
etk::Map<etk::String, etk::String>::iterator it = g_listThemeDefault.find(_refName);
#endif
if (it != g_listThemeDefault.end()) {
it->second = _folderName;
return;
}
g_listThemeDefault.insert(std::pair<etk::String,etk::String>(_refName, _folderName));
g_listThemeDefault.insert(etk::Pair<etk::String,etk::String>(_refName, _folderName));
}
#if __CPP_VERSION__ >= 2011
void etk::theme::setNameDefault(const etk::UString& _refName, const etk::UString& _folderName) {
@ -2405,7 +2398,7 @@ etk::String etk::theme::getNameDefault(const etk::String& _refName) {
#if __CPP_VERSION__ >= 2011
auto it=g_listThemeDefault.find(_refName);
#else
std::map<etk::String, etk::String>::iterator it = g_listThemeDefault.find(_refName);
etk::Map<etk::String, etk::String>::iterator it = g_listThemeDefault.find(_refName);
#endif
if (it != g_listThemeDefault.end()) {
return it->second;

View File

@ -77,7 +77,7 @@ namespace etk {
typeNode_socket, //!< The node is a socket
};
//! @not_in_doc
std::ostream& operator <<(std::ostream &_os, const enum etk::typeNode &_obj);
etk::Stream& operator <<(etk::Stream &_os, const enum etk::typeNode &_obj);
/**
* @brief Seek mode availlable (just to wrap it ...)
*/
@ -129,7 +129,7 @@ namespace etk {
FSNType_themeData //!< Theme data area
};
//! @not_in_doc
std::ostream& operator <<(std::ostream &_os, const enum etk::FSNType &_obj);
etk::Stream& operator <<(etk::Stream &_os, const enum etk::FSNType &_obj);
/*
note : The filename can be
@ -407,7 +407,7 @@ namespace etk {
* @param[in] _obj Node to display
* @return std debug IO
*/
friend std::ostream& operator <<( std::ostream &_os,const etk::FSNode &_obj);
friend etk::Stream& operator <<( etk::Stream &_os,const etk::FSNode &_obj);
/**
* @brief Count the number of subFolder in the curent Folder
@ -561,14 +561,14 @@ namespace etk {
* @return Number of element written (in block number)
*/
int64_t fileWrite(const void* _data, int64_t _blockSize, int64_t _nbBlock);
// TODO: etk::FSNode& operator<< (const std::ostream& _data);
// TODO: etk::FSNode& operator<< (const etk::Stream& _data);
/**
* @brief Stream write mode
* @param[in] _data Stream to write
* @return The current FSNode reference to add other stream.
* @note not stable API ...
*/
etk::FSNode& operator<< (const std::stringstream& _data);
etk::FSNode& operator<< (const etk::Stream& _data);
//! @copydoc etk::FSNode::operator<<(const etk::Stringstream&)
etk::FSNode& operator<< (const etk::String& _data);
//! @copydoc etk::FSNode::operator<<(const etk::Stringstream&)
@ -649,7 +649,7 @@ namespace etk {
void sortElementList(etk::Vector<etk::FSNode *>& _list);
};
//! @not_in_doc
std::ostream& operator <<(std::ostream &_os, const etk::FSNode &_obj);
etk::Stream& operator <<(etk::Stream &_os, const etk::FSNode &_obj);
/**
* @brief Set manualy the folder of the Data.(like /usr/shared/applName/ for linux)

View File

@ -204,7 +204,7 @@ etk::String etk::FSNodeRight::getRight() const {
}
std::ostream& etk::operator <<(std::ostream &_os, const etk::FSNodeRight &_obj) {
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::FSNodeRight &_obj) {
_os << _obj.getRight();
return _os;
};

View File

@ -153,7 +153,7 @@ namespace etk {
etk::String getRight() const;
};
//! @not_in_doc
std::ostream& operator <<(std::ostream &_os, const etk::FSNodeRight &_obj);
etk::Stream& operator <<(etk::Stream &_os, const etk::FSNodeRight &_obj);
}

View File

@ -9,7 +9,7 @@
#pragma once
#include <mutex>
#include <vector>
#include <etk/Vector.hpp>
#include <condition_variable>
namespace etk {
@ -22,7 +22,7 @@ namespace etk {
private :
std::mutex m_mutex; //!< protection of the internal data.
std::condition_variable m_condition; //!< Message system to send event on an other thread.
std::vector<MY_TYPE> m_data; //!< List of all message to send
etk::Vector<MY_TYPE> m_data; //!< List of all message to send
public :
/**
* @brief Create a fifo with no message.
@ -98,7 +98,7 @@ namespace etk {
*/
void post(MY_TYPE &_data) {
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push_back(_data);
m_data.pushBack(_data);
m_condition.notify_all();
};
/**
@ -107,7 +107,7 @@ namespace etk {
*/
void post(const MY_TYPE &_data) {
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push_back(_data);
m_data.pushBack(_data);
m_condition.notify_all();
};
/**

View File

@ -1,480 +1,8 @@
namespace etk {
#if __CPP_VERSION__ >= 2011
template<> etk::String toString<etk::UString>(const etk::UString& _input) {
etk::String out;
for (size_t iii=0; iii<_input.size(); ++iii) {
char output[10];
u32char::convertUtf8(_input[iii], output);
out += output;
}
return out;
}
template<> etk::String toString<char32_t>(const char32_t& _input) {
etk::String out;
char output[10];
u32char::convertUtf8(_input, output);
out += output;
return out;
}
#endif
};
#if __CPP_VERSION__ >= 2011
static etk::UString transform_toUString(const char* _input) {
if (_input == nullptr) {
return U"";
}
etk::UString 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 out;
}
#endif
#if __CPP_VERSION__ >= 2011
namespace etk {
template<> etk::UString toUString<char*>(char* const & _input) {
return transform_toUString(_input);
}
template<> etk::UString toUString<etk::String>(const etk::String& _input) {
return transform_toUString(_input.c_str());
}
template<> etk::UString toUString<int8_t>(const int8_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<int16_t>(const int16_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<int32_t>(const int32_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<int64_t>(const int64_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<uint8_t>(const uint8_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<uint16_t>(const uint16_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<uint32_t>(const uint32_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<uint64_t>(const uint64_t& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<float>(const float& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<double>(const double& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<long double>(const long double& _val) {
return etk::toUString(etk::toString(_val));
};
template<> etk::UString toUString<bool>(const bool& _val) {
if (_val == true) {
return U"true";
}
return U"false";
}
};
bool etk::string_to_bool(const etk::UString& _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;
}
double etk::string_to_double(const etk::UString& _str) {
return etk::string_to_double(etk::toString(_str));
}
long double etk::string_to_long_double(const etk::UString& _str) {
return etk::string_to_long_double(etk::toString(_str));
}
float etk::string_to_float(const etk::UString& _str) {
return etk::string_to_float(etk::toString(_str));
}
int8_t etk::string_to_int8_t(const etk::UString& _str) {
return etk::string_to_int8_t(etk::toString(_str));
}
int16_t etk::string_to_int16_t(const etk::UString& _str) {
return etk::string_to_int16_t(etk::toString(_str));
}
int32_t etk::string_to_int32_t(const etk::UString& _str) {
return etk::string_to_int32_t(etk::toString(_str));
}
int64_t etk::string_to_int64_t(const etk::UString& _str) {
return etk::string_to_int64_t(etk::toString(_str));
}
uint8_t etk::string_to_uint8_t(const etk::UString& _str) {
return etk::string_to_uint8_t(etk::toString(_str));
}
uint16_t etk::string_to_uint16_t(const etk::UString& _str) {
return etk::string_to_uint16_t(etk::toString(_str));
}
uint32_t etk::string_to_uint32_t(const etk::UString& _str) {
return etk::string_to_uint32_t(etk::toString(_str));
}
uint64_t etk::string_to_uint64_t(const etk::UString& _str) {
return etk::string_to_uint64_t(etk::toString(_str));
}
#endif
#if __CPP_VERSION__ >= 2011
bool etk::compare_no_case(const etk::UString& _obj, const etk::UString& _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;
}
#endif
class DoubleChar {
public:
char32_t lower;
char32_t upper;
};
DoubleChar conversionTable[] = {
#if __CPP_VERSION__ >= 2011
{U'ç', U'Ç'},
{U'á', U'Á'}, {U'à', U'À'}, {U'ä', U'Ä'}, {U'â', U'Â'}, {U'å', U'Å'}, {U'ã', U'Ã'},
{U'é', U'É'}, {U'è', U'È'}, {U'ë', U'Ë'}, {U'ê', U'Ê'},
{U'ú', U'Ú'}, {U'ù', U'Ù'}, {U'ü', U'Ü'}, {U'û', U'Û'},
{U'í', U'Í'}, {U'ì', U'Ì'}, {U'ï', U'Ï'}, {U'î', U'Î'},
{U'ó', U'Ó'}, {U'ò', U'Ò'}, {U'ö', U'Ö'}, {U'ô', U'Ô'}, {U'õ', U'Õ'},
{U'ý', U'Ý'}, {U'', U''}, {U'ÿ', U'Ÿ'}, {U'ŷ', U'Ŷ'},
{U'ñ', U'Ñ'}, {U'ǹ', U'Ǹ'},
{U'', U''}, {U'ĥ', U'Ĥ'},
{U'', U''}, {U'ŵ', U'Ŵ'}, {U'', U''},
{U'', U''},
{U'æ', U'Æ'},
{U'ð', U'Ð'},
{U'ø', U'Ø'}
#endif
};
size_t conversionTableSize = sizeof(conversionTable)/sizeof(DoubleChar);
static char32_t localToUpper(char32_t _input) {
if (_input >= 'a' && _input <= 'z') {
return _input + ((int)'A'-(int)'a');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].lower == _input) {
return conversionTable[iii].upper;
}
}
return _input;
}
static char32_t localToLower(char32_t _input) {
if (_input >= 'A' && _input <= 'Z') {
return _input + ((int)'a'-(int)'A');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].upper == _input) {
return conversionTable[iii].lower;
}
}
return _input;
}
#if __CPP_VERSION__ >= 2011
etk::UString etk::tolower(etk::UString _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = localToLower(_obj[iii]);
}
return _obj;
}
#endif
#if __CPP_VERSION__ >= 2011
etk::UString etk::toupper(etk::UString _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = localToUpper(_obj[iii]);
}
return _obj;
}
#endif
#if __CPP_VERSION__ >= 2011
bool etk::end_with(const etk::UString& _obj, const etk::UString& _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 (std::tolower(_val[iii]) != std::tolower(_obj[jjj])) {
return false;
}
}
return true;
}
#endif
#if __CPP_VERSION__ >= 2011
bool etk::start_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive) {
if (_val.size() == 0) {
return false;
}
if (_val.size() > _obj.size()) {
return false;
}
if (_caseSensitive == true) {
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 (std::tolower(_val[iii]) != std::tolower(_obj[iii])) {
return false;
}
}
return true;
}
etk::UString etk::replace(const etk::UString& _obj, char32_t _val, char32_t _replace) {
etk::UString copy(_obj);
for( size_t iii = 0;
iii < copy.size();
iii++) {
if (copy[iii] == _val) {
copy[iii] = _replace;
}
}
return copy;
}
#endif
#if __CPP_VERSION__ >= 2011
etk::UString etk::extract_line(const etk::UString& _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 == etk::String::npos) {
startPos = 0;
} else if (startPos >= _obj.size() ) {
return U"";
}
if (stopPos == etk::String::npos) {
return U"";
} else if (stopPos >= _obj.size() ) {
stopPos = _obj.size();
}
return etk::UString(_obj, startPos, stopPos - startPos);
}
#endif
#if __CPP_VERSION__ >= 2011
etk::Vector<etk::UString> etk::split(const etk::UString& _input, char32_t _val) {
etk::Vector<etk::UString> list;
size_t lastStartPos = 0;
for(size_t iii=0; iii<_input.size(); iii++) {
if (_input[iii]==_val) {
list.pushBack(etk::UString(_input, lastStartPos, iii - lastStartPos));
lastStartPos = iii+1;
}
}
if (lastStartPos<_input.size()) {
list.pushBack(etk::UString(_input, lastStartPos));
}
return list;
}
#endif
#if __CPP_VERSION__ >= 2011
void etk::sort(etk::Vector<etk::UString *> &_list) {
etk::Vector<etk::UString *> tmpList(_list);
_list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) {
size_t findPos = 0;
for(size_t jjj=0; jjj<_list.size(); jjj++) {
//TK_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (*tmpList[iii] > *_list[jjj]) {
findPos = jjj+1;
}
}
//TK_DEBUG("position="<<findPos);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
#endif
namespace etk {
#if __CPP_VERSION__ >= 2011
template<> bool from_string<etk::UString>(etk::UString& _variableRet, const etk::String& _value) {
_variableRet = etk::toUString(_value);
return true;
}
template<> bool from_string<int8_t>(int8_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int8_t(_value);
return true;
}
template<> bool from_string<int16_t>(int16_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int16_t(_value);
return true;
}
template<> bool from_string<int32_t>(int32_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int32_t(_value);
return true;
}
template<> bool from_string<int64_t>(int64_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int64_t(_value);
return true;
}
template<> bool from_string<uint8_t>(uint8_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint8_t(_value);
return true;
}
template<> bool from_string<uint16_t>(uint16_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint16_t(_value);
return true;
}
template<> bool from_string<uint32_t>(uint32_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint32_t(_value);
return true;
}
template<> bool from_string<uint64_t>(uint64_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint64_t(_value);
return true;
}
template<> bool from_string<float>(float& _variableRet, const etk::UString& _value) {
_variableRet = string_to_float(_value);
return true;
}
template<> bool from_string<double>(double& _variableRet, const etk::UString& _value) {
_variableRet = string_to_double(_value);
return true;
}
template<> bool from_string<long double>(long double& _variableRet, const etk::UString& _value) {
_variableRet = string_to_long_double(_value);
return true;
}
template<> bool from_string<bool>(bool& _variableRet, const etk::UString& _value) {
_variableRet = string_to_bool(_value);
return true;
}
#endif
};
#if __CPP_VERSION__ >= 2011
std::ostream& std::operator <<(std::ostream& _os, const etk::UString& _obj) {
_os << etk::toString(_obj).c_str();
return _os;
}
std::ostream& std::operator <<(std::ostream& _os, const etk::Vector<etk::UString>& _obj) {
_os << "{";
for (size_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) {
_os << " ~ ";
}
_os << _obj[iii];
}
_os << "}";
return _os;
}
#endif
#include <etk/stdTools.hpp>
namespace std {
std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
etk::Stream& operator <<(etk::Stream& _os, const std::chrono::system_clock::time_point& _obj) {
std::chrono::nanoseconds ns = std::chrono::duration_cast<std::chrono::nanoseconds>(_obj.time_since_epoch());
int64_t totalSecond = ns.count()/1000000000;
int64_t millisecond = (ns.count()%1000000000)/1000000;
@ -489,7 +17,7 @@ namespace std {
_os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns";
return _os;
}
std::ostream& operator <<(std::ostream& _os, const std::chrono::steady_clock::time_point& _obj) {
etk::Stream& operator <<(etk::Stream& _os, const std::chrono::steady_clock::time_point& _obj) {
std::chrono::nanoseconds ns = std::chrono::duration_cast<std::chrono::nanoseconds>(_obj.time_since_epoch());
int64_t totalSecond = ns.count()/1000000000;
int64_t millisecond = (ns.count()%1000000000)/1000000;

View File

@ -2,46 +2,11 @@
#pragma once
#include <etk/types.hpp>
#include <etk/Vector.hpp>
#include <etk/Stream.hpp>
#include <chrono>
namespace etk {
template<class ETK_ITERATOR_TYPE>
size_t distance(const ETK_ITERATOR_TYPE& _start, const ETK_ITERATOR_TYPE& _stop) {
size_t out = 0;
ETK_ITERATOR_TYPE tmp = _start;
while (tmp != _stop) {
out++;
++tmp;
}
return out;
}
}
namespace std {
etk::Stream& operator <<(etk::Stream& _os, const std::chrono::system_clock::time_point& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<float>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<double>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<int64_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint64_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<int32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint32_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<int16_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint16_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<int8_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint8_t>& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::chrono::steady_clock::time_point& _obj);
}
etk::Stream& operator <<(etk::Stream& _os, const std::chrono::steady_clock::time_point& _obj);
}

View File

@ -4,9 +4,6 @@
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stdarg.h>
@ -84,6 +81,54 @@ namespace etk {
* @return Value that min/max applied
*/
template <class TYPE> const TYPE& avg(const TYPE& _min, const TYPE& _val, const TYPE& _max) {
return std::min(std::max(_min,_val),_max);
return etk::min(etk::max(_min,_val),_max);
}
};
};
namespace etk {
template<class ETK_ITERATOR_TYPE>
size_t distance(const ETK_ITERATOR_TYPE& _start, const ETK_ITERATOR_TYPE& _stop) {
size_t out = 0;
ETK_ITERATOR_TYPE tmp = _start;
while (tmp != _stop) {
out++;
++tmp;
}
return out;
}
template<class ETK_MOVE_TYPE>
struct _Remove_reference {
// remove reference
typedef ETK_MOVE_TYPE m_type;
};
template<class ETK_MOVE_TYPE>
struct _Remove_reference<ETK_MOVE_TYPE&> {
// remove reference
typedef ETK_MOVE_TYPE m_type;
};
template<class ETK_MOVE_TYPE>
struct _Remove_reference<ETK_MOVE_TYPE&&> {
// remove rvalue reference
typedef ETK_MOVE_TYPE m_type;
};
template<class ETK_MOVE_TYPE> inline
typename etk::_Remove_reference<ETK_MOVE_TYPE>::m_type&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return ((typename etk::_Remove_reference<ETK_MOVE_TYPE>::m_type&&)_obj);
}
/*
template<class ETK_MOVE_TYPE>
eETK_MOVE_TYPE&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return ((ETK_MOVE_TYPE&&)_obj);
}
*/
}
#include <etk/Stream.hpp>

View File

@ -4,9 +4,10 @@
* @license MPL v2.0 (see license file)
*/
#include <etk/stdTools.hpp>
#include <etk/debug.hpp>
#include <etk/utf8.hpp>
//#include <etk/debug.hpp>
#include <etk/String.hpp>
#include <etk/UString.hpp>
@ -128,16 +129,77 @@ int8_t u32char::convertUtf8(char32_t _val, char _output[5]) {
return 4;
}
}
#if __CPP_VERSION__ >= 2011
etk::String u32char::convertToUtf8(const etk::UString& _input) {
TK_TODO("implement this function ...");
return "TODO ... etk::String u32char::convertToUtf8(const etk::UString& _input)";
etk::String u32char::convertToUtf8(const etk::UString& _input) {
return etk::toString(_input);
}
size_t u32char::strlen(const char32_t* _input) {
uint32_t out = 0;
while (_input != 0) {
out++;
_input++;
}
#endif
return out;
}
class DoubleChar {
public:
char32_t lower;
char32_t upper;
};
DoubleChar conversionTable[] = {
{U'ç', U'Ç'},
{U'á', U'Á'}, {U'à', U'À'}, {U'ä', U'Ä'}, {U'â', U'Â'}, {U'å', U'Å'}, {U'ã', U'Ã'},
{U'é', U'É'}, {U'è', U'È'}, {U'ë', U'Ë'}, {U'ê', U'Ê'},
{U'ú', U'Ú'}, {U'ù', U'Ù'}, {U'ü', U'Ü'}, {U'û', U'Û'},
{U'í', U'Í'}, {U'ì', U'Ì'}, {U'ï', U'Ï'}, {U'î', U'Î'},
{U'ó', U'Ó'}, {U'ò', U'Ò'}, {U'ö', U'Ö'}, {U'ô', U'Ô'}, {U'õ', U'Õ'},
{U'ý', U'Ý'}, {U'', U''}, {U'ÿ', U'Ÿ'}, {U'ŷ', U'Ŷ'},
{U'ñ', U'Ñ'}, {U'ǹ', U'Ǹ'},
{U'', U''}, {U'ĥ', U'Ĥ'},
{U'', U''}, {U'ŵ', U'Ŵ'}, {U'', U''},
{U'', U''},
{U'æ', U'Æ'},
{U'ð', U'Ð'},
{U'ø', U'Ø'}
};
size_t conversionTableSize = sizeof(conversionTable)/sizeof(DoubleChar);
char32_t u32char::toUpper(char32_t _input) {
if (_input >= 'a' && _input <= 'z') {
return _input + ((int)'A'-(int)'a');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].lower == _input) {
return conversionTable[iii].upper;
}
}
return _input;
}
char32_t u32char::toLower(char32_t _input) {
if (_input >= 'A' && _input <= 'Z') {
return _input + ((int)'a'-(int)'A');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].upper == _input) {
return conversionTable[iii].lower;
}
}
return _input;
}
static uint8_t sizeElement(const char* _data, int32_t _lenMax) {
uint8_t size = 0;
TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
//TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
if (0 > _lenMax) {
return 0;
}
@ -225,9 +287,59 @@ bool utf8::first(const char _input) {
}
return false;
}
#if __CPP_VERSION__ >= 2011
etk::UString utf8::convertUnicode(const etk::String& _input) {
TK_TODO("implement this function ...");
return U"TODO ... etk::UString utf8::convertUnicode(const etk::String& _input)";
etk::UString utf8::convertUnicode(const char* _input) {
if (_input == nullptr) {
return U"";
}
#endif
etk::UString 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 out;
}
etk::UString utf8::convertUnicode(const etk::String& _input) {
return utf8::convertUnicode(_input.c_str());
}

View File

@ -74,6 +74,9 @@ namespace u32char {
#if __CPP_VERSION__ >= 2011
etk::String convertToUtf8(const etk::UString& _input);
#endif
char32_t toUpper(char32_t _input);
char32_t toLower(char32_t _input);
size_t strlen(const char32_t* _input);
};
/**
@ -98,9 +101,8 @@ namespace utf8 {
* @return Converted Value
*/
char32_t convertChar32(const char* _input);
#if __CPP_VERSION__ >= 2011
etk::UString convertUnicode(const etk::String& _input);
#endif
etk::UString convertUnicode(const char* _input);
etk::UString convertUnicode(const etk::String& _input);
/**
* @brief Iterator on a simple etk::String that contain utf8 value
*/

65
lutin_etk-base.py Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/python
import lutin.debug as debug
import lutin.tools as tools
def get_type():
return "LIBRARY"
def get_desc():
return "Ewol tool kit (base: container)"
def get_licence():
return "MPL-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return "authors.txt"
def get_version():
return "version.txt"
def configure(target, my_module):
my_module.add_extra_flags()
# add the file to compile:
my_module.add_src_file([
'etk/String.cpp',
'etk/UString.cpp',
'etk/utf8.cpp',
'etk/stdTools.cpp',
'etk/Stream.cpp',
])
my_module.add_header_file([
'etk/types.hpp',
'etk/stdTools.hpp',
'etk/Buffer.hpp',
'etk/Hash.hpp',
'etk/String.hpp',
'etk/UString.hpp',
'etk/utf8.hpp',
'etk/Vector.hpp',
'etk/Stream.hpp',
'etk/Pair.hpp',
'etk/Map.hpp',
])
# build in C++ mode
my_module.compile_version("c++", 2011)
# add dependency of the generic C++ library:
my_module.add_depend([
'c',
])
if "Android" in target.get_type():
my_module.add_depend("SDK")
my_module.add_path(".")
return True

View File

@ -29,11 +29,7 @@ def configure(target, my_module):
# add the file to compile:
my_module.add_src_file([
'etk/debug.cpp',
'etk/String.cpp',
'etk/UString.cpp',
'etk/utf8.cpp',
'etk/etk.cpp',
'etk/stdTools.cpp',
'etk/tool.cpp',
'etk/Noise.cpp',
'etk/Color.cpp',
@ -55,18 +51,11 @@ def configure(target, my_module):
my_module.add_header_file([
'etk/etk.hpp',
'etk/debug.hpp',
'etk/types.hpp',
'etk/stdTools.hpp',
'etk/tool.hpp',
'etk/Noise.hpp',
'etk/Color.hpp',
'etk/RegEx.hpp',
'etk/Buffer.hpp',
'etk/Hash.hpp',
'etk/String.hpp',
'etk/UString.hpp',
'etk/utf8.hpp',
'etk/Vector.hpp',
'etk/math/Matrix2x2.hpp',
'etk/math/Matrix2x3.hpp',
'etk/math/Matrix3x3.hpp',
@ -89,7 +78,8 @@ def configure(target, my_module):
'c',
'm',
'elog',
'ememory'
'ememory',
'etk-base',
])
# add some optionnal libraries
my_module.add_optionnal_depend('minizip', ["c++", "-DETK_BUILD_MINIZIP"])

View File

@ -6,11 +6,11 @@
#include <etk/types.hpp>
#include <test-debug/debug.hpp>
#include <vector>
#include <string>
#include <etk/Vector.hpp>
#include <etk/String.hpp>
#include <etk/etk.hpp>
#include <etk/stdTools.hpp>
#include <string>
#include <etk/String.hpp>
#include <etk/os/FSNode.hpp>
#include <gtest/gtest.h>

View File

@ -12,7 +12,7 @@
#define NAME "FSNode"
TEST(TestEtkFSNode, checkType) {
std::string fileName("USERDATA:myFileTest.txt");
etk::String fileName("USERDATA:myFileTest.txt");
etk::FSNode myNodeTest1(fileName);
EXPECT_EQ(myNodeTest1.getNameFile(), "myFileTest.txt");
EXPECT_EQ(myNodeTest1.exist(), false);
@ -28,7 +28,7 @@ TEST(TestEtkFSNode, checkType) {
void testFSNode() {
TEST_INFO("==> Start test of FSNode");
std::string fileName("USERDATA:myFileTest.txt");
etk::String fileName("USERDATA:myFileTest.txt");
etk::FSNode myNodeTest1(fileName);
TEST_INFO("********************************************");
TEST_INFO("** Filename=\"" << fileName << "\"");

View File

@ -12,106 +12,106 @@
#define NAME "Hash"
std::pair<int32_t, int32_t> testRegExSingle(const std::string& _expression, const std::string& _search) {
etk::RegEx<std::string> expression(_expression);
etk::Pair<int32_t, int32_t> testRegExSingle(const etk::String& _expression, const etk::String& _search) {
etk::RegEx<etk::String> expression(_expression);
TK_INFO("Parse RegEx: \"" << expression.getRegExDecorated() << "\"");
TK_INFO(" IN: \"" << etk::regex::autoStr(_search) << "\"");
if (expression.parse(_search, 0, _search.size()) == true) {
TK_INFO(" match [" << expression.start() << ".." << expression.stop() << "] ");
TK_INFO(" ==> '" << etk::regex::autoStr(std::string(_search, expression.start(), expression.stop() - expression.start())) << "'");
return std::make_pair(expression.start(), expression.stop());
TK_INFO(" ==> '" << etk::regex::autoStr(etk::String(_search, expression.start(), expression.stop() - expression.start())) << "'");
return etk::makePair(expression.start(), expression.stop());
}
TK_INFO(" ==> ---------------");
return std::make_pair(0,0);
return etk::makePair(0,0);
}
static std::string data1 = " a /* plop */ \n int eee = 22; // error value \nint main(void) {\n return 0;\n}\n";
static std::string data2 = "alpha /* plop */ test";
static std::string data3 = "pp \n // qdfqdfsdf \nde";
static etk::String data1 = " a /* plop */ \n int eee = 22; // error value \nint main(void) {\n return 0;\n}\n";
static etk::String data2 = "alpha /* plop */ test";
static etk::String data3 = "pp \n // qdfqdfsdf \nde";
TEST(TestEtkRegEx, MultipleLineComment ) {
std::string expression = "/\\*.*\\*/";
std::pair<int32_t, int32_t> res;
etk::String expression = "/\\*.*\\*/";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, data1);
EXPECT_EQ(res, std::make_pair(3,13));
EXPECT_EQ(res, etk::makePair(3,13));
res = testRegExSingle(expression, data2);
EXPECT_EQ(res, std::make_pair(6,16));
EXPECT_EQ(res, etk::makePair(6,16));
res = testRegExSingle(expression, data3);
EXPECT_EQ(res, std::make_pair(0,0));
EXPECT_EQ(res, etk::makePair(0,0));
}
TEST(TestEtkRegEx, MultipleEndDollar ) {
std::string expression = "//.*$";
std::pair<int32_t, int32_t> res;
etk::String expression = "//.*$";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, data1);
EXPECT_EQ(res, std::make_pair(30,46));
EXPECT_EQ(res, etk::makePair(30,46));
res = testRegExSingle(expression, data2);
EXPECT_EQ(res, std::make_pair(0,0));
EXPECT_EQ(res, etk::makePair(0,0));
res = testRegExSingle(expression, data3);
EXPECT_EQ(res, std::make_pair(5,19));
EXPECT_EQ(res, etk::makePair(5,19));
}
TEST(TestEtkRegEx, MultipleNoEnd ) {
std::string expression = "/\\*.*";
std::pair<int32_t, int32_t> res;
etk::String expression = "/\\*.*";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, data1);
EXPECT_EQ(res, std::make_pair(3,5));
EXPECT_EQ(res, etk::makePair(3,5));
res = testRegExSingle(expression, data2);
EXPECT_EQ(res, std::make_pair(6,8));
EXPECT_EQ(res, etk::makePair(6,8));
res = testRegExSingle(expression, data3);
EXPECT_EQ(res, std::make_pair(0,0));
EXPECT_EQ(res, etk::makePair(0,0));
}
TEST(TestEtkRegEx, aToZ ) {
std::string expression = "[a-z]";
std::pair<int32_t, int32_t> res;
etk::String expression = "[a-z]";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, data1);
EXPECT_EQ(res, std::make_pair(1,2));
EXPECT_EQ(res, etk::makePair(1,2));
res = testRegExSingle(expression, data2);
EXPECT_EQ(res, std::make_pair(0,1));
EXPECT_EQ(res, etk::makePair(0,1));
res = testRegExSingle(expression, data3);
EXPECT_EQ(res, std::make_pair(0,1));
EXPECT_EQ(res, etk::makePair(0,1));
}
TEST(TestEtkRegEx, complexString ) {
std::string expression = "a.*plop(z{2,3}|h+)+r";
std::string dataToParse = " eesd a lzzml plophzzzzzhhhhhrlkmlkml";
std::pair<int32_t, int32_t> res;
etk::String expression = "a.*plop(z{2,3}|h+)+r";
etk::String dataToParse = " eesd a lzzml plophzzzzzhhhhhrlkmlkml";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, dataToParse);
EXPECT_EQ(res, std::make_pair(7,31));
EXPECT_EQ(res, etk::makePair(7,31));
}
TEST(TestEtkRegEx, multipleUnderscore ) {
std::string expression = "\\@\\w+_\\@";
std::string dataToParse = " aaa_bbb_ plop_ ";
std::pair<int32_t, int32_t> res;
etk::String expression = "\\@\\w+_\\@";
etk::String dataToParse = " aaa_bbb_ plop_ ";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, dataToParse);
EXPECT_EQ(res, std::make_pair(2,10));
EXPECT_EQ(res, etk::makePair(2,10));
}
TEST(TestEtkRegEx, endError ) {
std::string expression = "\\@((0(x|X)[0-9a-fA-F]*)|(\\d+\\.?\\d*|\\.\\d+)((e|E)(\\+|\\-)?\\d+)?)(LL|L|l|UL|ul|u|U|F|f)?\\@";
std::string dataToParse = "(95";
std::pair<int32_t, int32_t> res;
etk::String expression = "\\@((0(x|X)[0-9a-fA-F]*)|(\\d+\\.?\\d*|\\.\\d+)((e|E)(\\+|\\-)?\\d+)?)(LL|L|l|UL|ul|u|U|F|f)?\\@";
etk::String dataToParse = "(95";
etk::Pair<int32_t, int32_t> res;
res = testRegExSingle(expression, dataToParse);
EXPECT_EQ(res, std::make_pair(7,31));
EXPECT_EQ(res, etk::makePair(7,31));
}
void testRegEx() {
std::string data;
etk::String data;
//std::string data = "pp \n# plop // qdfqdfsdf \nde";
//std::string data = "pp \n# plop //\\\n qdfqdfsdf \nde";
//std::string data = "p#\ne";
//etk::String data = "pp \n# plop // qdfqdfsdf \nde";
//etk::String data = "pp \n# plop //\\\n qdfqdfsdf \nde";
//etk::String data = "p#\ne";
//testRegExSingle("#(\\\\\\\\|\\\\\\n|.)*$", data);
//testRegExSingle("#.*$", data);
//std::string data = "p//TODO:\ndse";
//std::string data = "p// TODO:\ndse";
//std::string data = "p// TODO :\ndse";
//std::string data = "p// TODO : sdfgsdfsd \ndse";
//etk::String data = "p//TODO:\ndse";
//etk::String data = "p// TODO:\ndse";
//etk::String data = "p// TODO :\ndse";
//etk::String data = "p// TODO : sdfgsdfsd \ndse";
//testRegExSingle("//[ \\t]*TODO[ \\t]*:.*$", data);
data = "abc m_def ghi";
@ -152,41 +152,41 @@ void testRegEx() {
/*
data = "ddfgdfgh";
etk::RegEx<std::string> reg(".*");
etk::RegEx<etk::String> reg(".*");
reg.setMaximize(true);
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
if (reg.parse(data, 0, data.size()) == true) {
//if (reg.processOneElement(data, 0, data.size()) == true) {
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
TK_INFO(" ==> '" << etk::String(data, reg.start(), reg.stop()-reg.start()) << "'");
}
data = "plop \"\" sdfsdf s\"swdfsqd sdfgsdfg \" \" sdfsf";
reg = etk::RegEx<std::string>("\"(\\\\[\\\\\"]|.)*\"");
reg = etk::RegEx<etk::String>("\"(\\\\[\\\\\"]|.)*\"");
reg.setMaximize(false);
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
if (reg.parse(data, 0, data.size()) == true) {
//if (reg.processOneElement(data, 0, data.size()) == true) {
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
TK_INFO(" ==> '" << etk::String(data, reg.start(), reg.stop()-reg.start()) << "'");
}
//TODO : good : "(\\+|[0-9])*" ==> really bad : "(+|[0-9])*"
data = "void limit(const vec2& _origin, const vec2& _size);\n";
reg = etk::RegEx<std::string>("\\@(\\w|_)+[ \\t]*\\(");
reg = etk::RegEx<etk::String>("\\@(\\w|_)+[ \\t]*\\(");
reg.setMaximize(false);
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
if (reg.parse(data, 0, data.size()) == true) {
//if (reg.processOneElement(data, 0, data.size()) == true) {
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
TK_INFO(" ==> '" << etk::String(data, reg.start(), reg.stop()-reg.start()) << "'");
}
data = "void limit const vec2& _origin, const vec2& _size);\n";
if (reg.parse(data, 0, data.size()) == true) {
//if (reg.processOneElement(data, 0, data.size()) == true) {
TK_INFO(" match [" << reg.start() << ".." << reg.stop() << "] ");
TK_INFO(" ==> '" << std::string(data, reg.start(), reg.stop()-reg.start()) << "'");
TK_INFO(" ==> '" << etk::String(data, reg.start(), reg.stop()-reg.start()) << "'");
}
*/
}