[DEV] some code writing rework

This commit is contained in:
Edouard DUPIN 2013-07-26 08:49:20 +02:00
parent b9a79c1dfc
commit 3c27f446f4
16 changed files with 115 additions and 235 deletions

View File

@ -7,7 +7,6 @@
*/ */
#include <etk/Char.h> #include <etk/Char.h>
#include <etk/os/Memory.h>
etk::Char::Char(void) { etk::Char::Char(void) {

View File

@ -31,7 +31,7 @@ namespace etk
// nothing to do ... // nothing to do ...
}; };
bool Wait(MY_TYPE &data) bool Wait(MY_TYPE &_data)
{ {
m_mutex.Lock(); m_mutex.Lock();
// Check if data is not previously here // Check if data is not previously here
@ -43,7 +43,7 @@ namespace etk
// End Waiting message : // End Waiting message :
if (0<m_data.Size()) { if (0<m_data.Size()) {
// copy element : // copy element :
data = m_data[0]; _data = m_data[0];
// remove element : // remove element :
m_data.Erase(0); m_data.Erase(0);
// remove lock // remove lock
@ -52,13 +52,13 @@ namespace etk
} }
return false; return false;
}; };
bool Wait(MY_TYPE &data, uint32_t timeOutInUs) bool Wait(MY_TYPE &_data, uint32_t _timeOutInUs)
{ {
m_mutex.Lock(); m_mutex.Lock();
// Check if data is not previously here // Check if data is not previously here
while(0==m_data.Size()) { while(0==m_data.Size()) {
m_mutex.UnLock(); m_mutex.UnLock();
if (false == m_semaphore.Wait(timeOutInUs)) { if (false == m_semaphore.Wait(_timeOutInUs)) {
return false; return false;
} }
m_mutex.Lock(); m_mutex.Lock();
@ -66,7 +66,7 @@ namespace etk
// End Waiting message : // End Waiting message :
if (0<m_data.Size()) { if (0<m_data.Size()) {
// copy element : // copy element :
data = m_data[0]; _data = m_data[0];
// remove element : // remove element :
m_data.Erase(0); m_data.Erase(0);
// remove lock // remove lock
@ -82,10 +82,10 @@ namespace etk
m_mutex.UnLock(); m_mutex.UnLock();
return nbElement; return nbElement;
}; };
void Post(MY_TYPE &data) void Post(MY_TYPE &_data)
{ {
m_mutex.Lock(); m_mutex.Lock();
m_data.PushBack(data); m_data.PushBack(_data);
m_semaphore.Post(); m_semaphore.Post();
m_mutex.UnLock(); m_mutex.UnLock();
}; };

View File

@ -17,14 +17,14 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
etk::BaseNoise::BaseNoise(ivec2 size, float min, float max) : etk::BaseNoise::BaseNoise(ivec2 _size, float _min, float _max) :
m_data(size.x()*size.y()), m_data(_size.x()*_size.y()),
m_size(size) m_size(_size)
{ {
m_data.ReSize(size.x()*size.y(), 0); m_data.ReSize(_size.x()*_size.y(), 0);
for(int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) { for(int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
m_data[iii] = etk::tool::frand(min, max); m_data[iii] = etk::tool::frand(_min, _max);
} }
} }
@ -33,77 +33,77 @@ etk::BaseNoise::~BaseNoise(void)
} }
float etk::BaseNoise::Get(int32_t x, int32_t y) const float etk::BaseNoise::Get(int32_t _x, int32_t _y) const
{ {
// We increment of the size to prevent the <0 result due to the "%" methode ... // We increment of the size to prevent the <0 result due to the "%" methode ...
x += m_size.x(); _x += m_size.x();
y += m_size.y(); _y += m_size.y();
x %= m_size.x(); _x %= m_size.x();
y %= m_size.y(); _y %= m_size.y();
return m_data[x + y*m_size.x()]; return m_data[_x + _y*m_size.x()];
} }
float etk::Noise::smoothNoise(float x, float y, const etk::BaseNoise& noise) float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise)
{ {
//get fractional part of x and y //get fractional part of x and y
float fractX = x - (int32_t)x; float fractX = _x - (int32_t)_x;
float fractY = y - (int32_t)y; float fractY = _y - (int32_t)_y;
//wrap around //wrap around
int32_t x1 = (int32_t)x; int32_t x1 = (int32_t)_x;
int32_t y1 = (int32_t)y; int32_t y1 = (int32_t)_y;
//neighbor values //neighbor values
int32_t x2 = x1 - 1; int32_t x2 = x1 - 1;
int32_t y2 = y1 - 1; int32_t y2 = y1 - 1;
//smooth the noise with bilinear interpolation //smooth the noise with bilinear interpolation
float value = 0.0; float value = 0.0f;
value += fractX * fractY * noise.Get(x1,y1); value += fractX * fractY * _noise.Get(x1,y1);
value += fractX * (1 - fractY) * noise.Get(x1,y2); value += fractX * (1 - fractY) * _noise.Get(x1,y2);
value += (1 - fractX) * fractY * noise.Get(x2,y1); value += (1 - fractX) * fractY * _noise.Get(x2,y1);
value += (1 - fractX) * (1 - fractY) * noise.Get(x2,y2); value += (1 - fractX) * (1 - fractY) * _noise.Get(x2,y2);
return value; return value;
} }
float etk::Noise::turbulence(float x, float y, float size, const etk::BaseNoise& noise) float etk::Noise::turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise)
{ {
float value = 0.0f; float value = 0.0f;
float initialSize = size; float initialSize = _size;
while(1<=size) { while(1<=_size) {
value += smoothNoise(x / size, y / size, noise) * size; value += smoothNoise(_x / _size, _y / _size, _noise) * _size;
size /= 2.0; _size *= 0.5f;
} }
return(0.5f * value / initialSize); return(0.5f * value / initialSize);
// NOTE : with 128 here, we have wood ... // NOTE : with 128 here, we have wood ...
} }
float etk::Noise::turbulenceNoSmooth(float x, float y, float size, const etk::BaseNoise& noise) float etk::Noise::turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise)
{ {
float value = 0.0f; float value = 0.0f;
float initialSize = size; float initialSize = _size;
while(1<=size) { while(1<=_size) {
value += noise.Get(x / size, y / size) * size; value += _noise.Get(_x / _size, _y / _size) * _size;
size /= 2.0; _size *= 0.5f;
} }
return(0.5f * value / initialSize); return(0.5f * value / initialSize);
// NOTE : with 128 here, we have wood ... // NOTE : with 128 here, we have wood ...
} }
etk::Noise::Noise(noise_te type, ivec2 size, int32_t depth) : etk::Noise::Noise(noise_te _type, ivec2 _size, int32_t _depth) :
m_data(size.x()*size.y()), m_data(_size.x()*_size.y()),
m_size(size), m_size(_size),
m_type(type) m_type(_type)
{ {
m_data.ReSize(size.x()*size.y(), 0); m_data.ReSize(_size.x()*_size.y(), 0);
switch(m_type) { switch(m_type) {
default: default:
case etk::Noise::NOISE_BASE: case etk::Noise::NOISE_BASE:
{ {
etk::BaseNoise myNoise(ivec2(m_size.x()/depth,m_size.y()/depth),0.0f,1.0f); etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) { for(int32_t iii=0; iii<m_size.y(); iii++) {
for(int32_t jjj=0; jjj<m_size.x(); jjj++) { for(int32_t jjj=0; jjj<m_size.x(); jjj++) {
m_data[iii+jjj*m_size.x()] = myNoise.Get(iii,jjj); m_data[iii+jjj*m_size.x()] = myNoise.Get(iii,jjj);
@ -113,30 +113,30 @@ etk::Noise::Noise(noise_te type, ivec2 size, int32_t depth) :
break; break;
case etk::Noise::NOISE_SMOOTH: case etk::Noise::NOISE_SMOOTH:
{ {
etk::BaseNoise myNoise(ivec2(m_size.x()/depth,m_size.y()/depth),0.0f,1.0f); etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) { for(int32_t iii=0; iii<m_size.y(); iii++) {
for(int32_t jjj=0; jjj<m_size.x(); jjj++) { for(int32_t jjj=0; jjj<m_size.x(); jjj++) {
m_data[iii+jjj*m_size.x()] = smoothNoise((float)iii/(float)depth,(float)jjj/(float)depth, myNoise); m_data[iii+jjj*m_size.x()] = smoothNoise((float)iii/(float)_depth,(float)jjj/(float)_depth, myNoise);
} }
} }
} }
break; break;
case etk::Noise::NOISE_TURBULENCE: case etk::Noise::NOISE_TURBULENCE:
{ {
etk::BaseNoise myNoise(ivec2(m_size.x()/depth,m_size.y()/depth),0.0f,1.0f); etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) { for(int32_t iii=0; iii<m_size.y(); iii++) {
for(int32_t jjj=0; jjj<m_size.x(); jjj++) { for(int32_t jjj=0; jjj<m_size.x(); jjj++) {
m_data[iii+jjj*m_size.x()] = turbulence(iii,jjj,depth,myNoise); m_data[iii+jjj*m_size.x()] = turbulence(iii,jjj,_depth,myNoise);
} }
} }
} }
break; break;
case etk::Noise::NOISE_TURBULENCE_NO_SMOOTH: case etk::Noise::NOISE_TURBULENCE_NO_SMOOTH:
{ {
etk::BaseNoise myNoise(ivec2(m_size.x()/depth,m_size.y()/depth),0.0f,1.0f); etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) { for(int32_t iii=0; iii<m_size.y(); iii++) {
for(int32_t jjj=0; jjj<m_size.x(); jjj++) { for(int32_t jjj=0; jjj<m_size.x(); jjj++) {
m_data[iii+jjj*m_size.x()] = turbulenceNoSmooth(iii,jjj,depth,myNoise); m_data[iii+jjj*m_size.x()] = turbulenceNoSmooth(iii,jjj,_depth,myNoise);
} }
} }
} }
@ -159,13 +159,13 @@ etk::Noise::~Noise(void)
} }
float etk::Noise::Get(int32_t x, int32_t y) const float etk::Noise::Get(int32_t _x, int32_t _y) const
{ {
// We increment of the size to prevent the <0 result due to the "%" methode ... // We increment of the size to prevent the <0 result due to the "%" methode ...
x += m_size.x(); _x += m_size.x();
y += m_size.y(); _y += m_size.y();
x %= m_size.x(); _x %= m_size.x();
y %= m_size.y(); _y %= m_size.y();
return m_data[x + y*m_size.x()]; return m_data[_x + _y*m_size.x()];
} }

View File

@ -20,9 +20,9 @@ namespace etk {
etk::Vector<float> m_data; etk::Vector<float> m_data;
ivec2 m_size; ivec2 m_size;
public: public:
BaseNoise(ivec2 size, float min, float max); BaseNoise(ivec2 _size, float _min, float _max);
~BaseNoise(void); ~BaseNoise(void);
float Get(int32_t x, int32_t y) const; float Get(int32_t _x, int32_t _y) const;
}; };
class Noise class Noise
{ {
@ -40,13 +40,13 @@ namespace etk {
etk::Vector<float> m_data; etk::Vector<float> m_data;
ivec2 m_size; ivec2 m_size;
noise_te m_type; noise_te m_type;
float smoothNoise(float x, float y, const etk::BaseNoise& noise); float smoothNoise(float _x, float _y, const etk::BaseNoise& _noise);
float turbulence(float x, float y, float size, const etk::BaseNoise& noise); float turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise);
float turbulenceNoSmooth(float x, float y, float size, const etk::BaseNoise& noise); float turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise);
public: public:
Noise(noise_te type, ivec2 size, int32_t depth); Noise(noise_te _type, ivec2 _size, int32_t _depth);
~Noise(void); ~Noise(void);
float Get(int32_t x, int32_t y) const; float Get(int32_t _x, int32_t _y) const;
}; };
}; };

