[DEV] add many const and capability to convert element in string and the oposite
This commit is contained in:
parent
91c6690daa
commit
fe0d7ab99f
@ -30,9 +30,9 @@ etk::Char::operator void *()
|
||||
};
|
||||
|
||||
|
||||
void etk::Char::SetValue(const etk::Vector<char>& data)
|
||||
void etk::Char::SetValue(const etk::Vector<char>& _data)
|
||||
{
|
||||
m_data = data;
|
||||
m_data = _data;
|
||||
// check presence of '\0' (note : start by the end might be faster ...
|
||||
for (int32_t iii=m_data.Size()-1; iii>=0; iii--) {
|
||||
if (m_data[iii] == '\0') {
|
||||
|
@ -24,7 +24,7 @@ namespace etk
|
||||
~Char(void);
|
||||
operator const char *();
|
||||
operator void *();
|
||||
void SetValue(const etk::Vector<char>& data);
|
||||
void SetValue(const etk::Vector<char>& _data);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1747,7 +1747,7 @@ template<class CLASS_TYPE> class RegExp {
|
||||
* @brief Get the regular expression string
|
||||
* @return the string representing the RegExp
|
||||
*/
|
||||
etk::UString GetRegExp(void)
|
||||
const etk::UString& GetRegExp(void) const
|
||||
{
|
||||
return m_expressionRequested;
|
||||
};
|
||||
|
@ -126,15 +126,29 @@ void etk::UString::Set(const uniChar_t * inputData, int32_t len)
|
||||
}
|
||||
|
||||
|
||||
etk::UString::UString(char inputData)
|
||||
etk::UString::UString(const bool _inputData)
|
||||
{
|
||||
char tmpVal[2];
|
||||
// generate the UString :
|
||||
sprintf(tmpVal, "%c", inputData);
|
||||
// set the internal data :
|
||||
m_data.Clear();
|
||||
if (true == _inputData) {
|
||||
m_data.PushBack('t');
|
||||
m_data.PushBack('r');
|
||||
m_data.PushBack('u');
|
||||
m_data.PushBack('e');
|
||||
} else {
|
||||
m_data.PushBack('f');
|
||||
m_data.PushBack('a');
|
||||
m_data.PushBack('l');
|
||||
m_data.PushBack('s');
|
||||
m_data.PushBack('e');
|
||||
}
|
||||
m_data.PushBack('\0');
|
||||
}
|
||||
|
||||
etk::UString::UString(const char inputData)
|
||||
{
|
||||
m_data.Clear();
|
||||
m_data.PushBack((uint32_t)inputData);
|
||||
m_data.PushBack('\0');
|
||||
Set(tmpVal);
|
||||
}
|
||||
|
||||
|
||||
@ -161,7 +175,7 @@ etk::UString::UString(unsigned int inputData, const char* mode)
|
||||
Set(tmpVal);
|
||||
}
|
||||
|
||||
etk::UString::UString(float inputData)
|
||||
etk::UString::UString(const float inputData)
|
||||
{
|
||||
char tmpVal[256];
|
||||
// generate the UString :
|
||||
@ -172,7 +186,7 @@ etk::UString::UString(float inputData)
|
||||
Set(tmpVal);
|
||||
}
|
||||
|
||||
etk::UString::UString(double inputData)
|
||||
etk::UString::UString(const double inputData)
|
||||
{
|
||||
char tmpVal[256];
|
||||
// generate the UString :
|
||||
@ -640,7 +654,14 @@ etk::Char etk::UString::c_str(void) const
|
||||
return tmpVar;
|
||||
}
|
||||
|
||||
|
||||
bool etk::UString::ToBool(void) const
|
||||
{
|
||||
if( true == CompareNoCase("true")
|
||||
|| *this == "1") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int64_t etk::UString::ToInt64(void) const
|
||||
{
|
||||
int64_t ret=0;
|
||||
|
@ -28,11 +28,12 @@ namespace etk
|
||||
void Set(const uniChar_t* inputData, int32_t len=-1);
|
||||
void Set(const char* inputData, int32_t len=-1);
|
||||
// basic convertion integer en string
|
||||
UString(char inputData);
|
||||
UString(const bool _inputData);
|
||||
UString(const char _inputData);
|
||||
UString(int inputData, const char* mode="%d");
|
||||
UString(unsigned int inputData, const char* mode="%d");
|
||||
UString(float inputData);
|
||||
UString(double inputData);
|
||||
UString(const float inputData);
|
||||
UString(const double inputData);
|
||||
UString(const etk::UString &etkS);
|
||||
//UString(const uniChar_t inputData);
|
||||
// destructor :
|
||||
@ -41,7 +42,7 @@ namespace etk
|
||||
/*****************************************************
|
||||
* = assigment
|
||||
*****************************************************/
|
||||
const etk::UString& operator= (const etk::UString &etkS );
|
||||
const etk::UString& operator= (const etk::UString& etkS );
|
||||
const etk::UString& operator= (etk::Vector<char> inputData);
|
||||
const etk::UString& operator= (etk::Vector<int8_t> inputData);
|
||||
const etk::UString& operator= (etk::Vector<uniChar_t> inputData);
|
||||
@ -157,6 +158,11 @@ namespace etk
|
||||
* @return the requested float
|
||||
*/
|
||||
float ToFloat(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in a boolean
|
||||
* @return the requested bool
|
||||
*/
|
||||
bool ToBool(void) const;
|
||||
};
|
||||
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::UString &obj);
|
||||
|
@ -8,136 +8,148 @@
|
||||
|
||||
#include <etk/math/Vector2D.h>
|
||||
|
||||
etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector2D<int32_t> obj)
|
||||
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<int32_t>& _obj)
|
||||
{
|
||||
os << "(";
|
||||
os << obj.x();
|
||||
os << ",";
|
||||
os << obj.y();
|
||||
os << ")";
|
||||
return os;
|
||||
_os << "(";
|
||||
_os << _obj.x();
|
||||
_os << ",";
|
||||
_os << _obj.y();
|
||||
_os << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector2D<float> obj)
|
||||
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<float>& _obj)
|
||||
{
|
||||
os << "(";
|
||||
os << obj.x();
|
||||
os << ",";
|
||||
os << obj.y();
|
||||
os << ")";
|
||||
return os;
|
||||
_os << "(";
|
||||
_os << _obj.x();
|
||||
_os << ",";
|
||||
_os << _obj.y();
|
||||
_os << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector2D<uint32_t> obj)
|
||||
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<uint32_t>& _obj)
|
||||
{
|
||||
os << "(";
|
||||
os << obj.x();
|
||||
os << ",";
|
||||
os << obj.y();
|
||||
os << ")";
|
||||
return os;
|
||||
_os << "(";
|
||||
_os << _obj.x();
|
||||
_os << ",";
|
||||
_os << _obj.y();
|
||||
_os << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector2D<bool> obj)
|
||||
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj)
|
||||
{
|
||||
os << "(";
|
||||
os << obj.x();
|
||||
os << ",";
|
||||
os << obj.y();
|
||||
os << ")";
|
||||
return os;
|
||||
_os << "(";
|
||||
_os << _obj.x();
|
||||
_os << ",";
|
||||
_os << _obj.y();
|
||||
_os << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
|
||||
template<> Vector2D<bool>::Vector2D(const etk::UString& str)
|
||||
namespace etk
|
||||
{
|
||||
template<> Vector2D<bool>::operator etk::UString(void) const
|
||||
{
|
||||
etk::UString str;
|
||||
str = "(";
|
||||
str += x();
|
||||
str += ",";
|
||||
str += y();
|
||||
str += ")";
|
||||
return str;
|
||||
}
|
||||
|
||||
template<> Vector2D<bool>::Vector2D(const etk::UString& _str)
|
||||
{
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
if (str.StartWith("(")) {
|
||||
if (str.StartWith("(t")) {
|
||||
if (str.CompareNoCase("(true,true)")) {
|
||||
if (_str.StartWith("(")) {
|
||||
if (_str.StartWith("(t")) {
|
||||
if (_str.CompareNoCase("(true,true)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("(true,false)")) {
|
||||
} else if (_str.CompareNoCase("(true,false)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("(true)")) {
|
||||
} else if (_str.CompareNoCase("(true)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
}
|
||||
} else if (str.StartWith("(f")) {
|
||||
if (str.CompareNoCase("(false,true)")) {
|
||||
} else if (_str.StartWith("(f")) {
|
||||
if (_str.CompareNoCase("(false,true)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("(false,false)")) {
|
||||
} else if (_str.CompareNoCase("(false,false)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("(false)")) {
|
||||
} else if (_str.CompareNoCase("(false)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
}
|
||||
} else {
|
||||
if (str.CompareNoCase("(1,1)")) {
|
||||
if (_str.CompareNoCase("(1,1)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("(1)")) {
|
||||
} else if (_str.CompareNoCase("(1)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("(1,0)")) {
|
||||
} else if (_str.CompareNoCase("(1,0)")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("(0,1)")) {
|
||||
} else if (_str.CompareNoCase("(0,1)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("(0,0)")) {
|
||||
} else if (_str.CompareNoCase("(0,0)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("(0)")) {
|
||||
} else if (_str.CompareNoCase("(0)")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (str.StartWith("t")) {
|
||||
if (str.CompareNoCase("true,true")) {
|
||||
if (_str.StartWith("t")) {
|
||||
if (_str.CompareNoCase("true,true")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("true,false")) {
|
||||
} else if (_str.CompareNoCase("true,false")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("true")) {
|
||||
} else if (_str.CompareNoCase("true")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
}
|
||||
} else if (str.StartWith("f")) {
|
||||
if (str.CompareNoCase("false,true")) {
|
||||
} else if (_str.StartWith("f")) {
|
||||
if (_str.CompareNoCase("false,true")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("false,false")) {
|
||||
} else if (_str.CompareNoCase("false,false")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("false")) {
|
||||
} else if (_str.CompareNoCase("false")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
}
|
||||
} else {
|
||||
if (str.CompareNoCase("1,1")) {
|
||||
if (_str.CompareNoCase("1,1")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("1")) {
|
||||
} else if (_str.CompareNoCase("1")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("1,0")) {
|
||||
} else if (_str.CompareNoCase("1,0")) {
|
||||
m_floats[0] = true;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("0,1")) {
|
||||
} else if (_str.CompareNoCase("0,1")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = true;
|
||||
} else if (str.CompareNoCase("0,0")) {
|
||||
} else if (_str.CompareNoCase("0,0")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
} else if (str.CompareNoCase("0")) {
|
||||
} else if (_str.CompareNoCase("0")) {
|
||||
m_floats[0] = false;
|
||||
m_floats[1] = false;
|
||||
}
|
||||
@ -145,54 +157,87 @@ namespace etk {
|
||||
}
|
||||
}
|
||||
|
||||
template<> Vector2D<int32_t>::Vector2D(const etk::UString& str)
|
||||
template<> Vector2D<int32_t>::operator etk::UString(void) const
|
||||
{
|
||||
etk::UString str;
|
||||
str = "(";
|
||||
str += x();
|
||||
str += ",";
|
||||
str += y();
|
||||
str += ")";
|
||||
return str;
|
||||
}
|
||||
|
||||
template<> Vector2D<int32_t>::Vector2D(const etk::UString& _str)
|
||||
{
|
||||
m_floats[0] = 0;
|
||||
m_floats[1] = 0;
|
||||
if (str.StartWith("(")) {
|
||||
if (_str.StartWith("(")) {
|
||||
int32_t val1=0;
|
||||
int32_t val2=0;
|
||||
sscanf(str.c_str(), "(%d,%d)", &val1, &val2);
|
||||
sscanf(_str.c_str(), "(%d,%d)", &val1, &val2);
|
||||
m_floats[0] = val1;
|
||||
m_floats[1] = val2;
|
||||
} else {
|
||||
int32_t val1=0;
|
||||
int32_t val2=0;
|
||||
sscanf(str.c_str(), "%d,%d", &val1, &val2);
|
||||
sscanf(_str.c_str(), "%d,%d", &val1, &val2);
|
||||
m_floats[0] = val1;
|
||||
m_floats[1] = val2;
|
||||
}
|
||||
}
|
||||
|
||||
template<> Vector2D<uint32_t>::Vector2D(const etk::UString& str)
|
||||
template<> Vector2D<uint32_t>::operator etk::UString(void) const
|
||||
{
|
||||
etk::UString str;
|
||||
str = "(";
|
||||
str += x();
|
||||
str += ",";
|
||||
str += y();
|
||||
str += ")";
|
||||
return str;
|
||||
}
|
||||
|
||||
template<> Vector2D<uint32_t>::Vector2D(const etk::UString& _str)
|
||||
{
|
||||
m_floats[0] = 0;
|
||||
m_floats[1] = 0;
|
||||
if (str.StartWith("(")) {
|
||||
if (_str.StartWith("(")) {
|
||||
int32_t val1=0;
|
||||
int32_t val2=0;
|
||||
sscanf(str.c_str(), "(%d,%d)", &val1, &val2);
|
||||
sscanf(_str.c_str(), "(%d,%d)", &val1, &val2);
|
||||
m_floats[0] = etk_max(0,val1);
|
||||
m_floats[1] = etk_max(0,val2);
|
||||
} else {
|
||||
int32_t val1=0;
|
||||
int32_t val2=0;
|
||||
sscanf(str.c_str(), "%d,%d", &val1, &val2);
|
||||
sscanf(_str.c_str(), "%d,%d", &val1, &val2);
|
||||
m_floats[0] = etk_max(0,val1);
|
||||
m_floats[1] = etk_max(0,val2);
|
||||
}
|
||||
}
|
||||
|
||||
template<> Vector2D<float>::Vector2D(const etk::UString& str)
|
||||
template<> Vector2D<float>::operator etk::UString(void) const
|
||||
{
|
||||
etk::UString str;
|
||||
str = "(";
|
||||
str += x();
|
||||
str += ",";
|
||||
str += y();
|
||||
str += ")";
|
||||
return str;
|
||||
}
|
||||
|
||||
template<> Vector2D<float>::Vector2D(const etk::UString& _str)
|
||||
{
|
||||
m_floats[0] = 0;
|
||||
m_floats[1] = 0;
|
||||
//TK_DEBUG("start parsing od vec2 with \"" << str << "\"");
|
||||
if (str.StartWith("(")) {
|
||||
if (_str.StartWith("(")) {
|
||||
//TK_DEBUG(" start with (");
|
||||
sscanf(str.c_str(), "(%f,%f)", &m_floats[0], &m_floats[1]);
|
||||
sscanf(_str.c_str(), "(%f,%f)", &m_floats[0], &m_floats[1]);
|
||||
} else {
|
||||
sscanf(str.c_str(), "%f,%f", &m_floats[0], &m_floats[1]);
|
||||
sscanf(_str.c_str(), "%f,%f", &m_floats[0], &m_floats[1]);
|
||||
}
|
||||
//TK_DEBUG(" result " << *this);
|
||||
}
|
||||
|
@ -363,15 +363,18 @@ namespace etk
|
||||
{
|
||||
return m_floats[0] == 0 && m_floats[1] == 0;
|
||||
}
|
||||
|
||||
//!< string cast :
|
||||
operator etk::UString(void) const;
|
||||
//etk::UString UString(void) const { return *this; };
|
||||
};
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human redeable information
|
||||
*/
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<int32_t> obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<float> obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<uint32_t> obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<bool> obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<int32_t>& obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<float>& obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<uint32_t>& obj);
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<bool>& obj);
|
||||
|
||||
|
||||
};
|
||||
// To siplify the writing of the code ==> this permit to have the same name with the glsl language...
|
||||
|
Loading…
x
Reference in New Issue
Block a user