[DEV] change idea std::u32string to std::string

This commit is contained in:
Edouard DUPIN 2013-11-12 21:58:13 +01:00
parent b83c99e371
commit c8dc0b0100
18 changed files with 939 additions and 538 deletions

View File

@ -84,7 +84,7 @@ namespace etk {
return Color<uint8_t>(*this).get(); return Color<uint8_t>(*this).get();
} }
template<> Color<uint8_t>::Color(std::u32string _input) : template<> Color<uint8_t>::Color(std::string _input) :
m_r(255), m_r(255),
m_g(255), m_g(255),
m_b(255), m_b(255),
@ -97,8 +97,7 @@ namespace etk {
//std::ostringstream oss; //std::ostringstream oss;
//oss << to_u8string(_input); //oss << to_u8string(_input);
//oss >> std::hex >> val; //oss >> std::hex >> val;
std::string plop = to_u8string(_input); val = std::stoul(_input);
val = stoul(plop);
if(_input.size() == 3) { if(_input.size() == 3) {
m_r = (val & 0x00000F00) >> 8; m_r = (val & 0x00000F00) >> 8;
m_r = (m_r | m_r << 4); m_r = (m_r | m_r << 4);
@ -139,20 +138,18 @@ namespace etk {
&& _input[1] == 'g' && _input[1] == 'g'
&& _input[2] == 'b' && _input[2] == 'b'
&& _input[3] == '(' ) { && _input[3] == '(' ) {
/*
int32_t _red=0, _green=0, _blue=0, _alpha=0; int32_t _red=0, _green=0, _blue=0, _alpha=0;
float fred=0, fgreen=0, fblue=0, falpha=0; float fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(inputData + 4, "%u,%u,%u,%u", &_red, &_green, &_blue, &_alpha) == 4) { if (sscanf(_input.c_str() + 4, "%u,%u,%u,%u", &_red, &_green, &_blue, &_alpha) == 4) {
m_r = etk_min(0xFF, _red); m_r = etk_min(0xFF, _red);
m_g = etk_min(0xFF, _green); m_g = etk_min(0xFF, _green);
m_b = etk_min(0xFF, _blue); m_b = etk_min(0xFF, _blue);
m_a = etk_min(0xFF, _alpha); m_a = etk_min(0xFF, _alpha);
} else if (sscanf(inputData + 4, "%u,%u,%u", &_red, &_green, &_blue) == 3) { } else if (sscanf(_input.c_str() + 4, "%u,%u,%u", &_red, &_green, &_blue) == 3) {
m_r = etk_min(0xFF, _red); m_r = etk_min(0xFF, _red);
m_g = etk_min(0xFF, _green); m_g = etk_min(0xFF, _green);
m_b = etk_min(0xFF, _blue); m_b = etk_min(0xFF, _blue);
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) { } else if (sscanf(_input.c_str() + 4, "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) {
fred = etk_avg(0.0, fred, 1.0); fred = etk_avg(0.0, fred, 1.0);
fgreen = etk_avg(0.0, fgreen, 1.0); fgreen = etk_avg(0.0, fgreen, 1.0);
fblue = etk_avg(0.0, fblue, 1.0); fblue = etk_avg(0.0, fblue, 1.0);
@ -161,7 +158,7 @@ namespace etk {
m_g = (uint8_t)(fgreen * 255.); m_g = (uint8_t)(fgreen * 255.);
m_b = (uint8_t)(fblue * 255.); m_b = (uint8_t)(fblue * 255.);
m_a = (uint8_t)(falpha * 255.); m_a = (uint8_t)(falpha * 255.);
} else if (sscanf(inputData + 4, "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) { } else if (sscanf(_input.c_str() + 4, "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) {
fred = etk_avg(0.0, fred, 1.0); fred = etk_avg(0.0, fred, 1.0);
fgreen= etk_avg(0.0, fgreen, 1.0); fgreen= etk_avg(0.0, fgreen, 1.0);
fblue = etk_avg(0.0, fblue, 1.0); fblue = etk_avg(0.0, fblue, 1.0);
@ -169,15 +166,13 @@ namespace etk {
m_g = (uint8_t)(fgreen * 255.); m_g = (uint8_t)(fgreen * 255.);
m_b = (uint8_t)(fblue * 255.); m_b = (uint8_t)(fblue * 255.);
} else { } else {
TK_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ..."); TK_ERROR(" pb in parsing the color : \"" << _input << "\" ==> unknown methode ...");
} }
*/
} else { } else {
bool findIt = false; bool findIt = false;
std::string tmputf8string = to_u8string(_input);
// direct named color ... // direct named color ...
for (esize_t iii=0; iii<getColorSize(); iii++) { for (esize_t iii=0; iii<getColorSize(); iii++) {
if (strnCmpNoCase(getColorList()[iii].colorName, tmputf8string.c_str(), strlen(getColorList()[iii].colorName)) == true) { if (strnCmpNoCase(getColorList()[iii].colorName, _input.c_str(), strlen(getColorList()[iii].colorName)) == true) {
findIt = true; findIt = true;
*this = getColorList()[iii].color; *this = getColorList()[iii].color;
// stop searching // stop searching
@ -192,8 +187,7 @@ namespace etk {
TK_VERBOSE("Parse color : \"" << _input << "\" ==> " << *this); TK_VERBOSE("Parse color : \"" << _input << "\" ==> " << *this);
} }
template<> Color<float>::Color(std::u32string _input) template<> Color<float>::Color(std::string _input) {
{
etk::Color<uint8_t> tmpColor(_input); etk::Color<uint8_t> tmpColor(_input);
*this = tmpColor; *this = tmpColor;
} }

View File

@ -34,7 +34,7 @@ namespace etk {
}; };
Color(const etk::Color<float>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; Color(const etk::Color<float>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); };
Color(const etk::Color<uint8_t>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; Color(const etk::Color<uint8_t>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); };
Color(std::u32string _input); Color(std::string _input);
~Color(void) { }; ~Color(void) { };
Color<MY_TYPE>& operator=(const etk::Color<MY_TYPE>& _input) Color<MY_TYPE>& operator=(const etk::Color<MY_TYPE>& _input)
{ {

View File

@ -21,9 +21,9 @@
namespace etk { namespace etk {
template<class MY_TYPE> class HashData { template<class MY_TYPE> class HashData {
public: public:
std::u32string m_key; //!< name of the current hash std::string m_key; //!< name of the current hash
MY_TYPE m_value; //!< data of the current Hash MY_TYPE m_value; //!< data of the current Hash
HashData(const std::u32string& _key, const MY_TYPE& _val) : HashData(const std::string& _key, const MY_TYPE& _val) :
m_key(_key), m_key(_key),
m_value(_val) { m_value(_val) {
// nothing to do ... // nothing to do ...
@ -45,7 +45,7 @@ namespace etk {
* @brief Remove all entry in the Hash table * @brief Remove all entry in the Hash table
*/ */
void clear(void) { void clear(void) {
for (int32_t iii=0; iii<m_data.size(); iii++) { for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != NULL) { if (m_data[iii] != NULL) {
delete(m_data[iii]); delete(m_data[iii]);
m_data[iii]=NULL; m_data[iii]=NULL;
@ -58,8 +58,8 @@ namespace etk {
* @param[in] _key Name of the hash requested * @param[in] _key Name of the hash requested
* @return Id of the element in the table or -1 of it does not existed * @return Id of the element in the table or -1 of it does not existed
*/ */
int64_t getId(const std::u32string& _key) const { int64_t getId(const std::string& _key) const {
for (int32_t iii=0; iii<m_data.size(); iii++) { for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != NULL) { if (m_data[iii] != NULL) {
//TK_INFO("Compare key : '" << m_data[iii]->m_key << "' with '" << _key << "'" ); //TK_INFO("Compare key : '" << m_data[iii]->m_key << "' with '" << _key << "'" );
if (m_data[iii]->m_key == _key) { if (m_data[iii]->m_key == _key) {
@ -75,7 +75,7 @@ namespace etk {
* @param[in] _key Name of the hash requested * @param[in] _key Name of the hash requested
* @return true if the element exist * @return true if the element exist
*/ */
bool exist(const std::u32string& _name) const { bool exist(const std::string& _name) const {
int64_t elementId = getId(_name); int64_t elementId = getId(_name);
//TK_INFO(" Exist ? '" << _name << "' id=" << elementId ); //TK_INFO(" Exist ? '" << _name << "' id=" << elementId );
if (elementId<0) { if (elementId<0) {
@ -90,7 +90,7 @@ namespace etk {
* @param[in] _key Name of the hash requested * @param[in] _key Name of the hash requested
* @return Reference on the Element * @return Reference on the Element
*/ */
MY_TYPE& get(const std::u32string& _key) const { MY_TYPE& get(const std::string& _key) const {
static MY_TYPE g_error; static MY_TYPE g_error;
int64_t elementId = getId(_key); int64_t elementId = getId(_key);
if (elementId<0) { if (elementId<0) {
@ -104,14 +104,14 @@ namespace etk {
* @param[in] _key Name of the hash requested * @param[in] _key Name of the hash requested
* @return An reference on the copy of selected element * @return An reference on the copy of selected element
*/ */
MY_TYPE& operator[] (const std::u32string& _key) { MY_TYPE& operator[] (const std::string& _key) {
return get(_key); return get(_key);
} }
const MY_TYPE& operator[] (const std::u32string& _key) const { const MY_TYPE& operator[] (const std::string& _key) const {
return get(_key); return get(_key);
} }
void add(const std::u32string& _key, const MY_TYPE& _value) { void add(const std::string& _key, const MY_TYPE& _value) {
int64_t elementId = getId(_key); int64_t elementId = getId(_key);
if (elementId <0) { if (elementId <0) {
HashData<MY_TYPE>* tmp = new HashData<MY_TYPE>(_key, _value); HashData<MY_TYPE>* tmp = new HashData<MY_TYPE>(_key, _value);
@ -124,10 +124,10 @@ namespace etk {
} }
m_data[elementId]->m_value = _value; m_data[elementId]->m_value = _value;
} }
void set(const std::u32string& _key, const MY_TYPE& _value) { void set(const std::string& _key, const MY_TYPE& _value) {
add(_key, _value); add(_key, _value);
} }
void remove(const std::u32string& _key) { void remove(const std::string& _key) {
int64_t elementId = getId(_key); int64_t elementId = getId(_key);
if (elementId <0) { if (elementId <0) {
//nothing to do ==> not existed //nothing to do ==> not existed
@ -144,13 +144,13 @@ namespace etk {
esize_t size(void) const { esize_t size(void) const {
return m_data.size(); return m_data.size();
} }
MY_TYPE& operator[] (esize_t _pos) { MY_TYPE& operator[] (size_t _pos) {
return getValue(_pos); return getValue(_pos);
} }
const MY_TYPE& operator[] (esize_t _pos) const { const MY_TYPE& operator[] (size_t _pos) const {
return getValue(_pos); return getValue(_pos);
} }
const std::u32string& getKey(esize_t _pos) const { const std::string& getKey(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode // NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if(_pos>m_data.size()){ if(_pos>m_data.size()){
@ -159,7 +159,7 @@ namespace etk {
#endif #endif
return m_data[_pos]->m_key; return m_data[_pos]->m_key;
} }
const MY_TYPE& getValue(esize_t _pos) const { const MY_TYPE& getValue(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode // NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if(_pos>m_data.size()){ if(_pos>m_data.size()){
@ -168,7 +168,7 @@ namespace etk {
#endif #endif
return m_data[_pos]->m_value; return m_data[_pos]->m_value;
} }
MY_TYPE& getValue(esize_t _pos) { MY_TYPE& getValue(size_t _pos) {
// NOTE :Do not change log level, this generate error only in debug mode // NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2 #if DEBUG_LEVEL > 2
if(_pos>m_data.size()){ if(_pos>m_data.size()){

View File

@ -45,7 +45,7 @@ namespace etk
// copy element : // copy element :
_data = m_data[0]; _data = m_data[0];
// remove element : // remove element :
m_data.erase(0); m_data.erase(m_data.begin());
// remove lock // remove lock
m_mutex.unLock(); m_mutex.unLock();
return true; return true;

View File

@ -15,6 +15,14 @@
#include <vector> #include <vector>
#include <etk/Char.h> #include <etk/Char.h>
const char32_t etk::UChar::Null('\0');
const char32_t etk::UChar::Return('\n');
const char32_t etk::UChar::CarrierReturn('\r');
const char32_t etk::UChar::Tabulation('\t');
const char32_t etk::UChar::Suppress((const char)127);
const char32_t etk::UChar::Delete((const char)8);
const char32_t etk::UChar::Space(' ');
const char32_t etk::UChar::Escape((const char)27);
bool etk::isWhiteChar(char32_t _val) { bool etk::isWhiteChar(char32_t _val) {
if( _val == ' ' if( _val == ' '
@ -210,14 +218,6 @@ char32_t etk::setUtf8(const char* _input) {
} }
#if 0 #if 0
const char32_t char32_t::Null('\0');
const char32_t char32_t::Return('\n');
const char32_t char32_t::CarrierReturn('\r');
const char32_t char32_t::Tabulation('\t');
const char32_t char32_t::Suppress((const char)127);
const char32_t char32_t::Delete((const char)8);
const char32_t char32_t::Space(' ');
const char32_t char32_t::Escape((const char)27);

View File

@ -38,7 +38,16 @@ namespace etk {
REGEXP_OPCODE_NO_CHAR,/* \@ */ REGEXP_OPCODE_NO_CHAR,/* \@ */
REGEXP_OPCODE_ERROR, // not used REGEXP_OPCODE_ERROR, // not used
}; };
namespace UChar {
extern const char32_t Null; //!< '\0'
extern const char32_t Return; //!< '\n'
extern const char32_t CarrierReturn; //!< '\r' CR
extern const char32_t Tabulation; //!< '\t' TAB
extern const char32_t Suppress; //!< BS (SUPPRESS)
extern const char32_t Delete; //!< DEL
extern const char32_t Space; //!< ' ' SPACE
extern const char32_t Escape; //!< ESC Escape
};
#if 0 #if 0
class UChar : public char32_t{ class UChar : public char32_t{
public: // classic unicar code : public: // classic unicar code :

View File

@ -13,6 +13,23 @@
#undef __class__ #undef __class__
#define __class__ "std::u32string" #define __class__ "std::u32string"
etk::CCout& etk::operator <<(etk::CCout& _os, const std::string& _obj) {
_os << _obj.c_str();
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<std::string>& _obj) {
_os << "{";
for (int32_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) {
_os << " ~ ";
}
_os << _obj[iii];
}
_os << "}";
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::u32string& _obj) { etk::CCout& etk::operator <<(etk::CCout& _os, const std::u32string& _obj) {
_os << to_u8string(_obj).c_str(); _os << to_u8string(_obj).c_str();
return _os; return _os;
@ -204,6 +221,13 @@ bool compare_no_case(const std::string& _obj, const std::string& _val) {
return true; return true;
} }
std::string to_lower(const std::string& _obj) {
std::string out;
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
out.push_back(tolower(_obj[iii]));
}
return out;
}
std::u32string to_lower(const std::u32string& _obj) { std::u32string to_lower(const std::u32string& _obj) {
std::u32string out; std::u32string out;
for(size_t iii=0 ; iii<_obj.size() ; iii++) { for(size_t iii=0 ; iii<_obj.size() ; iii++) {
@ -212,6 +236,14 @@ std::u32string to_lower(const std::u32string& _obj) {
return out; return out;
} }
std::string to_upper(const std::string& _obj) {
std::string out;
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
out.push_back(toupper(_obj[iii]));
}
return out;
}
std::u32string to_upper(const std::u32string& _obj) { std::u32string to_upper(const std::u32string& _obj) {
std::u32string out; std::u32string out;
for(size_t iii=0 ; iii<_obj.size() ; iii++) { for(size_t iii=0 ; iii<_obj.size() ; iii++) {
@ -220,6 +252,33 @@ std::u32string to_upper(const std::u32string& _obj) {
return out; return out;
} }
bool end_with(const std::string& _obj, const std::string& _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 (tolower(_val[iii]) != tolower(_obj[jjj])) {
return false;
}
}
return true;
}
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) {
if (_val.size() == 0) { if (_val.size() == 0) {
return false; return false;
@ -247,6 +306,33 @@ bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _case
return true; return true;
} }
bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) {
if (_val.size() == 0) {
return false;
}
if (_val.size() > _obj.size()) {
return false;
}
if (true == _caseSensitive) {
for( size_t iii = 0;
iii < _obj.size();
iii++) {
if (_obj[iii] != _val[iii]) {
return false;
}
}
return true;
}
for( size_t iii = 0;
iii < _obj.size();
iii++) {
if (tolower(_val[iii]) != tolower(_obj[iii])) {
return false;
}
}
return true;
}
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) {
if (_val.size() == 0) { if (_val.size() == 0) {
return false; return false;
@ -298,9 +384,38 @@ std::string replace(const std::string& _obj, char _val, char _replace) {
return copy; return copy;
} }
std::string extract_line(const std::string& _obj, int32_t _pos) {
// search back : '\n'
size_t startPos = _obj.rfind('\n', _pos);
if (startPos == _pos) {
startPos = 0;
} else {
startPos++;
}
// search forward : '\n'
size_t stopPos = _pos;
if (_obj[_pos] != '\n') {
stopPos = _obj.find('\n', _pos);
if (stopPos == _pos) {
stopPos = _obj.size();
}
}
if (startPos < 0) {
startPos = 0;
} else if (startPos >= _obj.size() ) {
return "";
}
if (stopPos < 0) {
return "";
} else if (stopPos >= _obj.size() ) {
stopPos = _obj.size();
}
return std::string(_obj, startPos, stopPos);
}
std::u32string extract_line(const std::u32string& _obj, int32_t _pos) { std::u32string extract_line(const std::u32string& _obj, int32_t _pos) {
// search back : '\n' // search back : '\n'
esize_t startPos = _obj.rfind('\n', _pos); size_t startPos = _obj.rfind('\n', _pos);
if (startPos == _pos) { if (startPos == _pos) {
startPos = 0; startPos = 0;
} else { } else {
@ -327,6 +442,20 @@ std::u32string extract_line(const std::u32string& _obj, int32_t _pos) {
return std::u32string(_obj, startPos, stopPos); return std::u32string(_obj, startPos, stopPos);
} }
std::vector<std::string> string_split(const std::string& _input, char _val) {
std::vector<std::string> list;
size_t lastStartPos=0;
for(size_t iii=0; iii<_input.size(); iii++) {
if (_input[iii]==_val) {
list.push_back(std::string(_input, lastStartPos, iii));
lastStartPos = iii+1;
}
}
if (lastStartPos<_input.size()) {
list.push_back(std::string(_input, lastStartPos));
}
return list;
}
#if 0 #if 0

View File

@ -264,6 +264,8 @@ namespace etk {
}; };
#endif #endif
etk::CCout& operator <<(etk::CCout& _os, const std::string& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::vector<std::string>& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj); etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::vector<std::u32string>& _obj); etk::CCout& operator <<(etk::CCout& _os, const std::vector<std::u32string>& _obj);
}; };
@ -310,7 +312,12 @@ bool stobool(const std::string& _str);
std::u32string to_lower(const std::u32string& _obj); std::u32string to_lower(const std::u32string& _obj);
std::u32string to_upper(const std::u32string& _obj); std::u32string to_upper(const std::u32string& _obj);
std::string to_lower(const std::string& _obj);
std::string to_upper(const std::string& _obj);
bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false);
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false);
bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = false);
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false);
bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); bool compare_no_case(const std::u32string& _obj, const std::u32string& _val);
@ -321,8 +328,10 @@ std::string replace(const std::string& _obj, char _val, char _replace);
int32_t strlen(const char32_t * _data); int32_t strlen(const char32_t * _data);
std::string extract_line(const std::string& _obj, int32_t _pos);
std::u32string extract_line(const std::u32string& _obj, int32_t _pos); std::u32string extract_line(const std::u32string& _obj, int32_t _pos);
std::vector<std::string> string_split(const std::string& _input, char _val);
#endif #endif

View File

@ -10,7 +10,7 @@
#include <etk/archive/Zip.h> #include <etk/archive/Zip.h>
#include <etk/debug.h> #include <etk/debug.h>
const etk::Archive::Content& etk::Archive::getContent(const std::u32string& _key) const { const etk::Archive::Content& etk::Archive::getContent(const std::string& _key) const {
static const etk::Archive::Content g_error; static const etk::Archive::Content g_error;
if (m_content.exist(_key)==false) { if (m_content.exist(_key)==false) {
TK_ERROR("File does not exist : " << _key); TK_ERROR("File does not exist : " << _key);
@ -28,12 +28,12 @@ void etk::Archive::display(void)
} }
} }
etk::Archive* etk::Archive::load(const std::u32string& _fileName) { etk::Archive* etk::Archive::load(const std::string& _fileName) {
etk::Archive* output=NULL; etk::Archive* output=NULL;
std::u32string tmpName = to_lower(_fileName); std::string tmpName = to_lower(_fileName);
// select the corect Loader : // select the corect Loader :
if( true == end_with(tmpName, U".zip") if( true == end_with(tmpName, ".zip")
|| true == end_with(tmpName, U".apk") ) { || true == end_with(tmpName, ".apk") ) {
output = new etk::archive::Zip(_fileName); output = new etk::archive::Zip(_fileName);
if (NULL==output) { if (NULL==output) {
TK_ERROR("An error occured when load archive : " << _fileName); TK_ERROR("An error occured when load archive : " << _fileName);
@ -45,7 +45,7 @@ etk::Archive* etk::Archive::load(const std::u32string& _fileName) {
} }
void etk::Archive::open(const std::u32string& _key) { void etk::Archive::open(const std::string& _key) {
if (m_content.exist(_key)==false) { if (m_content.exist(_key)==false) {
TK_ERROR("Try open an unexistant file : '" << _key << "'"); TK_ERROR("Try open an unexistant file : '" << _key << "'");
return; return;
@ -57,7 +57,7 @@ void etk::Archive::open(const std::u32string& _key) {
m_content[_key].increaseRef(); m_content[_key].increaseRef();
} }
void etk::Archive::close(const std::u32string& _key) { void etk::Archive::close(const std::string& _key) {
if (m_content.exist(_key)==false) { if (m_content.exist(_key)==false) {
TK_ERROR("Try close an unexistant file : '" << _key << "'"); TK_ERROR("Try close an unexistant file : '" << _key << "'");
return; return;

View File

@ -13,13 +13,10 @@
#include <vector> #include <vector>
#include <etk/Hash.h> #include <etk/Hash.h>
namespace etk namespace etk {
{ class Archive {
class Archive
{
public: public:
class Content class Content {
{
private: private:
int32_t m_link; //!< number of element open on this file int32_t m_link; //!< number of element open on this file
public: public:
@ -39,16 +36,21 @@ namespace etk
std::vector<char>& getDataVector(void) { return m_data; }; std::vector<char>& getDataVector(void) { return m_data; };
}; };
public: public:
Archive(const std::u32string& _fileName) : m_fileName(_fileName) { }; Archive(const std::string& _fileName) :
m_fileName(_fileName) {
};
virtual ~Archive(void) { }; virtual ~Archive(void) { };
protected: protected:
std::u32string m_fileName; //!< File name when it came from an file std::string m_fileName; //!< File name when it came from an file
public: public:
/** /**
* @brief Get the current file name. * @brief Get the current file name.
* @return the requested file name. * @return the requested file name.
*/ */
const std::u32string& getFileName(void) { return m_fileName; }; const std::string& getFileName(void) {
return m_fileName;
};
protected: protected:
etk::Hash<Content> m_content; etk::Hash<Content> m_content;
public: public:
@ -56,41 +58,49 @@ namespace etk
* @brief Get the number of elements * @brief Get the number of elements
* @return nb files in the archive * @return nb files in the archive
*/ */
esize_t size(void) const { return m_content.size(); }; esize_t size(void) const {
return m_content.size();
};
/** /**
* @brief Get the File name of the ID * @brief Get the File name of the ID
* @param[in] _id id of the element (must be < Size()) * @param[in] _id id of the element (must be < Size())
* @return FileName of the requested id * @return FileName of the requested id
*/ */
const std::u32string& getName(esize_t _id) const { return m_content.getKey(_id); }; const std::string& getName(esize_t _id) const {
return m_content.getKey(_id);
};
/** /**
* @brief Get the File name of the ID * @brief Get the File name of the ID
* @param[in] _id id of the element (must be < Size()) * @param[in] _id id of the element (must be < Size())
* @return the archive content * @return the archive content
*/ */
const Content& getContent(esize_t _id) const { return m_content.getValue(_id); }; const Content& getContent(esize_t _id) const {
return m_content.getValue(_id);
};
/** /**
* @brief Get the File name of the ID * @brief Get the File name of the ID
* @param[in] _key name of the file * @param[in] _key name of the file
* @return FileName of the requested id * @return FileName of the requested id
*/ */
const Content& getContent(const std::u32string& _key) const; const Content& getContent(const std::string& _key) const;
/** /**
* @brief Check if a file exist * @brief Check if a file exist
* @param[in] _key Name of the file * @param[in] _key Name of the file
* @return true if the file is present * @return true if the file is present
*/ */
bool exist(const std::u32string& _key) const { return m_content.exist(_key); }; bool exist(const std::string& _key) const {
return m_content.exist(_key);
};
/** /**
* @brief Load the specific file in the memory * @brief Load the specific file in the memory
* @param[in] _key Name of the file * @param[in] _key Name of the file
*/ */
void open(const std::u32string& _key); void open(const std::string& _key);
/** /**
* @brief Un-Load the specific file from the memory * @brief Un-Load the specific file from the memory
* @param[in] _key Name of the file * @param[in] _key Name of the file
*/ */
void close(const std::u32string& _key); void close(const std::string& _key);
/** /**
* @brief Display all Element in the archive * @brief Display all Element in the archive
*/ */
@ -107,7 +117,7 @@ namespace etk
* @param[in] _fileName File name of the specific archive. * @param[in] _fileName File name of the specific archive.
* @return A pointer an the specified archive, the user might delete it. * @return A pointer an the specified archive, the user might delete it.
*/ */
static Archive* load(const std::u32string& _fileName); static Archive* load(const std::string& _fileName);
/** /**
* @brief Create an Achive with a specific name. * @brief Create an Achive with a specific name.

View File

@ -10,12 +10,12 @@
#include <etk/debug.h> #include <etk/debug.h>
#include <etk/UString.h> #include <etk/UString.h>
etk::archive::Zip::Zip(const std::u32string& _fileName) : etk::archive::Zip::Zip(const std::string& _fileName) :
etk::Archive(_fileName), etk::Archive(_fileName),
m_ctx(NULL) m_ctx(NULL)
{ {
/* Open the zip file */ /* Open the zip file */
m_ctx = unzOpen(to_u8string(m_fileName).c_str()); m_ctx = unzOpen(m_fileName.c_str());
if(!m_ctx) { if(!m_ctx) {
TK_ERROR("Unable to open the zip file '" << m_fileName << "'"); TK_ERROR("Unable to open the zip file '" << m_fileName << "'");
return; return;
@ -38,7 +38,7 @@ etk::archive::Zip::Zip(const std::u32string& _fileName) :
if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) { if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) {
// find directory ... // find directory ...
} else { } else {
m_content.add(to_u32string(tmpFileName), etk::Archive::Content(tmpFileInfo.uncompressed_size)); m_content.add(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size));
} }
/* Go the the next entry listed in the zip file. */ /* Go the the next entry listed in the zip file. */
if((iii+1) < m_info.number_entry) { if((iii+1) < m_info.number_entry) {
@ -60,7 +60,7 @@ etk::archive::Zip::~Zip(void)
void etk::archive::Zip::loadFile(int32_t _id) void etk::archive::Zip::loadFile(int32_t _id)
{ {
std::u32string fileNameRequested = m_content.getKey(_id); std::string fileNameRequested = m_content.getKey(_id);
TK_VERBOSE("Real load file : " << _id << " = '" << fileNameRequested << "'"); TK_VERBOSE("Real load file : " << _id << " = '" << fileNameRequested << "'");
unzGoToFirstFile(m_ctx); unzGoToFirstFile(m_ctx);
@ -74,7 +74,7 @@ void etk::archive::Zip::loadFile(int32_t _id)
TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'"); TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'");
return; return;
} }
if (fileNameRequested == to_u32string(tmpFileName) ) { if (fileNameRequested == tmpFileName ) {
// Entry is a file, so extract it. // Entry is a file, so extract it.
if(unzOpenCurrentFile(m_ctx) != UNZ_OK) { if(unzOpenCurrentFile(m_ctx) != UNZ_OK) {
TK_ERROR("Could not open file '" << fileNameRequested << "' into the zip file '" << m_fileName << "'"); TK_ERROR("Could not open file '" << fileNameRequested << "' into the zip file '" << m_fileName << "'");

View File

@ -21,7 +21,7 @@ namespace etk {
unzFile m_ctx; //!< mini zip context unzFile m_ctx; //!< mini zip context
unz_global_info m_info; //!< global information of the Zip unz_global_info m_info; //!< global information of the Zip
public: public:
Zip(const std::u32string& _fileName); Zip(const std::string& _fileName);
virtual ~Zip(void); virtual ~Zip(void);
protected: // herited functions : protected: // herited functions :
virtual void loadFile(int32_t _id); virtual void loadFile(int32_t _id);

View File

@ -50,16 +50,49 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj)
namespace etk { namespace etk {
template<> Vector2D<bool>::operator std::string(void) const {
std::string str;
str = "(";
str += std::to_string(x());
str += ",";
str += std::to_string(y());
str += ")";
return str;
}
template<> Vector2D<bool>::operator std::u32string(void) const { template<> Vector2D<bool>::operator std::u32string(void) const {
std::u32string str; std::u32string str;
str = U"("; str = U"(";
str += x(); str += to_u32string(x());
str += U","; str += U",";
str += y(); str += to_u32string(y());
str += U")"; str += U")";
return str; return str;
} }
template<> Vector2D<bool>::Vector2D(const std::string& _str) {
m_floats[0] = false;
m_floats[1] = false;
// copy to permit to modify it :
std::string tmpStr = _str;
if (_str[0] == '(') {
tmpStr.erase(tmpStr.begin());
}
if (*tmpStr.end() == ')') {
tmpStr.erase(tmpStr.end());
}
size_t posComa = tmpStr.find(',');
if (posComa == 0) {
// no coma ...
// in every case, we parse the first element :
m_floats[0] = stobool(tmpStr);
m_floats[1] = m_floats[0];
} else {
m_floats[0] = stobool(std::string(tmpStr, 0, posComa));
tmpStr.erase(0, posComa+1);
m_floats[1] = stobool(tmpStr);
}
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
}
template<> Vector2D<bool>::Vector2D(const std::u32string& _str) { template<> Vector2D<bool>::Vector2D(const std::u32string& _str) {
m_floats[0] = false; m_floats[0] = false;
m_floats[1] = false; m_floats[1] = false;
@ -85,16 +118,50 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
template<> Vector2D<int32_t>::operator std::string(void) const {
std::string str;
str = "(";
str += std::to_string(x());
str += ",";
str += std::to_string(y());
str += ")";
return str;
}
template<> Vector2D<int32_t>::operator std::u32string(void) const { template<> Vector2D<int32_t>::operator std::u32string(void) const {
std::u32string str; std::u32string str;
str = U"("; str = U"(";
str += x(); str += to_u32string(x());
str += U","; str += U",";
str += y(); str += to_u32string(y());
str += U")"; str += U")";
return str; return str;
} }
template<> Vector2D<int32_t>::Vector2D(const std::string& _str) {
m_floats[0] = 0;
m_floats[1] = 0;
// copy to permit to modify it :
std::string tmpStr = _str;
if (_str[0] == '(') {
tmpStr.erase(tmpStr.begin());
}
if (*tmpStr.end() == ')') {
tmpStr.erase(tmpStr.end());
}
size_t posComa = tmpStr.find(',');
if (posComa == 0) {
// no coma ...
// in every case, we parse the first element :
m_floats[0] = stoi(tmpStr);
m_floats[1] = m_floats[0];
} else {
m_floats[0] = stoi(std::string(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1);
m_floats[1] = stoi(tmpStr);
}
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
}
template<> Vector2D<int32_t>::Vector2D(const std::u32string& _str) { template<> Vector2D<int32_t>::Vector2D(const std::u32string& _str) {
m_floats[0] = 0; m_floats[0] = 0;
m_floats[1] = 0; m_floats[1] = 0;
@ -121,16 +188,51 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
template<> Vector2D<uint32_t>::operator std::string(void) const {
std::string str;
str = "(";
str += std::to_string(x());
str += ",";
str += std::to_string(y());
str += ")";
return str;
}
template<> Vector2D<uint32_t>::operator std::u32string(void) const { template<> Vector2D<uint32_t>::operator std::u32string(void) const {
std::u32string str; std::u32string str;
str = U"("; str = U"(";
str += x(); str += to_u32string(x());
str += U","; str += U",";
str += y(); str += to_u32string(y());
str += U")"; str += U")";
return str; return str;
} }
template<> Vector2D<uint32_t>::Vector2D(const std::string& _str)
{
m_floats[0] = 0;
m_floats[1] = 0;
// copy to permit to modify it :
std::string tmpStr = _str;
if (_str[0] == '(') {
tmpStr.erase(tmpStr.begin());
}
if (*tmpStr.end() == ')') {
tmpStr.erase(tmpStr.end());
}
size_t posComa = tmpStr.find(',');
if (posComa == 0) {
// no coma ...
// in every case, we parse the first element :
m_floats[0] = stoi(tmpStr);
m_floats[1] = m_floats[0];
} else {
m_floats[0] = stoi(std::string(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1);
m_floats[1] = stoi(tmpStr);
}
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
}
template<> Vector2D<uint32_t>::Vector2D(const std::u32string& _str) template<> Vector2D<uint32_t>::Vector2D(const std::u32string& _str)
{ {
m_floats[0] = 0; m_floats[0] = 0;
@ -157,16 +259,49 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
template<> Vector2D<float>::operator std::string(void) const {
std::string str;
str = "(";
str += std::to_string(x());
str += ",";
str += std::to_string(y());
str += ")";
return str;
}
template<> Vector2D<float>::operator std::u32string(void) const { template<> Vector2D<float>::operator std::u32string(void) const {
std::u32string str; std::u32string str;
str = U"("; str = U"(";
str += x(); str += to_u32string(x());
str += U","; str += U",";
str += y(); str += to_u32string(y());
str += U")"; str += U")";
return str; return str;
} }
template<> Vector2D<float>::Vector2D(const std::string& _str) {
m_floats[0] = 0;
m_floats[1] = 0;
// copy to permit to modify it :
std::string tmpStr = _str;
if (_str[0] == '(') {
tmpStr.erase(tmpStr.begin());
}
if (*tmpStr.end() == ')') {
tmpStr.erase(tmpStr.end());
}
size_t posComa = tmpStr.find(',');
if (posComa == 0) {
// no coma ...
// in every case, we parse the first element :
m_floats[0] = stof(tmpStr);
m_floats[1] = m_floats[0];
} else {
m_floats[0] = stof(std::string(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1);
m_floats[1] = stof(tmpStr);
}
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
}
template<> Vector2D<float>::Vector2D(const std::u32string& _str) { template<> Vector2D<float>::Vector2D(const std::u32string& _str) {
m_floats[0] = 0; m_floats[0] = 0;
m_floats[1] = 0; m_floats[1] = 0;

View File

@ -25,8 +25,7 @@ namespace etk
/***************************************************** /*****************************************************
* Constructor * Constructor
*****************************************************/ *****************************************************/
Vector2D(void) Vector2D(void) {
{
#ifdef DEBUG #ifdef DEBUG
// in debug mode we set supid value to prevent forget of the inits ... // in debug mode we set supid value to prevent forget of the inits ...
m_floats[0] = (T)34673363; m_floats[0] = (T)34673363;
@ -34,14 +33,14 @@ namespace etk
#endif #endif
}; };
Vector2D(T _x, T _y) Vector2D(T _x, T _y) {
{
m_floats[0] = _x; m_floats[0] = _x;
m_floats[1] = _y; m_floats[1] = _y;
}; };
Vector2D(const Vector2D<double>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D<double>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<float>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D<float>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<int32_t>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D<int32_t>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const std::string& str);
Vector2D(const std::u32string& str); Vector2D(const std::u32string& str);
~Vector2D(void) { }; ~Vector2D(void) { };
/***************************************************** /*****************************************************
@ -173,14 +172,12 @@ namespace etk
/***************************************************** /*****************************************************
* ++ operator * ++ operator
*****************************************************/ *****************************************************/
Vector2D<T>& operator++() // prefix Vector2D<T>& operator++() {
{
++m_floats[0]; ++m_floats[0];
++m_floats[1]; ++m_floats[1];
return *this; return *this;
} }
Vector2D<T> operator++(int unused) // postfix Vector2D<T> operator++(int unused) {
{
Vector2D<T> result = *this; Vector2D<T> result = *this;
++(*this); ++(*this);
return result; return result;
@ -188,184 +185,161 @@ namespace etk
/***************************************************** /*****************************************************
* -- operator * -- operator
*****************************************************/ *****************************************************/
Vector2D<T>& operator--() // prefix Vector2D<T>& operator--() {
{
--m_floats[0]; --m_floats[0];
--m_floats[1]; --m_floats[1];
return *this; return *this;
} }
Vector2D<T> operator--(int unused) {
Vector2D<T> operator--(int unused) // postfix
{
Vector2D<T> result = *this; Vector2D<T> result = *this;
--(*this); --(*this);
return result; return result;
} }
/** /**
* @brief Return the dot product * @brief Return the dot product
* @param v The other vector in the dot product * @param v The other vector in the dot product
*/ */
btScalar dot(const Vector2D<T>& v) const btScalar dot(const Vector2D<T>& v) const {
{
return m_floats[0] * v.m_floats[0] + return m_floats[0] * v.m_floats[0] +
m_floats[1] * v.m_floats[1]; m_floats[1] * v.m_floats[1];
} }
/** /**
* @brief Return the length of the vector squared * @brief Return the length of the vector squared
*/ */
btScalar length2(void) const btScalar length2(void) const {
{
return dot(*this); return dot(*this);
} }
/** /**
* @brief Return the length of the vector * @brief Return the length of the vector
*/ */
btScalar length(void) const btScalar length(void) const {
{
return btSqrt(length2()); return btSqrt(length2());
} }
/** /**
* @brief Return the distance squared between the ends of this and another vector * @brief Return the distance squared between the ends of this and another vector
* This is symantically treating the vector like a point * This is symantically treating the vector like a point
*/ */
btScalar distance2(const btVector3& v) const btScalar distance2(const btVector3& v) const {
{
return (v - *this).length2(); return (v - *this).length2();
} }
/** /**
* @brief Return the distance between the ends of this and another vector * @brief Return the distance between the ends of this and another vector
* This is symantically treating the vector like a point * This is symantically treating the vector like a point
*/ */
btScalar distance(const btVector3& v) const btScalar distance(const btVector3& v) const {
{
return (v - *this).length(); return (v - *this).length();
} }
/** /**
* @brief Normalize this vector * @brief Normalize this vector
* x^2 + y^2 + z^2 = 1 * x^2 + y^2 + z^2 = 1
*/ */
Vector3D<T>& normalize(void) Vector3D<T>& normalize(void) {
{
return *this /= length(); return *this /= length();
} }
/** /**
* @brief Return a normalized version of this vector * @brief Return a normalized version of this vector
*/ */
Vector2D<T> normalized(void) const Vector2D<T> normalized(void) const {
{
return *this / length(); return *this / length();
} }
/** /**
* @brief Return a vector will the absolute values of each element * @brief Return a vector will the absolute values of each element
*/ */
Vector2D<T> absolute(void) const Vector2D<T> absolute(void) const {
{
return Vector2D<T>( abs(m_floats[0]), return Vector2D<T>( abs(m_floats[0]),
abs(m_floats[1])); abs(m_floats[1]));
} }
/** /**
* @brief Return the axis with the smallest value * @brief Return the axis with the smallest value
* Note return values are 0,1,2 for x, y, or z * Note return values are 0,1,2 for x, y, or z
*/ */
int32_t minAxis(void) const int32_t minAxis(void) const {
{
return m_floats[0] < m_floats[1] ? 0 : 1; return m_floats[0] < m_floats[1] ? 0 : 1;
} }
/** /**
* @brief Return the axis with the largest value * @brief Return the axis with the largest value
* Note return values are 0,1,2 for x, y, or z * Note return values are 0,1,2 for x, y, or z
*/ */
int32_t maxAxis(void) const int32_t maxAxis(void) const {
{
return m_floats[0] < m_floats[1] ? 1 : 0; return m_floats[0] < m_floats[1] ? 1 : 0;
} }
int32_t furthestAxis(void) const {
int32_t furthestAxis(void) const
{
return absolute().minAxis(); return absolute().minAxis();
} }
int32_t closestAxis(void) const {
int32_t closestAxis(void) const
{
return absolute().maxAxis(); return absolute().maxAxis();
} }
/** /**
* @brief Return the x value * @brief Return the x value
*/ */
const T& getX() const { return m_floats[0]; } const T& getX() const {
return m_floats[0];
}
/** /**
* @brief Return the y value * @brief Return the y value
*/ */
const T& getY() const { return m_floats[1]; } const T& getY() const {
return m_floats[1];
}
/** /**
* @brief Set the x value * @brief Set the x value
*/ */
void setX(T _x) { m_floats[0] = _x;}; void setX(T _x) {
m_floats[0] = _x;
};
/** /**
* @brief Set the y value * @brief Set the y value
*/ */
void setY(T _y) { m_floats[1] = _y;}; void setY(T _y) {
m_floats[1] = _y;
};
/** /**
* @brief Return the x value * @brief Return the x value
*/ */
const T& x() const { return m_floats[0]; } const T& x() const {
return m_floats[0];
}
/** /**
* @brief Return the y value * @brief Return the y value
*/ */
const T& y() const { return m_floats[1]; } const T& y() const {
return m_floats[1];
operator T *() { return &m_floats[0]; } }
operator const T *() const { return &m_floats[0]; } operator T *() {
return &m_floats[0];
}
operator const T *() const {
return &m_floats[0];
}
/** /**
* @brief Set each element to the max of the current values and the values of another btVector3 * @brief Set each element to the max of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param other The other btVector3 to compare with
*/ */
void setMax(const Vector2D<T>& other) void setMax(const Vector2D<T>& other) {
{
btSetMax(m_floats[0], other.m_floats[0]); btSetMax(m_floats[0], other.m_floats[0]);
btSetMax(m_floats[1], other.m_floats[1]); btSetMax(m_floats[1], other.m_floats[1]);
} }
/** /**
* @brief Set each element to the min of the current values and the values of another btVector3 * @brief Set each element to the min of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param other The other btVector3 to compare with
*/ */
void setMin(const Vector2D<T>& other) void setMin(const Vector2D<T>& other) {
{
btSetMin(m_floats[0], other.m_floats[0]); btSetMin(m_floats[0], other.m_floats[0]);
btSetMin(m_floats[1], other.m_floats[1]); btSetMin(m_floats[1], other.m_floats[1]);
} }
void setValue(const T& _x, const T& _y) {
void setValue(const T& _x, const T& _y)
{
m_floats[0]=_x; m_floats[0]=_x;
m_floats[1]=_y; m_floats[1]=_y;
} }
void setZero(void) {
void setZero(void)
{
setValue(0,0); setValue(0,0);
} }
bool isZero(void) const {
bool isZero(void) const
{
return m_floats[0] == 0 && m_floats[1] == 0; return m_floats[0] == 0 && m_floats[1] == 0;
} }
//!< string cast : //!< string cast :
operator std::string(void) const;
operator std::u32string(void) const; operator std::u32string(void) const;
//std::u32string UString(void) const { return *this; };
}; };
/** /**
* @brief Debug operator To display the curent element in a Human redeable information * @brief Debug operator To display the curent element in a Human redeable information
@ -384,14 +358,12 @@ typedef etk::Vector2D<int32_t> ivec2;
typedef etk::Vector2D<uint32_t> uivec2; typedef etk::Vector2D<uint32_t> uivec2;
typedef etk::Vector2D<bool> bvec2; typedef etk::Vector2D<bool> bvec2;
inline vec2 vec2ClipInt32(const vec2& val) inline vec2 vec2ClipInt32(const vec2& _val) {
{ return vec2((int32_t)_val.x(), (int32_t)_val.y());
return vec2((int32_t)val.x(), (int32_t)val.y());
} }
inline vec2 vec2ClipInt64(const vec2& val) inline vec2 vec2ClipInt64(const vec2& _val) {
{ return vec2((int64_t)_val.x(), (int64_t)_val.y());
return vec2((int64_t)val.x(), (int64_t)val.y());
} }
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
namespace etk namespace etk
{ {
void setArgZero(const std::u32string& _val); void setArgZero(const std::string& _val);
/** /**
* List of Type that a node can have (this wrap some type that not exist on Windows) * List of Type that a node can have (this wrap some type that not exist on Windows)
*/ */
@ -123,8 +123,8 @@ namespace etk
class FSNode class FSNode
{ {
private: private:
std::u32string m_userFileName; //!< the name requested by the User std::string m_userFileName; //!< the name requested by the User
std::u32string m_systemFileName; //!< the compleate filename for the system std::string m_systemFileName; //!< the compleate filename for the system
enum FSNType m_type; //!< the Type of data requested by the User enum FSNType m_type; //!< the Type of data requested by the User
enum typeNode m_typeNode; //!< type of the current file/Folder/Link enum typeNode m_typeNode; //!< type of the current file/Folder/Link
etk::FSNodeRight m_rights; //!< IO right of the current file etk::FSNodeRight m_rights; //!< IO right of the current file
@ -140,7 +140,8 @@ namespace etk
* @brief Constructor * @brief Constructor
* @param[in] _path Path of the curent file /folder ... * @param[in] _path Path of the curent file /folder ...
*/ */
FSNode(const std::u32string& _path = U"~"); FSNode(const std::string& _path = "~");
FSNode(const std::u32string& _path);
/** /**
* @brief Destructor * @brief Destructor
* @note you will have some warning if you did not close your files * @note you will have some warning if you did not close your files
@ -159,6 +160,7 @@ namespace etk
* @brief Common set name of the Node (if the user decide to change the node selection * @brief Common set name of the Node (if the user decide to change the node selection
* @param[in] _newName Name of the Node * @param[in] _newName Name of the Node
*/ */
void privateSetName(const std::string& _newName);
void privateSetName(const std::u32string& _newName); void privateSetName(const std::u32string& _newName);
private: private:
#ifdef __TARGET_OS__Android #ifdef __TARGET_OS__Android
@ -207,35 +209,41 @@ namespace etk
* @return true : action done * @return true : action done
* @return false : action not done * @return false : action not done
*/ */
void setName(const std::string& _newName);
void setName(const std::u32string& _newName); void setName(const std::u32string& _newName);
/** /**
* @brief Get the Generate FileSystem name * @brief Get the Generate FileSystem name
* @return the requested filename * @return the requested filename
*/ */
std::u32string getFileSystemName(void) const; std::string getFileSystemName(void) const;
std::u32string getUFileSystemName(void) const;
/** /**
* @brief Get the current folder of the Node. (file system name) * @brief Get the current folder of the Node. (file system name)
* @return the common name define (like /xxxxx/xxxxx/ or c:/xxxxx/xxxxx/) * @return the common name define (like /xxxxx/xxxxx/ or c:/xxxxx/xxxxx/)
* @note Auto remove of ../../../ and // * @note Auto remove of ../../../ and //
*/ */
std::u32string getNameFolder(void) const; std::string getNameFolder(void) const;
std::u32string getUNameFolder(void) const;
/** /**
* @brief Get the current compleate node name (file system name) * @brief Get the current compleate node name (file system name)
* @return All the user name definition (like /xxxxx/xxxxx/myFile.kkk or c:/xxxxx/xxxxx/myFile.kkk) * @return All the user name definition (like /xxxxx/xxxxx/myFile.kkk or c:/xxxxx/xxxxx/myFile.kkk)
* @note Auto remove of ../../../ and // * @note Auto remove of ../../../ and //
*/ */
std::u32string getName(void) const; std::string getName(void) const;
std::u32string getUName(void) const;
/** /**
* @brief Get the file or current folder name (if it was a folder) * @brief Get the file or current folder name (if it was a folder)
* @return the name of the node (like myFile.kkk) * @return the name of the node (like myFile.kkk)
*/ */
std::u32string getNameFile(void) const; std::string getNameFile(void) const;
std::u32string getUNameFile(void) const;
/** /**
* @brief Get the current folder of the Node. * @brief Get the current folder of the Node.
* @return the common name define (like DATA:xxxxx/xxxxx/) * @return the common name define (like DATA:xxxxx/xxxxx/)
* @note Auto remove of ../../../ and // * @note Auto remove of ../../../ and //
*/ */
std::u32string getRelativeFolder(void) const; std::string getRelativeFolder(void) const;
std::u32string getURelativeFolder(void) const;
/** /**
* @brief update the Time of the file with the current time * @brief update the Time of the file with the current time
* @return true : action done * @return true : action done
@ -248,6 +256,7 @@ namespace etk
* @return true : action done * @return true : action done
* @return false : action not done * @return false : action not done
*/ */
bool move(const std::string& _path);
bool move(const std::u32string& _path); bool move(const std::u32string& _path);
/** /**
* @brief Get the node type (DATA/DIRECT...) * @brief Get the node type (DATA/DIRECT...)
@ -271,7 +280,8 @@ namespace etk
* @brief Get the creating time of the File * @brief Get the creating time of the File
* @return The time requested (in string) * @return The time requested (in string)
*/ */
std::u32string timeCreatedString(void) const; std::string timeCreatedString(void) const;
std::u32string timeUCreatedString(void) const;
/** /**
* @brief Get the modifying time of the File * @brief Get the modifying time of the File
* @return The time requested * @return The time requested
@ -281,7 +291,8 @@ namespace etk
* @brief Get the modifying time of the File * @brief Get the modifying time of the File
* @return The time requested (in string) * @return The time requested (in string)
*/ */
std::u32string timeModifiedString(void) const; std::string timeModifiedString(void) const;
std::u32string timeUModifiedString(void) const;
/** /**
* @brief Get the Accessed time of the File * @brief Get the Accessed time of the File
* @return The time requested * @return The time requested
@ -291,7 +302,8 @@ namespace etk
* @brief Get the Accessed time of the File * @brief Get the Accessed time of the File
* @return The time requested (in string) * @return The time requested (in string)
*/ */
std::u32string timeAccessedString(void) const; std::string timeAccessedString(void) const;
std::u32string timeUAccessedString(void) const;
/** /**
* @brief copy the other FSnode ==> for vector * @brief copy the other FSnode ==> for vector
* @param[in] _obj input node * @param[in] _obj input node
@ -346,6 +358,7 @@ namespace etk
* @param[out] _output List of all the File names (You must clear it before set it in) * @param[out] _output List of all the File names (You must clear it before set it in)
* @param[in] _recursiveEnable Activate the recursive mode (enable by default) * @param[in] _recursiveEnable Activate the recursive mode (enable by default)
*/ */
void folderGetRecursiveFiles(std::vector<std::string>& _output, bool _recursiveEnable=true);
void folderGetRecursiveFiles(std::vector<std::u32string>& _output, bool _recursiveEnable=true); void folderGetRecursiveFiles(std::vector<std::u32string>& _output, bool _recursiveEnable=true);
/** /**
* @brief Check if the file have an extention ( ***.ccc) * @brief Check if the file have an extention ( ***.ccc)
@ -357,7 +370,8 @@ namespace etk
* @brief Get the extention of the Node * @brief Get the extention of the Node
* @return the requested extention * @return the requested extention
*/ */
std::u32string fileGetExtention(void); std::string fileGetExtention(void);
std::u32string fileUGetExtention(void);
/** /**
* @brief Get the File size * @brief Get the File size
* @return the requested size * @return the requested size
@ -463,12 +477,14 @@ namespace etk
* @brief Get the home folder of the user * @brief Get the home folder of the user
* @return the home folder : like : "/home/machin/" * @return the home folder : like : "/home/machin/"
*/ */
std::u32string getUserHomeFolder(void); std::string getUserHomeFolder(void);
std::u32string getUUserHomeFolder(void);
/** /**
* @brief Get the folder of the Program is running * @brief Get the folder of the Program is running
* @return the basic folder name (ex : run ./appl in the pwd=/home/machin/sousFolder ==> this return the pwd folder) * @return the basic folder name (ex : run ./appl in the pwd=/home/machin/sousFolder ==> this return the pwd folder)
*/ */
std::u32string getUserRunFolder(void); std::string getUserRunFolder(void);
std::u32string getUUserRunFolder(void);
namespace theme { namespace theme {
// TODO : Add an INIT ... // TODO : Add an INIT ...
@ -477,18 +493,21 @@ namespace etk
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/") * @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/")
*/ */
void setName(std::u32string _refName, std::u32string _folderName); void setName(const std::string& _refName, const std::string& _folderName);
void setName(const std::u32string& _refName, const std::u32string& _folderName);
/** /**
* @brief get the folder from a Reference theme * @brief get the folder from a Reference theme
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @return the path of the theme * @return the path of the theme
*/ */
std::u32string getName(std::u32string _refName); std::string getName(const std::string& _refName);
std::u32string getName(const std::u32string& _refName);
/** /**
* @brief Get the list of all the theme folder availlable in the user Home/appl * @brief Get the list of all the theme folder availlable in the user Home/appl
* @return The list of elements * @return The list of elements
*/ */
std::vector<std::u32string> list(void); std::vector<std::string> list(void);
std::vector<std::u32string> listU(void);
}; };
/** /**
@ -497,6 +516,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeRemove(const std::string& _path);
bool FSNodeRemove(const std::u32string& _path); bool FSNodeRemove(const std::u32string& _path);
/** /**
* @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1) * @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1)
@ -504,6 +524,7 @@ namespace etk
* @return number of File inside * @return number of File inside
* @return -1 : An error occured * @return -1 : An error occured
*/ */
int64_t FSNodeGetCount(const std::string& _path);
int64_t FSNodeGetCount(const std::u32string& _path); int64_t FSNodeGetCount(const std::u32string& _path);
/** /**
* @brief Simple access for : Create a file or a folder depending of the request * @brief Simple access for : Create a file or a folder depending of the request
@ -513,6 +534,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER);
bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER);
/** /**
* @brief Simple access for : chexk the exestance of an element * @brief Simple access for : chexk the exestance of an element
@ -520,6 +542,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeExist(const std::string& _path);
bool FSNodeExist(const std::u32string& _path); bool FSNodeExist(const std::u32string& _path);
/** /**
* @brief Simple access for : chexk the exestance of an element * @brief Simple access for : chexk the exestance of an element
@ -528,6 +551,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeMove(const std::string& _path1, const std::string& _path2);
bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2);
/** /**
* @brief Simple access for : Get right of the current Node * @brief Simple access for : Get right of the current Node
@ -535,6 +559,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
etk::FSNodeRight FSNodeGetRight(const std::string& _path);
etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); etk::FSNodeRight FSNodeGetRight(const std::u32string& _path);
/** /**
* @brief Simple access for : Get type of the current node * @brief Simple access for : Get type of the current node
@ -542,6 +567,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
enum etk::typeNode FSNodeGetType(const std::string& _path);
enum etk::typeNode FSNodeGetType(const std::u32string& _path); enum etk::typeNode FSNodeGetType(const std::u32string& _path);
/** /**
* @brief Simple access for : Getting creation time of the current node * @brief Simple access for : Getting creation time of the current node
@ -549,6 +575,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
uint64_t FSNodeGetTimeCreated(const std::string& _path);
uint64_t FSNodeGetTimeCreated(const std::u32string& _path); uint64_t FSNodeGetTimeCreated(const std::u32string& _path);
/** /**
* @brief Simple access for : Getting Modification time of the current node * @brief Simple access for : Getting Modification time of the current node
@ -556,6 +583,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
uint64_t FSNodeGetTimeModified(const std::string& _path);
uint64_t FSNodeGetTimeModified(const std::u32string& _path); uint64_t FSNodeGetTimeModified(const std::u32string& _path);
/** /**
* @brief Simple access for : Getting Accessing time of the current node * @brief Simple access for : Getting Accessing time of the current node
@ -563,6 +591,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
uint64_t FSNodeGetTimeAccessed(const std::string& _path);
uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); uint64_t FSNodeGetTimeAccessed(const std::u32string& _path);
/** /**
* @brief Simple access for : Update Modification time with the current time of the node (>) * @brief Simple access for : Update Modification time with the current time of the node (>)
@ -570,6 +599,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeTouch(const std::string& _path);
bool FSNodeTouch(const std::u32string& _path); bool FSNodeTouch(const std::u32string& _path);
/** /**
* @brief Simple access for : Basic write on the node (like console echo) * @brief Simple access for : Basic write on the node (like console echo)
@ -578,6 +608,7 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeEcho(const std::string& _path, const std::string& _dataTowrite);
bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite);
/** /**
* @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>) * @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>)
@ -586,12 +617,14 @@ namespace etk
* @return true : Action done corectly * @return true : Action done corectly
* @return false : An error occured * @return false : An error occured
*/ */
bool FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrite);
bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite);
/** /**
* @brief move file to generate an history of the current file * @brief move file to generate an history of the current file
* @param[in] _path Folder/File/Pipe path of the node * @param[in] _path Folder/File/Pipe path of the node
* @param[in] _historyCount number of saved file in the history (-xxx) * @param[in] _historyCount number of saved file in the history (-xxx)
*/ */
void FSNodeHistory(const std::string& _path, int32_t _historyCount);
void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); void FSNodeHistory(const std::u32string& _path, int32_t _historyCount);
}; };

View File

@ -176,8 +176,8 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus)
m_rights |= RIGHT_OTHER_EXECUTE; m_rights |= RIGHT_OTHER_EXECUTE;
} }
} }
std::u32string etk::FSNodeRight::getRight(void) const
{ std::u32string etk::FSNodeRight::getURight(void) const {
std::u32string tmp; std::u32string tmp;
if (isUserReadable() == true) { if (isUserReadable() == true) {
tmp += U"r"; tmp += U"r";
@ -227,6 +227,56 @@ std::u32string etk::FSNodeRight::getRight(void) const
return tmp; return tmp;
} }
std::string etk::FSNodeRight::getRight(void) const {
std::string tmp;
if (isUserReadable() == true) {
tmp += "r";
} else {
tmp += "-";
}
if (isUserWritable() == true) {
tmp += "w";
} else {
tmp += "-";
}
if (isUserRunable() == true) {
tmp += "x";
} else {
tmp += "-";
}
if (isGroupReadable() == true) {
tmp += "r";
} else {
tmp += "-";
}
if (isGroupWritable() == true) {
tmp += "w";
} else {
tmp += "-";
}
if (isGroupRunable() == true) {
tmp += "x";
} else {
tmp += "-";
}
if (isOtherReadable() == true) {
tmp += "r";
} else {
tmp += "-";
}
if (isOtherWritable() == true) {
tmp += "w";
} else {
tmp += "-";
}
if (isOtherRunable() == true) {
tmp += "x";
} else {
tmp += "-";
}
return tmp;
}
etk::CCout& etk::operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj) etk::CCout& etk::operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj)
{ {

View File

@ -49,7 +49,8 @@ namespace etk
void setOtherWritable(bool _newStatus); void setOtherWritable(bool _newStatus);
void setOtherRunable(bool _newStatus); void setOtherRunable(bool _newStatus);
std::u32string getRight(void) const; std::u32string getURight(void) const;
std::string getRight(void) const;
}; };
etk::CCout& operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj); etk::CCout& operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj);
}; };