View File

@ -11,7 +11,6 @@
#include <etk/types.h> #include <etk/types.h>
#include <etk/DebugInternal.h> #include <etk/DebugInternal.h>
#include <etk/os/Memory.h>
#include <etk/UString.h> #include <etk/UString.h>
#include <etk/Vector.h> #include <etk/Vector.h>

View File

@ -7,7 +7,6 @@
*/ */
#include <etk/UString.h> #include <etk/UString.h>
#include <etk/os/Memory.h>
#include <etk/unicode.h> #include <etk/unicode.h>
#include <etk/Debug.h> #include <etk/Debug.h>

View File

@ -11,7 +11,6 @@
#include <etk/types.h> #include <etk/types.h>
#include <etk/DebugInternal.h> #include <etk/DebugInternal.h>
#include <etk/os/Memory.h>
#undef __class__ #undef __class__
#define __class__ "etk::Vector" #define __class__ "etk::Vector"

View File

@ -1,35 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/types.h>
#include <etk/os/Memory.h>
// General
#if ETK_MEMORY_CHECKER > 0
void etk::MemFree( void * pointerData, const char * variableName, const char * functionName, int32_t line, const char * fileName )
{
TK_CRITICAL(" MEM FREE is not written ==> TODO...");
if (NULL != pointerData) {
free(pointerData);
}
}
void * etk::MemMalloc( size_t num, size_t size, uint8_t init, const char * variableName, const char * functionName, int32_t line, const char * fileName )
{
TK_CRITICAL(" MEM ALLOCATOR is not written ==> TODO...");
return calloc(num, size);
}
void etk::MemShowLogs( void )
{
TK_CRITICAL(" MEM DISPLAY is not written ==> TODO...");
}
#endif

View File

@ -1,80 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_TOOLS_MEMORY_H__
#define __ETK_TOOLS_MEMORY_H__
#ifndef ETK_MEMORY_CHECKER
#define ETK_MEMORY_CHECKER 0
#endif
// General
#if ETK_MEMORY_CHECKER > 0
namespace etk {
void MemFree( void * pointerData, const char * variableName, const char * functionName, int32_t line, const char * fileName );
void * MemMalloc( size_t num, size_t size, uint8_t init, const char * variableName, const char * functionName, int32_t line, const char * fileName );
void MemShowLogs( void );
};
# define ETK_MALLOC(pointerData, nbElements, dataType) do { \
pointerData = (dataType *)etk::MemMalloc( (nbElements), sizeof(dataType), 0, #pointerData, __func__, __LINE__, __FILE__); \
}while(0)
# define ETK_MALLOC_CAST(pointerData, nbElements, dataType, cast) do { \
pointerData = (cast)etk::MemMalloc( (nbElements), sizeof(dataType), 0, #pointerData, __func__, __LINE__, __FILE__); \
}while(0)
# define ETK_CALLOC(pointerData, nbElements, dataType) do { \
pointerData = (dataType *)etk::MemMalloc( (nbElements), sizeof(dataType), 1, #pointerData, __func__, __LINE__, __FILE__); \
}while(0)
# define ETK_CALLOC_CAST(pointerData, nbElements, dataType, cast) do { \
pointerData = (cast)etk::MemMalloc( (nbElements), sizeof(dataType), 1, #pointerData, __func__, __LINE__, __FILE__); \
}while(0)
# define ETK_FREE(pointerData) do { \
etk::MemFree( (pointerData) , #pointerData, __func__, __LINE__, __FILE__); \
(pointerData) = NULL; \
}while(0)
# define ETK_MEM_SHOW_LOG() do { \
etk::MemShowLogs(); \
}while(0)
#else
# define ETK_MALLOC(pointerData, nbElements, dataType) do { \
(pointerData) = (dataType *)malloc( (nbElements) * sizeof(dataType) ); \
}while(0)
# define ETK_MALLOC_CAST(pointerData, nbElements, dataType, cast) do { \
(pointerData) = (cast)malloc( (nbElements) * sizeof(dataType) ); \
}while(0)
# define ETK_CALLOC(pointerData, nbElements, dataType) do { \
(pointerData) = (dataType *)calloc( (nbElements), sizeof(dataType) ); \
}while(0)
# define ETK_CALLOC_CAST(pointerData, nbElements, dataType, cast) do { \
(pointerData) = (cast)calloc( (nbElements), sizeof(dataType) ); \
}while(0)
# define ETK_REALLOC(pointerData, nbElements, dataType) do { \
(pointerData) = (dataType *)realloc( (pointerData), (nbElements)* sizeof(dataType) ); \
}while(0)
# define ETK_REALLOC_CAST(pointerData, nbElements, dataType, cast) do { \
(pointerData) = (cast)realloc( (pointerData), (nbElements) * sizeof(dataType) ); \
}while(0)
# define ETK_FREE(pointerData) do { \
free( pointerData ); \
(pointerData) = NULL; \
}while(0)
# define ETK_MEM_SHOW_LOG() do { \
TK_DEBUG("No Memory check availlable"); \
}while(0)
#endif
#endif

View File

@ -11,7 +11,7 @@
#include <etk/DebugInternal.h> #include <etk/DebugInternal.h>
#include <sys/time.h> #include <sys/time.h>
etk::Semaphore::Semaphore(uint32_t nbBasicElement, uint32_t nbMessageMax) etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax)
{ {
// create interface mutex : // create interface mutex :
int ret = pthread_mutex_init(&m_mutex, NULL); int ret = pthread_mutex_init(&m_mutex, NULL);
@ -23,8 +23,8 @@ etk::Semaphore::Semaphore(uint32_t nbBasicElement, uint32_t nbMessageMax)
ret = pthread_mutex_destroy(&m_mutex); ret = pthread_mutex_destroy(&m_mutex);
TK_ASSERT(ret == 0, "Error destroying Mutex ..."); TK_ASSERT(ret == 0, "Error destroying Mutex ...");
} }
m_maximum = nbMessageMax; m_maximum = _nbMessageMax;
m_data = nbBasicElement; m_data = _nbBasicElement;
} }
@ -72,7 +72,7 @@ void etk::Semaphore::Wait(void)
} }
bool etk::Semaphore::Wait(uint32_t timeOutInUs) bool etk::Semaphore::Wait(uint32_t _timeOutInUs)
{ {
pthread_mutex_lock(&m_mutex); pthread_mutex_lock(&m_mutex);
if(m_data == 0) { if(m_data == 0) {
@ -80,7 +80,7 @@ bool etk::Semaphore::Wait(uint32_t timeOutInUs)
struct timespec ts; struct timespec ts;
gettimeofday(&tp,NULL); gettimeofday(&tp,NULL);
uint64_t totalTimeUS = tp.tv_sec * 1000000 + tp.tv_usec; uint64_t totalTimeUS = tp.tv_sec * 1000000 + tp.tv_usec;
totalTimeUS += timeOutInUs; totalTimeUS += _timeOutInUs;
ts.tv_sec = totalTimeUS / 1000000; ts.tv_sec = totalTimeUS / 1000000;
ts.tv_nsec = (totalTimeUS%1000000) * 1000; ts.tv_nsec = (totalTimeUS%1000000) * 1000;
int ret = pthread_cond_timedwait(&m_condition, &m_mutex, &ts); int ret = pthread_cond_timedwait(&m_condition, &m_mutex, &ts);

View File

@ -9,10 +9,10 @@
#include <etk/os/Semaphore.h> #include <etk/os/Semaphore.h>
#include <etk/DebugInternal.h> #include <etk/DebugInternal.h>
etk::Semaphore::Semaphore(uint32_t nbBasicElement, uint32_t nbMessageMax) etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax)
{ {
// create interface mutex : // create interface mutex :
m_semaphore = CreateSemaphore(NULL, nbBasicElement, nbMessageMax, NULL); m_semaphore = CreateSemaphore(NULL, _nbBasicElement, _nbMessageMax, NULL);
TK_ASSERT(m_semaphore != 0, "Error creating SEMAPHORE ..."); TK_ASSERT(m_semaphore != 0, "Error creating SEMAPHORE ...");
} }
@ -41,9 +41,9 @@ void etk::Semaphore::Wait(void)
} }
bool etk::Semaphore::Wait(uint32_t timeOutInUs) bool etk::Semaphore::Wait(uint32_t _timeOutInUs)
{ {
DWORD result = WaitForSingleObject(m_semaphore, timeOutInUs); DWORD result = WaitForSingleObject(m_semaphore, _timeOutInUs);
if (result == WAIT_FAILED) { if (result == WAIT_FAILED) {
TK_ERROR("Failed to wait for semaphore "); TK_ERROR("Failed to wait for semaphore ");
return false; return false;

View File

View File

@ -31,13 +31,13 @@ namespace etk
uint32_t m_maximum; uint32_t m_maximum;
#endif #endif
public: public:
Semaphore(uint32_t nbBasicElement=0, uint32_t nbMessageMax=1); Semaphore(uint32_t _nbBasicElement=0, uint32_t _nbMessageMax=1);
~Semaphore(void); ~Semaphore(void);
uint32_t GetCount(void); uint32_t GetCount(void);
void Post(void); void Post(void);
void Wait(void); void Wait(void);
// wait with a timeout in us; return true if get the semaphore // wait with a timeout in us; return true if get the semaphore
bool Wait(uint32_t timeOutInUs); bool Wait(uint32_t _timeOutInUs);
}; };
}; };

View File

@ -14,42 +14,42 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
float etk::tool::frand(float a, float b) float etk::tool::frand(float _a, float _b)
{ {
return ( rand()/(float)RAND_MAX ) * (b-a) + a; return ( rand()/(float)RAND_MAX ) * (_b-_a) + _a;
} }
int32_t etk::tool::irand(int32_t a, int32_t b) int32_t etk::tool::irand(int32_t _a, int32_t _b)
{ {
return (int32_t)(( rand()/(float)RAND_MAX ) * ((float)b-(float)a) + (float)a); return (int32_t)(( rand()/(float)RAND_MAX ) * ((float)_b-(float)_a) + (float)_a);
} }
void etk::tool::SortList(etk::Vector<etk::UString *> &m_listDirectory) void etk::tool::SortList(etk::Vector<etk::UString *> &_list)
{ {
etk::Vector<etk::UString *> tmpList = m_listDirectory; etk::Vector<etk::UString *> tmpList = _list;
m_listDirectory.Clear(); _list.Clear();
for(int32_t iii=0; iii<tmpList.Size(); iii++) { for(int32_t iii=0; iii<tmpList.Size(); iii++) {
int32_t findPos = 0; int32_t findPos = 0;
for(int32_t jjj=0; jjj<m_listDirectory.Size(); jjj++) { for(int32_t jjj=0; jjj<_list.Size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\""); //EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (*tmpList[iii] > *m_listDirectory[jjj]) { if (*tmpList[iii] > *_list[jjj]) {
findPos = jjj+1; findPos = jjj+1;
} }
} }
//EWOL_DEBUG("position="<<findPos); //EWOL_DEBUG("position="<<findPos);
m_listDirectory.Insert(findPos, tmpList[iii]); _list.Insert(findPos, tmpList[iii]);
} }
} }
bool etk::tool::strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen) bool etk::tool::strnCmpNoCase(const char * _input1, const char * _input2, int32_t _maxLen)
{ {
int32_t iii=0; int32_t iii=0;
while ('\0' != *input1 && '\0' != *input2 && iii < maxLen) { while ('\0' != *_input1 && '\0' != *_input2 && iii < _maxLen) {
char in1 = *input1; char in1 = *_input1;
char in2 = *input2; char in2 = *_input2;
if (in1 != in2) { if (in1 != in2) {
if (in1 <= 'Z' && in1 >= 'A') { if (in1 <= 'Z' && in1 >= 'A') {
in1 = in1 - 'A' + 'a'; in1 = in1 - 'A' + 'a';
@ -62,53 +62,53 @@ bool etk::tool::strnCmpNoCase(const char * input1, const char * input2, int32_t
} }
} }
iii++; iii++;
input1++; _input1++;
input2++; _input2++;
} }
return true; return true;
} }
etk::UString etk::tool::SimplifyPath(etk::UString input) etk::UString etk::tool::SimplifyPath(etk::UString _input)
{ {
int32_t findStartPos = input.FindForward('/') + 1; int32_t findStartPos = _input.FindForward('/') + 1;
int32_t findPos = input.FindForward('/', findStartPos); int32_t findPos = _input.FindForward('/', findStartPos);
//TK_DEBUG("Siplify : \"" << input << "\""); //TK_DEBUG("Siplify : \"" << input << "\"");
int32_t preventBadCode = 0; int32_t preventBadCode = 0;
while (findPos!=-1) while (findPos!=-1)
{ {
//TK_DEBUG(" string=\"" << input << "\""); //TK_DEBUG(" string=\"" << input << "\"");
//TK_DEBUG(" '/' @" << findPos); //TK_DEBUG(" '/' @" << findPos);
if (input.Size()<findPos+1) { if (_input.Size()<findPos+1) {
// no more element ... // no more element ...
break; break;
} }
if( input[findPos+1] == '/' if( _input[findPos+1] == '/'
|| ( input[findPos+1] == '.' || ( _input[findPos+1] == '.'
&& input.Size()==findPos+2 )) { && _input.Size()==findPos+2 )) {
// cleane the element path // cleane the element path
input.Remove(findPos+1, 1); _input.Remove(findPos+1, 1);
//TK_DEBUG(" Remove // string=\"" << input << "\""); //TK_DEBUG(" Remove // string=\"" << input << "\"");
} else { } else {
if (input.Size()<findPos+2) { if (_input.Size()<findPos+2) {
// no more element ... // no more element ...
break; break;
} }
if( input[findPos+1] == '.' if( _input[findPos+1] == '.'
&& input[findPos+2] == '.') { && _input[findPos+2] == '.') {
// cleane the element path // cleane the element path
input.Remove(findStartPos, findPos+3 - findStartPos ); _input.Remove(findStartPos, findPos+3 - findStartPos );
//TK_DEBUG(" Remove xxx/.. string=\"" << input << "\""); //TK_DEBUG(" Remove xxx/.. string=\"" << input << "\"");
} else if( input[findPos+1] == '.' } else if( _input[findPos+1] == '.'
&& input[findPos+2] == '/') { && _input[findPos+2] == '/') {
// cleane the element path // cleane the element path
input.Remove(findPos+1, 2); _input.Remove(findPos+1, 2);
//TK_DEBUG(" Remove ./ string=\"" << input << "\""); //TK_DEBUG(" Remove ./ string=\"" << input << "\"");
} else { } else {
findStartPos = findPos+1; findStartPos = findPos+1;
} }
} }
findPos = input.FindForward('/', findStartPos); findPos = _input.FindForward('/', findStartPos);
preventBadCode++; preventBadCode++;
if (preventBadCode>5000) { if (preventBadCode>5000) {
TK_CRITICAL("ERROR when getting the small path ... this is loop prevention..."); TK_CRITICAL("ERROR when getting the small path ... this is loop prevention...");
@ -119,16 +119,16 @@ etk::UString etk::tool::SimplifyPath(etk::UString input)
// for the target that supported the Realpath system : // for the target that supported the Realpath system :
char buf[MAX_FILE_NAME]; char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME); memset(buf, 0, MAX_FILE_NAME);
char * ok = realpath(input.c_str(), buf); char * ok = realpath(_input.c_str(), buf);
if (!ok) { if (!ok) {
TK_ERROR("Error to get the real path"); TK_ERROR("Error to get the real path");
input = "/"; _input = "/";
} else { } else {
input = buf; _input = buf;
} }
#endif #endif
//TK_DEBUG(" ==> \"" << input << "\""); //TK_DEBUG(" ==> \"" << input << "\"");
return input; return _input;
} }

View File

@ -14,12 +14,12 @@
namespace etk { namespace etk {
namespace tool { namespace tool {
float frand(float a, float b); float frand(float _a, float _b);
int32_t irand(int32_t a, int32_t b); int32_t irand(int32_t _a, int32_t _b);
void SortList(etk::Vector<etk::UString *> &m_listDirectory); void SortList(etk::Vector<etk::UString *>& _list);
bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen); bool strnCmpNoCase(const char* _input1, const char* _input2, int32_t _maxLen);
etk::UString SimplifyPath(etk::UString input); etk::UString SimplifyPath(etk::UString _input);
}; };
}; };

View File

@ -25,7 +25,6 @@ def Create(target):
'etk/math/Vector3D.cpp', 'etk/math/Vector3D.cpp',
'etk/os/FSNode.cpp', 'etk/os/FSNode.cpp',
'etk/os/FSNodeRight.cpp', 'etk/os/FSNodeRight.cpp',
'etk/os/Memory.cpp',
'etk/archive/Archive.cpp', 'etk/archive/Archive.cpp',
'etk/archive/Zip.cpp']) 'etk/archive/Zip.cpp'])