Compare commits

...

25 Commits

Author SHA1 Message Date
53624b73e7 [DEV] add at the end the log of errored test 2019-08-18 12:39:06 +02:00
a03590d6fd [DEBUG] correct the line number in execption log 2019-08-18 12:38:18 +02:00
18876f0162 [DEV] buffer get data string 2019-07-26 22:26:47 +02:00
139fb3b758 [DEV] add external exec component 2019-07-26 22:26:21 +02:00
14d615358f [DEV] add find in parents 2019-07-26 22:15:45 +02:00
c679e8d486 [DEV] add capability to set a test not implemented 2019-07-26 22:14:38 +02:00
f4d16db62f [DEBUG] update new API of lutin log 2019-05-03 10:18:22 +02:00
d02adca39d [DEV] add allocation test in vector (in comment) 2019-04-01 21:53:48 +02:00
68e371d932 [DEV] update string basic implement 2019-04-01 21:53:08 +02:00
13b8c4bf75 [DEV] separate test string 2019-04-01 21:52:44 +02:00
258f7aca01 [DEV] add move in the provider files 2019-04-01 21:52:23 +02:00
1ed74db7a8 [DEV] correct quaternion 2019-04-01 21:51:57 +02:00
60ee77804c [DEBUG] remove unneeded logs 2018-10-30 22:04:48 +01:00
408a3745bd [DEV] add get binary directory 2018-10-30 22:04:32 +01:00
03c0b121e7 [DEBUG] correct treeNode removing 2018-10-30 22:04:06 +01:00
39a0476377 [DEBUG] coorect the interface of the filesystem ==> add absolute to prevent errors... 2018-10-24 22:53:08 +02:00
55a4e4b5f2 [DEV] other 2018-10-23 22:10:43 +02:00
669fb6968d [DEV] add copy and remove in URI interface 2018-10-23 22:10:21 +02:00
38829891c6 [DEV] add /= and += in the uri interface 2018-10-23 22:07:23 +02:00
c866bfe734 [DEV] add stream operator in io interface 2018-10-23 22:06:57 +02:00
088e9b1a2d [DEBUG] correct color interface 2018-10-23 22:06:27 +02:00
247ada05cb [DEV] update URI interface and Path 2018-10-09 23:06:37 +02:00
6b6c81844e [DEV] update for build URI 2018-09-29 21:58:19 +02:00
7d95093c36 [DEV] integrate the new interface of URI and file 2018-09-24 23:26:06 +02:00
232fb530db [DEBUG] add missing uri 2018-09-18 22:48:14 +02:00
57 changed files with 1670 additions and 139 deletions

View File

@ -20,6 +20,7 @@ static etk::Vector<etest::GenericTest*>& getListOfTest() {
}
static etk::String filterGroup;
static etk::String filterTest;
static bool showAtTheEnd = false;
void etest::unInit() {
@ -88,6 +89,30 @@ static void listAllTest() {
}
}
static void listAllTestError() {
int32_t count = 0;
for (auto &it: getListOfTest()) {
if (it->getError() == true) {
count++;
break;
}
}
if (count == 0) {
return;
}
ETEST_PRINT("List all error test:");
etk::Vector<etk::String> listGroup = getListGroup();
for (auto &itGroup: listGroup) {
for (auto &it: getListOfTest()) {
if (it->getTestGroup() == itGroup) {
if (it->getError() == true) {
ETEST_PRINT(" - " << itGroup << "." << it->getTestName());
}
}
}
}
}
void etest::init(int32_t _argc, const char** _argv) {
if (nbTimeInit > 0) {
nbTimeInit++;
@ -96,6 +121,7 @@ void etest::init(int32_t _argc, const char** _argv) {
}
nbTimeInit++;
elog::init(_argc, _argv, "etest");
//etk::initDefaultFolder("ewolApplNoName");
ETEST_INFO("ETEST system init (BEGIN) ");
for (int32_t iii=0; iii<_argc ; ++iii) {
@ -107,6 +133,7 @@ void etest::init(int32_t _argc, const char** _argv) {
ETEST_PRINT(" " << _argv[0] << " [options]");
ETEST_PRINT(" --etest-list List all test names");
ETEST_PRINT(" --etest-filter=XXX filter group or test: XXX or WWW.yyy");
ETEST_PRINT(" --etest-show Display at the end the list of test that fail");
}
ETEST_PRINT(" -h/--help: this help");
} else if (data == "--etest-list") {
@ -115,6 +142,9 @@ void etest::init(int32_t _argc, const char** _argv) {
} else if (data == "--etest-filter=") {
ETEST_PRINT("Missing data in the filter list...");
exit(0);
} else if (data == "--etest-show") {
ETEST_PRINT("Display all error test at the end ...");
showAtTheEnd = true;
} else if (data.startWith("--etest-filter=") == true) {
etk::String filter = &data[15];
ETEST_PRINT(" Filter: " << filter);
@ -176,6 +206,16 @@ uint32_t etest::GenericTest::getNumberCheckError() const {
return m_numberCheckFail;
}
uint32_t etest::GenericTest::getNumberCheckNotImplemented() const {
return m_numberCheckNotImplemented;
}
void etest::GenericTest::testNotImplemented(uint32_t _line) {
ETEST_ERROR("Not implemented: " << m_file << ":" << _line << ":");
m_haveError = true;
m_numberCheckNotImplemented++;
}
void etest::GenericTest::testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
@ -222,6 +262,7 @@ void etest::GenericTest::clearLocal() {
m_haveError = false;
m_numberCheck = 0;
m_numberCheckFail = 0;
m_numberCheckNotImplemented = 0;
}
etest::GenericTest* etest::g_currentTest = null;
@ -233,6 +274,7 @@ int32_t etest::runAllTest() {
echrono::Steady tic = echrono::Steady::now();
uint32_t nbTotalCheck = 0;
uint32_t nbTotalCheckFail = 0;
uint32_t nbTotalCheckNotImplemented = 0;
for (auto &itGroup: listGroup) {
int32_t count = 0;
for (auto &it: getListOfTest()) {
@ -243,6 +285,7 @@ int32_t etest::runAllTest() {
ETEST_PRINT("[++++++++++] " << count << " test from " << itGroup << ":");
uint32_t nbCheck = 0;
uint32_t nbCheckFail = 0;
uint32_t nbCheckNotImplemented = 0;
echrono::Steady ticGroup = echrono::Steady::now();
for (auto &it: runList) {
if (it->getTestGroup() != itGroup) {
@ -277,6 +320,7 @@ int32_t etest::runAllTest() {
}
nbCheck += it->getNumberCheck();
nbCheckFail += it->getNumberCheckError();
nbCheckNotImplemented += it->getNumberCheckNotImplemented();
}
#if ETK_MEMORY_CHECKER > 0
ETEST_DEBUG("[ MEM ] CHECK memory properties");
@ -295,16 +339,28 @@ int32_t etest::runAllTest() {
#endif
}
echrono::Steady tocGroup = echrono::Steady::now();
ETEST_PRINT("[++++++++++] " << count << " test [" << nbCheck << " check / " << nbCheckFail << " fails] from " << itGroup << " (" << (tocGroup - ticGroup) << ")");
etk::String notImplemented = "";
if (nbCheckNotImplemented != 0) {
notImplemented = " / " + etk::toString(nbCheckNotImplemented) + " Not Implemented";
}
ETEST_PRINT("[++++++++++] " << count << " test [" << nbCheck << " check / " << nbCheckFail << " fails " << notImplemented << "] from " << itGroup << " (" << (tocGroup - ticGroup) << ")");
nbTotalCheck += nbCheck;
nbTotalCheckFail += nbCheckFail;
nbTotalCheckNotImplemented += nbCheckNotImplemented;
}
echrono::Steady toc = echrono::Steady::now();
ETEST_PRINT("[==========] All done [" << nbTotalCheck << " check / " << nbTotalCheckFail << " fails] in " << (toc - tic));
etk::String notImplementedFull = "";
if (nbTotalCheckNotImplemented != 0) {
notImplementedFull = " / " + etk::toString(nbTotalCheckNotImplemented) + " Not Implemented";
}
ETEST_PRINT("[==========] All done [" << nbTotalCheck << " check / " << nbTotalCheckFail << " fails" << notImplementedFull << "] in " << (toc - tic));
if (errorCount != 0) {
ETEST_PRINT("[== FAIL ==] Have " << errorCount << " test fail ");
}
ETK_MEM_SHOW_LOG();
if (showAtTheEnd == true) {
listAllTestError();
}
return -errorCount;
}

View File

@ -104,6 +104,7 @@ namespace etest {
protected:
uint32_t m_numberCheck;
uint32_t m_numberCheckFail;
uint32_t m_numberCheckNotImplemented;
public:
GenericTest(const char* _file,
uint32_t _line,
@ -129,9 +130,15 @@ namespace etest {
* @return simple count of test done with error
*/
uint32_t getNumberCheckError() const;
/**
* @brief Get the number of check marked as not implemented
* @return simple count of test not implemented with error
*/
uint32_t getNumberCheckNotImplemented() const;
void addCheck() {
m_numberCheck++;
}
void testNotImplemented(uint32_t _line);
void testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
@ -172,6 +179,14 @@ namespace etest {
#define RUN_ALL_TESTS etest::runAllTest
#define TEST_NOT_IMPLEMENTED() \
do { \
etest::g_currentTest->addCheck(); \
etest::g_currentTest->testNotImplemented(__LINE__); \
/* Force exit of the function */ \
return; \
} while (false)
#define EXPECT_EQ(element, result) \
do { \
try { \

View File

@ -7,15 +7,16 @@
#include <etk/Allocator.hpp>
#include <stdlib.h>
void* operator new (size_t size) {
return malloc(size);
void* operator new (size_t _size) {
void* data = malloc(_size);
return data;
}
void* operator new[] (size_t size) {
return malloc(size);
void* operator new[] (size_t _size) {
void* data = malloc(_size);
return data;
}
void operator delete (void* ptr) {
free(ptr);
}
@ -768,6 +769,14 @@ void* etk::memory::allocate(size_t _num,
const char* _functionName,
int32_t _line,
const char* _fileName) {
/*
if ( (_num * _size ) > 100*1024*1024) {
printf("-------------------------------------------------------------------------------------------\n");
printf("== %s:%d %s %s\n", _fileName, _fileName, _functionName, _variableName);
printf("-------------------------------------------------------------------------------------------\n");
assert(false);
}
*/
return getHandle().allocate(_num, _size, _variableName, _functionName, _line, _fileName);
}

View File

@ -17,7 +17,7 @@
}
#endif
//#define ETK_MEMORY_CHECKER 0
//#define ETK_MEMORY_CHECKER 2
#ifndef ETK_MEMORY_CHECKER
#define ETK_MEMORY_CHECKER 0

View File

@ -71,7 +71,7 @@ etk::String etk::Exception::toString() const {
out += " in ";
out += m_file;
out += ":";
out += m_line;
out += etk::toString(m_line);
}
out += "}";
return out;

View File

@ -25,7 +25,7 @@ etk::String::String():
//printf("size of string=%ld %ld %ld\n", uint64_t(sizeof(etk::String)), m_sizeLocal, uint64_t(sizeof(etk::Vector<char>)));
memset(m_localData, 0, sizeof(m_localData));
#else
//m_data.resize(1, '\0');
m_data.resize(1, '\0');
#endif
}
@ -401,6 +401,7 @@ const etk::String::Iterator etk::String::end() const {
void etk::String::resize(size_t _newSize, char _value) {
if (_newSize == 0) {
m_data.clear();
m_data.resize(1, '\0');
return;
}
size_t oldSize = m_data.size();

View File

@ -23,15 +23,13 @@ namespace etk {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the string
String* m_string; //!< Pointer on the current element of the string
size_t m_current = 0; //!< current Id on the string
String* m_string = null; //!< Pointer on the current element of the string
public:
/**
* @brief Basic iterator constructor with no link with an etk::String
*/
Iterator():
m_current(0),
m_string(null) {
Iterator() {
// nothing to do ...
}
/**

View File

@ -312,14 +312,19 @@ const etk::UString::Iterator etk::UString::begin() const {
}
etk::UString::Iterator etk::UString::end() {
return position( size()-1 );
return position( size() );
}
const etk::UString::Iterator etk::UString::end() const {
return position( size()-1 );
return position( size() );
}
void etk::UString::resize(size_t _newSize, char32_t _value) {
if (_newSize == 0) {
m_data.clear();
m_data.resize(1, '\0');
return;
}
size_t oldSize = m_data.size();
if (oldSize != 0) {
m_data[m_data.size()-1] = _value;

View File

@ -19,15 +19,13 @@ namespace etk {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the string
UString* m_string; //!< Pointer on the current element of the stringBin
size_t m_current = 0; //!< current Id on the string
UString* m_string = null; //!< Pointer on the current element of the stringBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::UString
*/
Iterator():
m_current(0),
m_string(null) {
Iterator() {
// nothing to do ...
}
/**

View File

@ -9,6 +9,7 @@
//#include <etk/debug.hpp>
#include <etk/Stream.hpp>
#include <etk/Allocator.hpp>
//#include <etk/Exception.hpp>
//#include <etk/algorithm.hpp>
//#define ETK_VECTOR_DEBUG(...) printf(__VA_ARGS__)
@ -291,6 +292,11 @@ namespace etk {
m_data(null),
m_size(0),
m_allocated(0) {
/*
if (_obj.m_data == null) {
throw "Vector data whith nullptr data";
}
*/
reserve(_obj.m_size);
for(size_t iii=0; iii<_obj.m_size; iii++) {
new ((char*)&m_data[iii]) ETK_VECTOR_TYPE(etk::move(_obj.m_data[iii]));
@ -305,6 +311,11 @@ namespace etk {
m_data(_obj.m_data),
m_size(_obj.m_size),
m_allocated(_obj.m_allocated) {
/*
if (_obj.m_data == null) {
throw "Vector DAta whith nullptr data";
}
*/
_obj.m_data = null;
_obj.m_size = 0;
_obj.m_allocated = 0;
@ -335,6 +346,11 @@ namespace etk {
* @param[in] _obj second vector to swap data.
*/
void swap(etk::Vector<ETK_VECTOR_TYPE>& _obj) {
/*
if (_obj.m_data == null) {
throw "Vector data whith nullptr data";
}
*/
// avoid Swap of itself
if(this != &_obj) {
etk::swap(m_data, _obj.m_data);
@ -348,6 +364,11 @@ namespace etk {
* @return reference on the current re-copy vector
*/
Vector& operator=(etk::Vector<ETK_VECTOR_TYPE>&& _obj) {
/*
if (_obj.m_data == null) {
throw "Vector data whith nullptr data";
}
*/
if(this != &_obj) {
etk::swap(m_data, _obj.m_data);
etk::swap(m_allocated, _obj.m_allocated);
@ -362,6 +383,11 @@ namespace etk {
* @return reference on the current re-copy vector
*/
Vector& operator=(const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
/*
if (_obj.m_data == null) {
throw "Vector data whith nullptr data";
}
*/
// remove all previous elements
clear();
// Force a specicfic size
@ -378,6 +404,11 @@ namespace etk {
* @param[in] _obj Element to add at the end of vector
*/
Vector& operator+= (const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
/*
if (_obj.m_data == null) {
throw "Vector data whith nullptr data";
}
*/
reserve(m_size + _obj.size());
for(size_t iii=0; iii<_obj.size(); iii++) {
// copy operator ...
@ -850,6 +881,7 @@ namespace etk {
// check if something is allocated :
if (m_data == null) {
// no data allocated ==> request an allocation (might be the first)
//printf("Allocate : %d\n", int(sizeof(ETK_VECTOR_TYPE)*requestSize));
m_data = (ETK_VECTOR_TYPE*)ETK_MALLOC(char, sizeof(ETK_VECTOR_TYPE)*requestSize);
if (m_data == null) {
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );
@ -865,6 +897,12 @@ namespace etk {
#endif
} else {
// allocate a new pool of data:
/*
printf("Allocate : %d\n", int(sizeof(ETK_VECTOR_TYPE)*requestSize));
if ( int(sizeof(ETK_VECTOR_TYPE)*requestSize) > 33554432) {
throw "hello";
}
*/
ETK_VECTOR_TYPE* dataTmp = (ETK_VECTOR_TYPE*)ETK_MALLOC(char, sizeof(ETK_VECTOR_TYPE)*requestSize);;
if (dataTmp == null) {
//TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(ETK_VECTOR_TYPE)) << "bytes" );

30
etk-core/system.cpp Normal file
View File

@ -0,0 +1,30 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Exception.hpp>
#include <etk/system.hpp>
#include <stdio.h>
etk::String etk::exec(const etk::String& _cmd) {
FILE* pipe = popen(_cmd.c_str(), "r");
if (!pipe) {
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("popen() failed!"));
return "";
}
etk::String out;
try {
char buffer[128];
while (fgets(buffer, 128, pipe) != NULL) {
out += buffer;
}
} catch (...) {
pclose(pipe);
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("Broken pipe"));
}
pclose(pipe);
return out;
}

14
etk-core/system.hpp Normal file
View File

@ -0,0 +1,14 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#pragma once
namespace etk {
etk::String exec(const etk::String& _cmd);
}

View File

@ -129,6 +129,10 @@ etk::String u32char::convertToUtf8(const etk::UString& _input) {
return etk::toString(_input);
}
etk::String u32char::convertToUtf8(char32_t _input) {
return etk::toString(etk::UString(_input));
}
size_t u32char::strlen(const char32_t* _input) {
uint32_t out = 0;
while (*_input != 0) {
@ -193,7 +197,7 @@ char32_t u32char::toLower(char32_t _input) {
static uint8_t sizeElement(const char* _data, int32_t _lenMax) {
uint8_t size = 0;
uint8_t size = 1;
//TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
if (0 > _lenMax) {
return 0;

View File

@ -67,6 +67,7 @@ namespace u32char {
*/
int8_t convertUtf8(char32_t _val, char _output[7]);
etk::String convertToUtf8(const etk::UString& _input);
etk::String convertToUtf8(char32_t _input);
char32_t toUpper(char32_t _input);
char32_t toLower(char32_t _input);
size_t strlen(const char32_t* _input);

View File

@ -7,8 +7,10 @@
*/
#pragma once
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
#include <etk/io/File.hpp>
#include <etk/debug.hpp>
#include <string.h>
// minimum gapSize when allocated
#define GAP_SIZE_MIN (80)
@ -93,31 +95,40 @@ namespace etk {
* @return true if the data correctly stored
* @return false if an error occurred
*/
bool dumpIn(const etk::String& _file) {
etk::FSNode file(_file);
if (false == file.fileOpenWrite()) {
bool dumpIn(const etk::Path& _file) {
etk::io::File fileIO(_file);
if (fileIO.open(etk::io::OpenMode::Write) == false) {
return false;
}
bool ret = true;
// write Data
file.fileWrite(m_data, sizeof(int8_t), m_gapStart);
file.fileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd);
file.fileClose();
return ret;
fileIO.write(m_data, sizeof(int8_t), m_gapStart);
fileIO.write(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd);
fileIO.close();
return true;
}
/**
* @brief Get all data in a single string element
* @return the buffer in string
*/
etk::String getString() {
etk::String data;
data.resize(m_allocated - m_gapEnd + m_gapStart, ' ');
memcpy(&data[0], m_data, m_gapStart);
memcpy(&data[m_gapStart], &m_data[m_gapEnd], m_allocated - m_gapEnd);
return data;
}
/**
* @brief Load data from a selected file name.
* @param[in] _file Name of the file to store buffer data.
* @return true if the data correctly stored
* @return false if an error occurred
*/
bool dumpFrom(const etk::String& _file) {
etk::FSNode file(_file);
if (false == file.fileOpenRead()) {
bool dumpFrom(const etk::Path& _file) {
etk::io::File fileIO(_file);
if (fileIO.open(etk::io::OpenMode::Read) == false) {
return false;
}
bool ret = true;
int64_t length = file.fileSize();
int64_t length = fileIO.size();
// error case ...
if (length > 2000000000) {
return false;
@ -125,9 +136,10 @@ namespace etk {
// allocate the current buffer :
changeAllocation(length + GAP_SIZE_MIN);
// insert Data
int32_t nbReadData = file.fileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length);
int32_t nbReadData = fileIO.read(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length);
TK_INFO("load data : fileSize=" << length << ", readData=" << nbReadData);
// check ERROR
bool ret = true;
if (nbReadData != length) {
TK_ERROR("load data error: fileSize=" << length << ", readData=" << nbReadData);
ret = false;
@ -135,7 +147,7 @@ namespace etk {
// set the gap size at the buffer ...
m_gapStart = 0;
m_gapEnd = GAP_SIZE_MIN;
file.fileClose();
fileIO.close();
return ret;
}

View File

@ -34,6 +34,7 @@ static const ColorList* getColorList();
etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const etk::String& _input) {
TK_VERBOSE("parseStringStartWithSharp('" << _input << "'");
//elog::displayBacktrace(false, 0);
size_t len = _input.size();
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
if(len == 3) {

View File

@ -237,7 +237,7 @@ namespace etk {
if (tmp < 10) {
out += ('0'+tmp);
} else {
out += ('A'+tmp);
out += ('A'+tmp-10);
}
}
return out;

View File

@ -35,7 +35,8 @@ namespace etk {
if (_parent == m_parent.lock()) {
return;
}
if (m_parent != null) {
if ( m_parent != null
&& _parent != null) {
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("Set a treeNode parrent on an already used treeNode"));
}
m_parent = _parent;
@ -80,7 +81,7 @@ namespace etk {
auto it = m_childs.begin();
while (it != m_childs.end()) {
if (*it == _child) {
it->setParent(null);
(*it)->setParent(null);
m_childs.erase(it);
return;
}

View File

@ -47,6 +47,24 @@ ememory::SharedPtr<etk::ArchiveContent> etk::Archive::getContent(const etk::Path
bool etk::Archive::exist(const etk::Path& _key) const {
ethread::UniqueLock lock(m_mutex);
if (m_content.find(_key) != m_content.end()) {
return true;
}
return isDirectory(_key);
}
bool etk::Archive::isDirectory(const etk::Path& _key) const {
etk::String base = _key.getString() + "/";
for (auto &it: m_content) {
if (it.first.getString().startWith(base) == true) {
return true;
}
}
return false;
}
bool etk::Archive::isFile(const etk::Path& _key) const {
ethread::UniqueLock lock(m_mutex);
return m_content.find(_key) != m_content.end();
}
@ -186,5 +204,21 @@ etk::Vector<etk::Path> etk::Archive::list(const etk::Path& _path) {
}
return out;
}
etk::Vector<etk::Path> etk::Archive::listRecursive(const etk::Path& _path) {
etk::Vector<etk::Path> out;
etk::String base = _path.getString();
for (auto& it: m_content) {
etk::String name = it.first.getString();
if (name.size() < base.size()) {
continue;
}
if (etk::start_with(name, base) == true) {
// element or subElement...
out.pushBack(it.first);
}
}
return out;
}
#endif

View File

@ -20,7 +20,7 @@ namespace etk {
*/
class ArchiveContent {
private:
int32_t m_link; //!< number of element open on this file
int32_t m_link = 0; //!< number of element open on this file
public:
/**
* @brief Increment the number of user of this resource (permit to keep data alive)
@ -42,7 +42,7 @@ namespace etk {
return m_link;
}
private:
int32_t m_theoricSize; //!< Size set by the zip file (theoric ==> the data has not been read)
int32_t m_theoricSize = -1; //!< Size set by the zip file (theoric ==> the data has not been read)
public:
/**
* @brief Get the size of the element (size set by Zip file (not read))
@ -148,6 +148,20 @@ namespace etk {
* @return true if the file is present
*/
bool exist(const etk::Path& _key) const;
/**
* @brief Check if the path is a directory.
* @param[in] _key Name of the file
* @return true This is a directory.
* @return false This is something else...
*/
bool isDirectory(const etk::Path& _key) const;
/**
* @brief Check if the path is a file (regular).
* @param[in] _key Name of the file
* @return true This is a file.
* @return false This is something else...
*/
bool isFile(const etk::Path& _key) const;
/**
* @brief Load the specific file in the memory
* @param[in] _key Name of the file
@ -193,6 +207,12 @@ namespace etk {
* @return the full list of path in the _path.
*/
etk::Vector<etk::Path> list(const etk::Path& _path);
/**
* @brief List the content of a specific path.
* @param[in] Path to parse.
* @return the full list of path in the _path.
*/
etk::Vector<etk::Path> listRecursive(const etk::Path& _path);
};
}
#endif

View File

@ -14,7 +14,7 @@
#include <etk/theme/theme.hpp>
#include <etk/path/fileSystem.hpp>
#include <etk/uri/provider/provider.hpp>
#include <etk/uri/provider/ProviderFile.hpp>
static int32_t nbTimeInit = 0;
void etk::unInit() {
@ -50,6 +50,12 @@ void etk::init(int _argc, const char** _argv) {
}
elog::init(_argc, _argv, etk::path::getBinaryName());
etk::uri::provider::init();
// Add default elements for the DATA:/// USER_DATA:// TMP:// HOME://
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getDataPath()));
etk::uri::provider::add("USER_DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getHomePath() / ".local" / "share" / etk::path::getBinaryName()));
etk::uri::provider::add("CONFIG", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getHomePath() / ".config" / "share" / etk::path::getBinaryName()));
etk::uri::provider::add("CACHE", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getHomePath() / ".cache" / etk::path::getBinaryName()));
etk::uri::provider::add("TMP", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getTemporaryProcessPath()));
etk::theme::init();
for (int32_t iii=0; iii<_argc ; ++iii) {
etk::String data = _argv[iii];

View File

@ -39,6 +39,9 @@ bool etk::io::File::open(etk::io::OpenMode _mode) {
m_pointer = fopen(m_path.getNative().c_str(), "rb");
break;
case etk::io::OpenMode::Write:
if (etk::path::isDirectory(m_path.getParent().getNative()) == false) {
etk::path::makeDirectories(m_path.getParent().getNative());
}
m_pointer = fopen(m_path.getNative().c_str(), "wb");
break;
case etk::io::OpenMode::Append:
@ -67,6 +70,7 @@ bool etk::io::File::close() {
}
uint64_t etk::io::File::size() {
TK_VERBOSE(" file size= " << m_path.getNative());
return etk::path::fileSize(m_path);
}

View File

@ -26,6 +26,9 @@ namespace etk {
ETK_CONSTRUCTOR_COPY_DELETE(File);
ETK_CONSTRUCTOR_MOVE_DEFAULT(File);
public:
const etk::Path& getPath() {
return m_path;
}
bool open(etk::io::OpenMode _mode) override;
bool isOpen() override;
bool close() override;

View File

@ -23,7 +23,8 @@ bool etk::io::Interface::gets(etk::String& _output) {
_output += tmp;
tmp = get();
}
if (tmp == '\0') {
if ( tmp == '\0'
&& _output.isEmpty() == true) {
return false;
}
return true;
@ -42,3 +43,31 @@ bool etk::io::Interface::puts(const etk::String& _input) {
}
return false;
}
etk::io::Interface& etk::io::Interface::operator<< (const etk::Stream& _data) {
write(_data.c_str(), 1, _data.size());
return *this;
}
etk::io::Interface& etk::io::Interface::operator<< (const etk::String& _data) {
write(_data.c_str(), 1, _data.size());
return *this;
}
etk::io::Interface& etk::io::Interface::operator<< (const char* _data) {
write(_data, 1, strlen(_data));
return *this;
}
etk::io::Interface& etk::io::Interface::operator<< (const int32_t _data) {
etk::String sss = etk::toString(_data);
write(sss.c_str(), 1, sss.size());
return *this;
}
etk::io::Interface& etk::io::Interface::operator<< (const uint32_t _data) {
etk::String sss = etk::toString(_data);
write(sss.c_str(), 1, sss.size());
return *this;
}
etk::io::Interface& etk::io::Interface::operator<< (const float _data) {
etk::String sss = etk::toString(_data);
write(sss.c_str(), 1, sss.size());
return *this;
}

View File

@ -138,9 +138,26 @@ namespace etk {
* @param[in] _value String data to write in the File
* @return true the file is fully correcty write
*/
bool fileWriteAll(const etk::String& _value) {
bool writeAll(const etk::String& _value) {
return int64_t(_value.size()) == write(static_cast<const void*>(&(_value[0])), sizeof(char), _value.size()/sizeof(char));
}
/**
* @brief Stream write mode
* @param[in] _data Stream to write
* @return The current FSNode reference to add other stream.
* @note not stable API ...
*/
etk::io::Interface& operator<< (const etk::Stream& _data);
//! @copydoc etk::io::Interface::operator<<(const etk::Stringstream&)
etk::io::Interface& operator<< (const etk::String& _data);
//! @copydoc etk::io::Interface::operator<<(const etk::Stringstream&)
etk::io::Interface& operator<< (const char* _data);
//! @copydoc etk::io::Interface::operator<<(const etk::Stringstream&)
etk::io::Interface& operator<< (const int32_t _data);
//! @copydoc etk::io::Interface::operator<<(const etk::Stringstream&)
etk::io::Interface& operator<< (const uint32_t _data);
//! @copydoc etk::io::Interface::operator<<(const etk::Stringstream&)
etk::io::Interface& operator<< (const float _data);
};
}
}

View File

@ -25,6 +25,7 @@ bool etk::io::ZipFile::open(etk::io::OpenMode _mode) {
if (m_archive == null) {
return false;
}
m_offset = 0;
TK_VERBOSE(" Read file : " << m_path);
switch (_mode) {
case etk::io::OpenMode::Read:

View File

@ -21,7 +21,7 @@ namespace etk {
etk::Path m_path; //!< Path to access in this interface
ememory::SharedPtr<etk::Archive> m_archive; //!< Archive interface
ememory::SharedPtr<etk::ArchiveContent> m_content; //!< Data in the archive file
int32_t m_offset;
int32_t m_offset = 0;
public:
ZipFile(ememory::SharedPtr<etk::Archive> _archive);
ZipFile(const etk::Path& _path, ememory::SharedPtr<etk::Archive> _archive);

View File

@ -12,6 +12,7 @@ extern "C" {
}
#include <etk/math/Matrix3x3.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/debug.hpp>
namespace etk {
/**
@ -30,6 +31,20 @@ namespace etk {
m_floats[2] = 0.0f;
m_floats[3] = 0.0f;
}
/*
void checkValues() const {
if ( isinf(m_floats[0]) == true
|| isnan(m_floats[0]) == true
|| isinf(m_floats[1]) == true
|| isnan(m_floats[1]) == true
|| isinf(m_floats[2]) == true
|| isnan(m_floats[2]) == true
|| isinf(m_floats[3]) == true
|| isnan(m_floats[3]) == true) {
TK_CRITICAL(" set transform: (" << m_floats[0] << "," << m_floats[1] << "," << m_floats[2] << "," << m_floats[3] << ")");
}
}
*/
/**
* @brief Constructor from scalars.
* @param _xxx X value
@ -409,6 +424,7 @@ namespace etk {
m_floats[1] = m_floats[3] * _obj.m_floats[1] + _obj.m_floats[3] * m_floats[1] + crossValue.y();
m_floats[2] = m_floats[3] * _obj.m_floats[2] + _obj.m_floats[3] * m_floats[2] + crossValue.z();
m_floats[3] = m_floats[3] * _obj.m_floats[3] - base.dot(_obj.getVectorV());
safeNormalize();
return *this;
}
/**
@ -462,10 +478,10 @@ namespace etk {
* @param[in] _www W value.
*/
void setValue(const float& _xxx, const float& _yyy, const float& _zzz, const float& _www) {
m_floats[0]=_xxx;
m_floats[1]=_yyy;
m_floats[2]=_zzz;
m_floats[3]=_www;
m_floats[0] = _xxx;
m_floats[1] = _yyy;
m_floats[2] = _zzz;
m_floats[3] = _www;
}
/**
* @brief Set 0 value on all the quaternion

View File

@ -277,25 +277,61 @@ etk::String etk::Path::getFileName() const {
}
etk::String etk::Path::getExtention() const {
etk::String fileName = getFileName();
size_t pos = fileName.rfind('.');
size_t pos = m_data.rfind('.');
size_t posSlash = m_data.rfind('/');
if (pos == etk::String::npos) {
return "";
}
if (pos == 0) {
if ( posSlash != etk::String::npos
&& posSlash > pos) {
return "";
}
if ( pos == 0
|| ( posSlash != etk::String::npos
&& posSlash == pos-1
)
) {
// a simple name started with a .
return "";
}
return fileName.extract(pos+1);
return m_data.extract(pos+1);
}
void etk::Path::removeExtention() {
size_t pos = m_data.rfind('.');
size_t posSlash = m_data.rfind('/');
if (pos == etk::String::npos) {
return;
}
if ( posSlash != etk::String::npos
&& posSlash > pos) {
return;
}
if ( pos == 0
|| ( posSlash != etk::String::npos
&& posSlash == pos-1
)
) {
// a simple name started with a .
return;
}
m_data = m_data.extract(0, pos);
}
etk::Path etk::Path::getExtentionRemoved() const {
etk::Path tmp(*this);
tmp.removeExtention();
return tmp;
}
void etk::Path::parent() {
size_t pos = m_data.rfind('/');
if (pos == etk::String::npos) {
m_data = "";
return;
}
if (pos == 0) {
// Last root element ==> do nothing.
m_data = "/";
return;
}
m_data = m_data.extract(0, pos);
@ -354,6 +390,10 @@ etk::Path& etk::Path::operator/= (const etk::Path& _path) {
if (_path.m_data[0] == '/') {
ETK_THROW_EXCEPTION(etk::exception::InvalidArgument("add path that is absolute"));
}
if (m_data.isEmpty() == true){
m_data = _path.m_data;
return *this;
}
m_data += '/' + _path.m_data;
m_data = simplifyPath(m_data);
return *this;
@ -428,3 +468,24 @@ bool etk::operator<= (const Path& _left, const Path& _right) {
return _left.getString() <= _right.getString();
}
#include <etk/UString.hpp>
namespace etk {
template<> etk::String toString<etk::Path>(const etk::Path& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<etk::Path>(const etk::Path& _val) {
return toUString(_val.getString());
}
template<> bool from_string<etk::Path>(etk::Path& _variableRet, const etk::UString& _value) {
_variableRet = etk::Path(toString(_value));
return true;
}
#endif
template<> bool from_string<etk::Path >(etk::Path& _variableRet, const etk::String& _value) {
_variableRet = etk::Path(_value);
return true;
}
}

View File

@ -111,6 +111,15 @@ namespace etk {
* @return * extention of the file.
*/
etk::String getExtention() const;
/**
* @brief remove extention of the file (all after the last '.').
*/
void removeExtention();
/**
* @brief Get a copy with the extention of the file removed.
* @return a copy of the path without extention
*/
etk::Path getExtentionRemoved() const;
/**
* @brief remove the last child element of the path.
*/

View File

@ -30,28 +30,33 @@ extern "C" {
#include <etk/io/SeekMode.hpp>
bool etk::path::copy(const etk::Path& _path1, const etk::Path& _path2) {
TK_TODO("Not Implemented COPY of File : " << _path1 << " => " << _path2);
return false;
}
bool etk::path::copyDirectory(const etk::Path& _path1, const etk::Path& _path2, bool _recursive) {
TK_TODO("Not Implemented COPY of Directory : " << _path1 << " => " << _path2);
return false;
}
bool etk::path::copyFile(const etk::Path& _path1, const etk::Path& _path2) {
TK_TODO("Not Implemented COPY of File : " << _path1 << " => " << _path2);
return false;
}
bool etk::path::move(const etk::Path& _path1, const etk::Path& _path2) {
TK_VERBOSE("Move : \"" << _path1 << "\" ==> \"" << _path2 << "\"");
if (etk::path::exist(_path2) == true) {
removes(_path2);
etk::Path path1 = _path1.getAbsolute();
etk::Path path2 = _path2.getAbsolute();
TK_VERBOSE("Move : \"" << path1 << "\" ==> \"" << path2 << "\"");
if (etk::path::exist(path2) == true) {
removes(path2);
}
// create path to be sure it exist ...
etk::path::makeDirectories(_path2.getParent());
int32_t res = ::rename(_path1.getNative().c_str(), _path2.getNative().c_str());
etk::path::makeDirectories(path2.getParent());
int32_t res = ::rename(path1.getNative().c_str(), path2.getNative().c_str());
if (res != 0) {
TK_ERROR("Can not move the file: '" << _path1 << "' ==> '" << _path2 << "' errno" << errno << " (" << strerror(errno) << ")");
TK_ERROR("Can not move the file: '" << path1 << "' ==> '" << path2 << "' errno" << errno << " (" << strerror(errno) << ")");
return false;
}
return true;
@ -68,21 +73,23 @@ bool etk::path::moveFile(const etk::Path& _path1, const etk::Path& _path2) {
namespace detail {
bool removeDirectories(const etk::Path& _path, bool _recursive);
bool removes(const etk::Path& _path, bool _recursive) {
TK_VERBOSE("remove: " << _path);
if (etk::path::isDirectory(_path) == true) {
return detail::removeDirectories(_path, _recursive);
etk::Path path = _path.getAbsolute();
TK_VERBOSE("remove: " << path);
if (etk::path::isDirectory(path) == true) {
return detail::removeDirectories(path, _recursive);
}
return etk::path::removeFile(_path);
return etk::path::removeFile(path);
}
bool removeDirectories(const etk::Path& _path, bool _recursive) {
TK_VERBOSE("remove Directory: " << _path);
etk::Path path = _path.getAbsolute();
TK_VERBOSE("remove Directory: " << path);
if (_recursive == true) {
etk::Vector<etk::Path> elements = etk::path::list(_path);
etk::Vector<etk::Path> elements = etk::path::list(path);
for (auto& it : elements) {
detail::removes(it, _recursive);
}
}
if ( 0 != ::rmdir(_path.getNative().c_str()) ) {
if ( 0 != ::rmdir(path.getNative().c_str()) ) {
if (ENOTEMPTY == errno) {
TK_ERROR("The Directory is not empty...");
}
@ -109,26 +116,28 @@ bool etk::path::removeDirectories(const etk::Path& _path) {
}
bool etk::path::removeFile(const etk::Path& _path) {
TK_VERBOSE("remove File: " << _path);
if (0 != unlink(_path.getNative().c_str()) ) {
etk::Path path = _path.getAbsolute();
TK_VERBOSE("remove File: " << path);
if (0 != unlink(path.getNative().c_str()) ) {
return false;
}
return true;
}
bool etk::path::makeDirectory(const etk::Path& _path, etk::path::Permissions _permission) {
TK_VERBOSE("Make directory : " << _path << " perm: " << _permission);
if (etk::path::exist(_path) == true) {
etk::Path path = _path.getAbsolute();
TK_VERBOSE("Make directory : " << path << " perm: " << _permission);
if (etk::path::exist(path) == true) {
return true;
}
#ifdef __TARGET_OS__Windows
if (::mkdir(_path.getNative().c_str()) != 0
if (::mkdir(path.getNative().c_str()) != 0
&& errno != EEXIST) {
return false;
}
#else
mode_t mode = _permission.getRightValue();
if ( ::mkdir(_path.getNative().c_str(), mode) != 0
if ( ::mkdir(path.getNative().c_str(), mode) != 0
&& errno != EEXIST ) {
return false;
}
@ -137,11 +146,12 @@ bool etk::path::makeDirectory(const etk::Path& _path, etk::path::Permissions _pe
}
bool etk::path::makeDirectories(const etk::Path& _path, etk::path::Permissions _permission) {
TK_VERBOSE("Make dirrectories: " << _path << " perm: " << _permission);
if (etk::path::exist(_path) == true) {
etk::Path path = _path.getAbsolute();
TK_VERBOSE("Make dirrectories: " << path << " perm: " << _permission);
if (etk::path::exist(path) == true) {
return true;
}
auto elements = _path.getNative().split('/');
auto elements = path.getNative().split('/');
etk::Path pathToCreate;
if (elements[0].size() == 0) {
elements.popFront();
@ -186,6 +196,7 @@ bool etk::path::exist(const etk::Path& _path) {
uint64_t etk::path::fileSize(const etk::Path& _path) {
// Note : this is a proper methode to get the file size for Big files ... otherwithe the size is limited at 2^31 bytes
// tmpStat Buffer :
TK_VERBOSE(" file size of " << _path.getNative());
struct stat statProperty;
if (stat(_path.getNative().c_str(), &statProperty) == -1) {
//Normal case when the file does not exist ... ==> the it was in unknow mode ...
@ -232,6 +243,14 @@ bool etk::path::isSymLink(const etk::Path& _path) {
return true;
}
bool etk::path::haveChild(const etk::Path& _path) {
if (isDirectory(_path) == false) {
return false;
}
// TODO: do it better. it work, but is slow ...
return list(_path).size() != 0;
}
etk::path::Permissions etk::path::getPermission(const etk::Path& _path) {
etk::path::Permissions permissions;
@ -407,6 +426,10 @@ etk::Path etk::path::getBinaryPath() {
return out;
}
etk::Path etk::path::getBinaryDirectory() {
return getBinaryPath().getParent();
}
etk::String etk::path::getBinaryName() {
return getBinaryPath().getFileName();
}
@ -474,7 +497,62 @@ uint32_t etk::path::getIdGroup(const etk::Path& _path) {
return statProperty.st_gid;
}
etk::Vector<etk::Path> etk::path::list(const etk::Path& _path) {
etk::Vector<etk::Path> etk::path::list(const etk::Path& _path, uint32_t _flags) {
etk::Vector<etk::Path> out;
if (etk::path::isDirectory(_path) == false) {
return out;
}
DIR *dir = null;
struct dirent *ent = null;
TK_VERBOSE("List path: " << _path << " with flags: " << _flags);
TK_VERBOSE(" native=" << _path.getNative());
dir = opendir(_path.getNative().c_str());
if (dir != null) {
// for each element in the drectory...
while ((ent = readdir(dir)) != null) {
if( strcmp(ent->d_name, ".") == 0
|| strcmp(ent->d_name, "..") == 0
|| strlen(ent->d_name) == 0) {
// do nothing ...
continue;
}
TK_VERBOSE(" find=" << ent->d_name);
etk::Path tmpPath = _path / ent->d_name;
if (_flags == etk::path::LIST_ALL) {
out.pushBack(tmpPath);
continue;
}
// Hidden file
if ( ent->d_name[0] == '.'
&& (_flags & etk::path::LIST_HIDDEN) == 0) {
TK_VERBOSE(" ==> hidden");
continue;
}
// FOLDER
if (etk::path::isDirectory(tmpPath) == true) {
if ((_flags & etk::path::LIST_FOLDER) != 0) {
TK_VERBOSE(" ==> directory (add)");
out.pushBack(tmpPath);
} else {
TK_VERBOSE(" ==> directory");
}
continue;
}
// OTHER ==> clasify as file ==> 99.9999% of usage
if ((_flags & etk::path::LIST_FILE) != 0) {
TK_VERBOSE(" ==> file (add)");
out.pushBack(tmpPath);
}
}
closedir(dir);
} else {
TK_ERROR("could not open directory : '" << _path << "'");
}
return out;
}
etk::Vector<etk::Path> etk::path::listRecursive(const etk::Path& _path, uint32_t _flags) {
etk::Vector<etk::Path> out;
if (etk::path::isDirectory(_path) == false) {
return out;
@ -490,7 +568,37 @@ etk::Vector<etk::Path> etk::path::list(const etk::Path& _path) {
// do nothing ...
continue;
}
out.pushBack(_path / ent->d_name);
etk::Path tmpPath = _path / ent->d_name;
if (_flags == etk::path::LIST_ALL) {
out.pushBack(tmpPath);
if (etk::path::isDirectory(tmpPath) == true) {
for (auto& it: etk::path::listRecursive(tmpPath, _flags)) {
out.pushBack(it);
}
}
continue;
}
// Hidden file
if ( ent->d_name[0] == '.'
|| (_flags & etk::path::LIST_HIDDEN) == 0) {
continue;
}
// FOLDER
if (etk::path::isDirectory(tmpPath) == true) {
if ((_flags & etk::path::LIST_FOLDER) != 0) {
out.pushBack(tmpPath);
}
if (etk::path::isDirectory(tmpPath) == true) {
for (auto& it: etk::path::listRecursive(tmpPath, _flags)) {
out.pushBack(it);
}
}
continue;
}
// OTHER ==> clasify as file ==> 99.9999% of usage
if ((_flags & etk::path::LIST_FILE) != 0) {
out.pushBack(tmpPath);
}
}
closedir(dir);
} else {
@ -499,3 +607,15 @@ etk::Vector<etk::Path> etk::path::list(const etk::Path& _path) {
return out;
}
etk::Path etk::path::findInParent(const etk::Path& _path, const etk::String& _fileName) {
etk::Path base = _path;
while (base.getAbsolute() != "/") {
etk::Path tmp = base / _fileName;
if (etk::path::isFile(tmp) == true) {
return tmp;
}
base.parent();
}
return base;
}

View File

@ -36,7 +36,6 @@ namespace etk {
* @return false Operation Failed.
*/
bool copyFile(const etk::Path& _path1, const etk::Path& _path2);
/**
* @brief Move a path to an other (if possible...)
* @param[in] _path1 Path source.
@ -127,6 +126,7 @@ namespace etk {
bool exist(const etk::Path& _path);
/**
* @brief Get the File size
* @param[in] _path Path of the file
* @return the requested size
*/
uint64_t fileSize(const etk::Path& _path);
@ -151,6 +151,13 @@ namespace etk {
* @return false This is something else...
*/
bool isSymLink(const etk::Path& _path);
/**
* @brief check if the path have under file inside.
* @param[in] _path Path of the requested information.
* @return true This contain sub elements.
* @return false This is empty.
*/
bool haveChild(const etk::Path& _path);
/**
* @brief Get the relative string of the path.
* @param[in] _path Path to transform.
@ -214,10 +221,15 @@ namespace etk {
*/
etk::String getBinaryName();
/**
* @brief Full banary name (with root path).
* @brief Full binary name (with root path and binamary name).
* @return the binary absolute path.
*/
etk::Path getBinaryPath();
/**
* @brief Full binary name (with root path) ==> without executable name.
* @return the binary absolute path.
*/
etk::Path getBinaryDirectory();
/**
* @brief Get the data path of the application.
* @return the root path of the data for this application.
@ -259,12 +271,32 @@ namespace etk {
* @return Generic permission class.
*/
etk::path::Permissions getPermission(const etk::Path& _path);
enum {
LIST_HIDDEN = 1<<1,
LIST_FOLDER = 1<<2,
LIST_FILE = 1<<3,
LIST_ALL = LIST_HIDDEN|LIST_FOLDER|LIST_FILE,
};
/**
* @brief List the content of a specific path.
* @param[in] Path to parse.
* @return the full list of path in the _path.
*/
etk::Vector<etk::Path> list(const etk::Path& _path);
etk::Vector<etk::Path> list(const etk::Path& _path, uint32_t _flags=etk::path::LIST_ALL);
/**
* @brief List the content of a specific path (recursively).
* @param[in] _path Path to parse.
* @return the full list of path in the _path.
*/
etk::Vector<etk::Path> listRecursive(const etk::Path& _path, uint32_t _flags=etk::path::LIST_ALL);
/**
* @brief Find a filename in the parents directory of the path
* @param[in] _path Path to parse.
* @param[in] _fileName Name of the file we need to find
* @return the path of the file found
*/
etk::Path findInParent(const etk::Path& _path, const etk::String& _fileName);
}
}

172
etk/theme/ProviderTheme.cpp Normal file
View File

@ -0,0 +1,172 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/theme/ProviderTheme.hpp>
#include <etk/io/File.hpp>
#include <etk/path/fileSystem.hpp>
#include <etk/debug.hpp>
#include <etk/uri/uri.hpp>
etk::theme::ProviderTheme::ProviderTheme() {
}
etk::theme::ProviderTheme::ProviderTheme(const etk::Path& _offset, const etk::Path& _offsetDefault) :
m_offset(_offset),
m_offsetDefault(_offsetDefault) {
}
ememory::SharedPtr<etk::io::Interface> etk::theme::ProviderTheme::create(const etk::Uri& _uri) {
etk::Uri uri = _uri;
uri.setScheme("DATA");
TK_WARNING("Create URI file IO " << _uri);
if (m_offset.isEmpty() == true) {
TK_WARNING(" check " << uri);
if (etk::uri::exist(uri) == true) {
TK_WARNING(" ==> find");
return etk::uri::get(uri);
}
} else {
uri.setPath(m_offset / _uri.getPath());
TK_WARNING(" check " << uri);
if (etk::uri::exist(uri) == true) {
TK_WARNING(" ==> find");
return etk::uri::get(uri);
}
}
if ( m_offsetDefault.isEmpty() == false
&& m_offsetDefault != "theme") {
etk::Uri uri2 = uri;
uri2.setPath(m_offsetDefault / _uri.getPath());
TK_WARNING(" check " << uri2);
if (etk::uri::exist(uri2) == true) {
TK_WARNING(" ==> find");
return etk::uri::get(uri2);
}
}
TK_WARNING(" ** Find nothing ...");
return etk::uri::get(uri);
}
bool etk::theme::ProviderTheme::exist(const etk::Uri& _uri) {
etk::Uri uri = _uri;
uri.setScheme("DATA");
TK_WARNING("Exist URI file IO " << _uri);
if (m_offset.isEmpty() == true) {
TK_WARNING(" check " << uri);
if (etk::uri::exist(uri) == true) {
TK_WARNING(" ==> true");
return true;
}
} else {
uri.setPath(m_offset / _uri.getPath());
TK_WARNING(" check " << uri);
if (etk::uri::exist(uri) == true) {
TK_WARNING(" ==> true");
return true;
}
}
if ( m_offsetDefault.isEmpty() == false
&& m_offsetDefault != "theme") {
etk::Uri uri2 = uri;
uri2.setPath(m_offsetDefault / _uri.getPath());
TK_WARNING(" check " << uri2);
if (etk::uri::exist(uri2) == true) {
TK_WARNING(" ==> true");
return true;
}
}
TK_WARNING(" ** Find nothing ...");
return false;
}
bool etk::theme::ProviderTheme::isDirectory(const etk::Uri& _uri) {
// TODO:
throw "kjkjkj";
}
bool etk::theme::ProviderTheme::isFile(const etk::Uri& _uri) {
// TODO:
throw "kjkjkj";
}
bool etk::theme::ProviderTheme::isSymLink(const etk::Uri& _uri) {
// TODO:
throw "kjkjkj";
}
etk::Vector<etk::Uri> etk::theme::ProviderTheme::list(const etk::Uri& _uri) {
etk::Uri uri = _uri;
uri.setScheme("DATA");
etk::Vector<etk::Uri> directList;
if (m_offset.isEmpty() == true) {
directList = etk::uri::list(uri);
} else {
uri.setPath(m_offset / _uri.getPath());
directList = etk::uri::list(uri);
}
etk::Vector<etk::Uri> defaultList;
if ( m_offsetDefault.isEmpty() == false
&& m_offsetDefault != "theme") {
uri.setPath(m_offsetDefault / _uri.getPath());
defaultList = etk::uri::list(uri);
}
for (auto& it: defaultList) {
it.setScheme(_uri.getScheme());
}
for (auto& it: directList) {
it.setScheme(_uri.getScheme());
}
if (defaultList.size() == 0) {
return directList;
}
if (directList.size() == 0) {
return defaultList;
}
for (auto& it: defaultList) {
if (etk::isIn(it, directList) == false) {
directList.pushBack(it);
}
}
return directList;
}
etk::Vector<etk::Uri> etk::theme::ProviderTheme::listRecursive(const etk::Uri& _uri) {
etk::Uri uri = _uri;
uri.setScheme("DATA");
etk::Vector<etk::Uri> directList;
if (m_offset.isEmpty() == true) {
directList = etk::uri::listRecursive(uri);
} else {
uri.setPath(m_offset / _uri.getPath());
directList = etk::uri::listRecursive(uri);
}
etk::Vector<etk::Uri> defaultList;
if ( m_offsetDefault.isEmpty() == false
&& m_offsetDefault != "theme") {
uri.setPath(m_offsetDefault / _uri.getPath());
defaultList = etk::uri::listRecursive(uri);
}
for (auto& it: defaultList) {
it.setScheme(_uri.getScheme());
}
for (auto& it: directList) {
it.setScheme(_uri.getScheme());
}
if (defaultList.size() == 0) {
return directList;
}
if (directList.size() == 0) {
return defaultList;
}
for (auto& it: defaultList) {
if (etk::isIn(it, directList) == false) {
directList.pushBack(it);
}
}
return directList;
}

View File

@ -0,0 +1,30 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/uri/provider/provider.hpp>
namespace etk {
namespace theme {
class ProviderTheme : public etk::uri::provider::Interface {
protected:
etk::Path m_offset;
etk::Path m_offsetDefault;
public:
ProviderTheme();
ProviderTheme(const etk::Path& _offset, const etk::Path& _offsetDefault);
public:
ememory::SharedPtr<etk::io::Interface> create(const etk::Uri& _uri) override;
bool exist(const etk::Uri& _uri) override;
bool isDirectory(const etk::Uri& _uri) override;
bool isFile(const etk::Uri& _uri) override;
bool isSymLink(const etk::Uri& _uri) override;
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override;
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override;
};
}
}

View File

@ -5,20 +5,32 @@
*/
#include <etk/types.hpp>
#include <etk/theme/theme.hpp>
#include <etk/theme/ProviderTheme.hpp>
#include <etk/Map.hpp>
#include <etk/debug.hpp>
#include <etk/uri/uri.hpp>
static etk::Map<etk::String, etk::String>& getTheme() {
static etk::Map<etk::String, etk::String> g_listTheme;
static etk::Map<etk::String, etk::Path>& getTheme() {
static etk::Map<etk::String, etk::Path> g_listTheme;
return g_listTheme;
}
static etk::Map<etk::String, etk::String>& getThemeDefault() {
static etk::Map<etk::String, etk::String> g_listThemeDefault;
static etk::Map<etk::String, etk::Path>& getThemeDefault() {
static etk::Map<etk::String, etk::Path> g_listThemeDefault;
return g_listThemeDefault;
}
static void updateProvider(const etk::String& _refName) {
etk::Path base = etk::theme::getName(_refName);
etk::Path baseDefault = etk::theme::getNameDefault(_refName);
if (base.isEmpty() == true) {
etk::uri::provider::add("THEME_" + _refName, ememory::makeShared<etk::theme::ProviderTheme>(etk::Path("theme") / baseDefault, etk::Path("theme") / base));
} else {
etk::uri::provider::add("THEME_" + _refName, ememory::makeShared<etk::theme::ProviderTheme>(etk::Path("theme") / base, etk::Path("theme") / baseDefault));
}
}
void etk::theme::init() {
}
@ -28,17 +40,18 @@ void etk::theme::unInit() {
getThemeDefault().clear();
}
void etk::theme::setName(const etk::String& _refName, const etk::String& _folderName) {
void etk::theme::setName(const etk::String& _refName, const etk::Path& _folderName) {
TK_WARNING("Change theme : '" << _refName << "' : '" << _folderName << "'");
getTheme().set(_refName, _folderName);
updateProvider(_refName);
}
etk::String etk::theme::getName(const etk::String& _refName) {
etk::Path etk::theme::getName(const etk::String& _refName) {
auto it = getTheme().find(_refName);
if (it != getTheme().end()) {
return it->second;
}
return _refName;
return "";
}
// get the list of all the theme folder availlable in the user Home/appl
@ -50,16 +63,12 @@ etk::Vector<etk::String> etk::theme::list() {
return keys;
}
void etk::theme::setNameDefault(const etk::String& _refName, const etk::String& _folderName) {
auto it = getThemeDefault().find(_refName);
if (it != getThemeDefault().end()) {
it->second = _folderName;
return;
}
void etk::theme::setNameDefault(const etk::String& _refName, const etk::Path& _folderName) {
getThemeDefault().set(_refName, _folderName);
updateProvider(_refName);
}
etk::String etk::theme::getNameDefault(const etk::String& _refName) {
etk::Path etk::theme::getNameDefault(const etk::String& _refName) {
auto it = getThemeDefault().find(_refName);
if (it != getThemeDefault().end()) {
return it->second;

View File

@ -7,6 +7,7 @@
#include <etk/types.hpp>
#include <etk/Vector.hpp>
#include <etk/String.hpp>
#include <etk/path/Path.hpp>
#pragma once
@ -25,25 +26,25 @@ namespace etk {
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/")
*/
void setName(const etk::String& _refName, const etk::String& _folderName);
void setName(const etk::String& _refName, const etk::Path& _folderName);
/**
* @brief get the folder from a Reference theme
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @return the path of the theme
*/
etk::String getName(const etk::String& _refName);
etk::Path getName(const etk::String& _refName);
/**
* @brief Set the default folder of a subset of a theme ...
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @param[in] _folderName The associated default folder of the Theme (like "myTheme/color/default/")
*/
void setNameDefault(const etk::String& _refName, const etk::String& _folderName);
void setNameDefault(const etk::String& _refName, const etk::Path& _folderName);
/**
* @brief get the default folder from a Reference theme
* @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT"
* @return the path of the theme
*/
etk::String getNameDefault(const etk::String& _refName);
etk::Path getNameDefault(const etk::String& _refName);
/**
* @brief Get the list of all the theme folder availlable in the user Home/appl
* @return The list of elements

View File

@ -5,6 +5,8 @@
*/
#include <etk/uri/Query.hpp>
#include <etk/debug.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::uri::Query);
static const etk::String hexData = "0123456789ABCDEF";
@ -122,7 +124,7 @@ void etk::uri::Query::set(const etk::String& _key, const etk::String& _value) {
m_data.set(_key, _value);
}
bool etk::uri::Query::exist(const etk::String& _key) {
bool etk::uri::Query::exist(const etk::String& _key) const {
return m_data.exist(_key);
}

View File

@ -57,7 +57,7 @@ namespace etk {
* @return true Key exist.
* @return false Unknown key.
*/
bool exist(const etk::String& _key);
bool exist(const etk::String& _key) const;
/**
* @brief erase a specific key.
* @param[in] _key Key of the query.

View File

@ -6,6 +6,8 @@
#include <etk/uri/Uri.hpp>
#include <etk/debug.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::Uri);
etk::Uri::Uri() {
@ -274,6 +276,10 @@ const etk::uri::Query& etk::Uri::getQuery() const {
return m_query;
}
etk::uri::Query& etk::Uri::getQuery() {
return m_query;
}
void etk::Uri::setQuery(const etk::uri::Query& _value) {
m_query = _value;
}
@ -286,6 +292,73 @@ void etk::Uri::setFragment(const etk::String& _value) {
m_fragment = _value;
}
etk::Uri etk::Uri::operator/ (const etk::String& _element) const {
etk::Uri tmp = *this;
tmp /= etk::Path(_element);
return tmp;
}
etk::Uri etk::Uri::operator/ (const char* _element) const {
etk::Uri tmp = *this;
tmp /= etk::Path(_element);
return tmp;
}
etk::Uri etk::Uri::operator/ (const etk::Path& _path) const {
etk::Uri tmp = *this;
tmp /= _path;
return tmp;
}
etk::Uri& etk::Uri::operator/= (const etk::String& _element) {
*this /= etk::Path(_element);
return *this;
}
etk::Uri& etk::Uri::operator/= (const char* _element) {
*this /= etk::Path(_element);
return *this;
}
etk::Uri& etk::Uri::operator/= (const etk::Path& _path) {
m_path /= _path;
return *this;
}
etk::Uri etk::Uri::operator+ (const char* _element) const {
etk::Uri tmp = *this;
tmp += etk::Path(_element);
return tmp;
}
etk::Uri etk::Uri::operator+ (const etk::String& _element) const {
etk::Uri tmp = *this;
tmp += etk::Path(_element);
return tmp;
}
etk::Uri etk::Uri::operator+ (const etk::Path& _element) const {
etk::Uri tmp = *this;
tmp += _element;
return tmp;
}
etk::Uri& etk::Uri::operator+= (const char* _element) {
*this += etk::Path(_element);
return *this;
}
etk::Uri& etk::Uri::operator+= (const etk::String& _element) {
*this += etk::Path(_element);
return *this;
}
etk::Uri& etk::Uri::operator+= (const etk::Path& _element) {
m_path += _element;
return *this;
}
void etk::Uri::display() const {
TK_PRINT("Display of an URI:");
TK_PRINT(" m_scheme = '" << m_scheme << "'");
@ -298,3 +371,25 @@ void etk::Uri::display() const {
TK_PRINT(" m_fragment = '" << m_fragment << "'");
}
#include <etk/UString.hpp>
namespace etk {
template<> etk::String toString<etk::Uri>(const etk::Uri& _val) {
return _val.get();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<etk::Uri>(const etk::Uri& _val) {
return toUString(_val.get());
}
template<> bool from_string<etk::Uri>(etk::Uri& _variableRet, const etk::UString& _value) {
_variableRet = etk::Uri(toString(_value));
return true;
}
#endif
template<> bool from_string<etk::Uri >(etk::Uri& _variableRet, const etk::String& _value) {
_variableRet = etk::Uri(_value);
return true;
}
}

View File

@ -64,6 +64,8 @@ namespace etk {
* @return the uri correctly encoded
*/
etk::String get() const;
//! @previous
etk::String getString() const { return get(); }
/**
* @brief Get the scheme of the URI.
* @return Scheme value.
@ -129,6 +131,7 @@ namespace etk {
* @return query data.
*/
const etk::uri::Query& getQuery() const;
etk::uri::Query& getQuery();
/**
* @brief Set the new query.
* @param[in] _value Data.
@ -190,6 +193,38 @@ namespace etk {
* @return false : Greater Uri, true otherwise.
*/
bool operator>= (const etk::Uri& _obj) const;
/**
* @brief Add a subfolder on the current path.
* @param[in] _element sub folder or file to add.
* @return false : same path, true otherwise.
*/
Uri operator/ (const etk::String& _element) const;
//! @preivious
Uri& operator/= (const etk::String& _element);
//! @preivious
Uri operator/ (const char* _element) const;
//! @preivious
Uri& operator/= (const char* _element);
//! @preivious
Uri operator/ (const etk::Path& _element) const;
//! @preivious
Uri& operator/= (const etk::Path& _element);
/**
* @brief Add a subfolder on the current path.
* @param[in] _element sub folder or file to add.
* @return false : same path, true otherwise.
*/
Uri operator+ (const etk::String& _element) const;
//! @preivious
Uri& operator+= (const etk::String& _element);
//! @preivious
Uri operator+ (const char* _element) const;
//! @preivious
Uri& operator+= (const char* _element);
//! @preivious
Uri operator+ (const etk::Path& _element) const;
//! @preivious
Uri& operator+= (const etk::Path& _element);
/**
* @brief Detail display of this element
*/

View File

@ -0,0 +1,14 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/uri/provider/Interface.hpp>
uint64_t etk::uri::provider::Interface::fileSize(const etk::Uri& _uri) {
auto fileIO = create(_uri);
if (fileIO == null) {
return 0;
}
return fileIO->size();
}

View File

@ -23,10 +23,79 @@ namespace etk {
virtual ~Interface() = default;
public:
virtual ememory::SharedPtr<etk::io::Interface> create(const etk::Uri& _uri) = 0;
/**
* @brief Check if an URI really exist.
* @param[in] _uri Uri to check.
* @return true if exist, false ortherwise
*/
virtual bool exist(const etk::Uri& _uri) = 0;
/**
* @brief Check if the path is a directory.
* @param[in] _uri Uri to check.
* @return true This is a directory.
* @return false This is something else...
*/
virtual bool isDirectory(const etk::Uri& _uri) = 0;
/**
* @brief Check if the path is a file (regular).
* @param[in] _uri Uri to check.
* @return true This is a file.
* @return false This is something else...
*/
virtual bool isFile(const etk::Uri& _uri) = 0;
/**
* @brief check if the path is a symbolink link.
* @param[in] _uri Uri to check.
* @return true This is a synbolic link.
* @return false This is something else...
*/
virtual bool isSymLink(const etk::Uri& _uri) = 0;
/**
* @brief Get the File size
* @param[in] _uri URI of the file
* @return the requested size
*/
virtual uint64_t fileSize(const etk::Uri& _uri);
virtual etk::Vector<etk::Uri> list(const etk::Uri& _uri) = 0;
virtual etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) = 0;
/**
* @brief Check if an URI Can be moved.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
virtual bool canMove() { return false; }
/**
* @brief Move an element for a source to a destination.
* @param[in] _uriSource Source Uri.
* @param[in] _uriDestination Destination Uri.
* @return true if moved, false ortherwise
*/
virtual bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) { return false; }
/**
* @brief Check if an URI Can be copy.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
virtual bool canCopy() { return false; }
/**
* @brief Copy an element for a source to a destination.
* @param[in] _uriSource Source Uri.
* @param[in] _uriDestination Destination Uri.
* @return true if copied, false ortherwise
*/
virtual bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) { return false; }
/**
* @brief Check if an URI Can be removed.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
virtual bool canRemove() { return false; }
/**
* @brief Remove an element.
* @param[in] _uri Uri to remove.
* @return true if removed, false ortherwise
*/
virtual bool remove(const etk::Uri& _uri) { return false; }
};
}
}

View File

@ -31,6 +31,27 @@ bool etk::uri::provider::ProviderFile::exist(const etk::Uri& _uri) {
return etk::path::exist(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFile::isDirectory(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) {
return etk::path::isDirectory(_uri.getPath());
}
return etk::path::isDirectory(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFile::isFile(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) {
return etk::path::isFile(_uri.getPath());
}
return etk::path::isFile(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFile::isSymLink(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) {
return etk::path::isSymLink(_uri.getPath());
}
return etk::path::isSymLink(m_offset / _uri.getPath());
}
etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _uri) {
etk::Vector<etk::Path> tmp;
etk::Vector<etk::Uri> out;
@ -54,10 +75,69 @@ etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _ur
return out;
}
etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::listRecursive(const etk::Uri& _uri) {
etk::Vector<etk::Path> tmp;
etk::Vector<etk::Uri> out;
if (m_offset.isEmpty() == true) {
tmp = etk::path::listRecursive(_uri.getPath());
for (auto& elem: tmp) {
etk::Uri newUri = _uri;
newUri.setPath(elem);
out.pushBack(newUri);
}
return out;
}
TK_VERBOSE("list path: " << m_offset / _uri.getPath());
tmp = etk::path::listRecursive(m_offset / _uri.getPath());
int32_t offset = m_offset.getString().size()+1;
for (auto& elem: tmp) {
etk::Uri newUri = _uri;
newUri.setPath(elem.getString().extract(offset));
out.pushBack(newUri);
}
return out;
}
bool etk::uri::provider::ProviderFile::canMove() {
return true;
}
bool etk::uri::provider::ProviderFile::move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
return etk::path::move(_uriSource.getPath(), _uriDestination.getPath());
etk::Path pathSource =_uriSource.getPath();
if (m_offset.isEmpty() == false) {
pathSource = m_offset / _uriSource.getPath();
}
etk::Path pathDestination =_uriDestination.getPath();
if (m_offset.isEmpty() == false) {
pathDestination = m_offset / _uriDestination.getPath();
}
return etk::path::move(pathSource, pathDestination);
}
bool etk::uri::provider::ProviderFile::canCopy() {
return true;
}
bool etk::uri::provider::ProviderFile::copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
etk::Path pathSource =_uriSource.getPath();
if (m_offset.isEmpty() == false) {
pathSource = m_offset / _uriSource.getPath();
}
etk::Path pathDestination =_uriDestination.getPath();
if (m_offset.isEmpty() == false) {
pathDestination = m_offset / _uriDestination.getPath();
}
return etk::path::copy(pathSource, pathDestination);
}
bool etk::uri::provider::ProviderFile::canRemove() {
return true;
}
bool etk::uri::provider::ProviderFile::remove(const etk::Uri& _uri) {
etk::Path pathSource =_uri.getPath();
if (m_offset.isEmpty() == false) {
pathSource = m_offset / _uri.getPath();
}
return etk::path::remove(pathSource);
}

View File

@ -20,9 +20,17 @@ namespace etk {
public:
ememory::SharedPtr<etk::io::Interface> create(const etk::Uri& _uri) override;
bool exist(const etk::Uri& _uri) override;
bool isDirectory(const etk::Uri& _uri) override;
bool isFile(const etk::Uri& _uri) override;
bool isSymLink(const etk::Uri& _uri) override;
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override;
virtual bool canMove() override;
virtual bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override;
bool canMove() override;
bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
bool canCopy() override;
bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
bool canRemove() override;
bool remove(const etk::Uri& _uri) override;
};
}
}

View File

@ -38,6 +38,25 @@ bool etk::uri::provider::ProviderFileZip::exist(const etk::Uri& _uri) {
return m_archive->exist(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFileZip::isDirectory(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) {
return m_archive->isDirectory(_uri.getPath());
}
return m_archive->isDirectory(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFileZip::isFile(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) {
return m_archive->isFile(_uri.getPath());
}
return m_archive->isFile(m_offset / _uri.getPath());
}
bool etk::uri::provider::ProviderFileZip::isSymLink(const etk::Uri& _uri) {
// No symlink in ZIP ...
return false;
}
etk::Vector<etk::Uri> etk::uri::provider::ProviderFileZip::list(const etk::Uri& _uri) {
etk::Vector<etk::Path> tmp;
etk::Vector<etk::Uri> out;
@ -59,3 +78,25 @@ etk::Vector<etk::Uri> etk::uri::provider::ProviderFileZip::list(const etk::Uri&
}
return out;
}
etk::Vector<etk::Uri> etk::uri::provider::ProviderFileZip::listRecursive(const etk::Uri& _uri) {
etk::Vector<etk::Path> tmp;
etk::Vector<etk::Uri> out;
if (m_offset.isEmpty() == true) {
tmp = m_archive->listRecursive(_uri.getPath());
for (auto& elem: tmp) {
etk::Uri newUri = _uri;
newUri.setPath(elem);
out.pushBack(newUri);
}
return out;
}
tmp = m_archive->listRecursive(m_offset / _uri.getPath());
int32_t offset = m_offset.getString().size()+1;
for (auto& elem: tmp) {
etk::Uri newUri = _uri;
newUri.setPath(elem.getString().extract(offset));
out.pushBack(newUri);
}
return out;
}

View File

@ -25,7 +25,11 @@ namespace etk {
public:
ememory::SharedPtr<etk::io::Interface> create(const etk::Uri& _uri) override;
bool exist(const etk::Uri& _uri) override;
bool isDirectory(const etk::Uri& _uri) override;
bool isFile(const etk::Uri& _uri) override;
bool isSymLink(const etk::Uri& _uri) override;
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override;
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override;
};
}
}

View File

@ -21,27 +21,37 @@ namespace etk {
}
}
static void displayProviders() {
TK_INFO("List all datat provider:");
for (auto& it: etk::uri::provider::getProviders()) {
TK_INFO(" - " << it.first);
}
}
void etk::uri::provider::add(const etk::String& _scheme, ememory::SharedPtr<etk::uri::provider::Interface> _interface) {
etk::String scheme = _scheme;
if (scheme.empty() == true) {
scheme = "RAW";
scheme = "FILE";
}
etk::uri::provider::getProviders().set(scheme, _interface);
displayProviders();
}
void etk::uri::provider::clear() {
etk::uri::provider::getProviders().clear();
etk::uri::provider::add("", ememory::makeShared<etk::uri::provider::ProviderFile>());
displayProviders();
}
void etk::uri::provider::remove(const etk::String& _scheme) {
etk::uri::provider::getProviders().erase(_scheme);
displayProviders();
}
bool etk::uri::provider::exist(const etk::String& _scheme) {
etk::String scheme = _scheme;
if (scheme.empty() == true) {
scheme = "RAW";
scheme = "FILE";
}
return etk::uri::provider::getProviders().exist(scheme);
}
@ -49,7 +59,7 @@ bool etk::uri::provider::exist(const etk::String& _scheme) {
ememory::SharedPtr<etk::uri::provider::Interface> etk::uri::provider::getProvider(const etk::String& _scheme) {
etk::String scheme = _scheme;
if (scheme.empty() == true) {
scheme = "RAW";
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return null;

233
etk/uri/uri.cpp Normal file
View File

@ -0,0 +1,233 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/uri/provider/provider.hpp>
#include <etk/uri/provider/ProviderFile.hpp>
#include <etk/Map.hpp>
#include <etk/io/File.hpp>
#include <etk/uri/uri.hpp>
#include <etk/debug.hpp>
namespace etk {
namespace uri {
namespace provider {
etk::Map<etk::String, ememory::SharedPtr<etk::uri::provider::Interface>>& getProviders();
}
}
}
bool etk::uri::exist(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->exist(_uri);
}
bool etk::uri::isDirectory(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->isDirectory(_uri);
}
bool etk::uri::isFile(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->isFile(_uri);
}
bool etk::uri::isSymLink(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->isSymLink(_uri);
}
uint64_t etk::uri::fileSize(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return 0;
}
return etk::uri::provider::getProviders()[scheme]->fileSize(_uri);
}
etk::Vector<etk::Uri> etk::uri::list(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return etk::Vector<etk::Uri>();
}
return etk::uri::provider::getProviders()[scheme]->list(_uri);
}
etk::Vector<etk::Uri> etk::uri::listRecursive(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return etk::Vector<etk::Uri>();
}
return etk::uri::provider::getProviders()[scheme]->listRecursive(_uri);
}
ememory::SharedPtr<etk::io::Interface> etk::uri::get(const etk::Uri& _uri) {
TK_WARNING("uri get: " << _uri);
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
TK_ERROR("lklklk " << scheme << " " << _uri << " " << etk::uri::provider::getProviders().getKeys());
return null;
}
if (_uri.getPath().getString().size() == 0) {
TK_WARNING("uri:" << _uri << " Have NO path");
}
return etk::uri::provider::getProviders()[scheme]->create(_uri);
}
bool etk::uri::canMove(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->canMove();
}
bool etk::uri::move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
etk::String scheme = _uriSource.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
etk::String scheme2 = _uriDestination.getScheme();
if (scheme2.empty() == true) {
scheme2 = "FILE";
}
if (scheme != scheme2) {
TK_ERROR("Can not move 2 uri between 2 model of resource... " << _uriSource << " => " << _uriDestination);
return false;
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
if (etk::uri::provider::getProviders()[scheme]->canMove() == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->move(_uriSource, _uriDestination);
}
bool etk::uri::canCopy(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->canCopy();
}
bool etk::uri::copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
etk::String scheme = _uriSource.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
etk::String scheme2 = _uriDestination.getScheme();
if (scheme2.empty() == true) {
scheme2 = "FILE";
}
if (scheme != scheme2) {
TK_ERROR("Can not copy 2 uri between 2 model of resource... " << _uriSource << " => " << _uriDestination);
return false;
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
if (etk::uri::provider::getProviders()[scheme]->canCopy() == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->copy(_uriSource, _uriDestination);
}
bool etk::uri::canRemove(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->canRemove();
}
bool etk::uri::remove(const etk::Uri& _uri) {
etk::String scheme = _uri.getScheme();
if (scheme.empty() == true) {
scheme = "FILE";
}
if (etk::uri::provider::getProviders().exist(scheme) == false) {
return false;
}
if (etk::uri::provider::getProviders()[scheme]->canRemove() == false) {
return false;
}
return etk::uri::provider::getProviders()[scheme]->remove(_uri);
}
bool etk::uri::writeAll(const etk::Uri& _uri, const etk::String& _data) {
auto fileIo = etk::uri::get(_uri);
if (fileIo == null) {
TK_ERROR("Can not create the uri: " << _uri);
return false;
}
if (fileIo->open(etk::io::OpenMode::Write) == false) {
TK_ERROR("Can not open (w) the file : " << _uri);
return false;
}
fileIo->writeAll(_data);
fileIo->close();
return true;
}
bool etk::uri::readAll(const etk::Uri& _uri, etk::String& _data) {
auto fileIo = etk::uri::get(_uri);
if (fileIo == null) {
TK_ERROR("Can not create the uri: " << _uri);
return false;
}
if (fileIo->open(etk::io::OpenMode::Read) == false) {
TK_ERROR("Can not open (w) the file : " << _uri);
return false;
}
_data = fileIo->readAllString();
fileIo->close();
return true;
}

123
etk/uri/uri.hpp Normal file
View File

@ -0,0 +1,123 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etk/Map.hpp>
#include <etk/uri/Query.hpp>
#include <etk/path/Path.hpp>
#include <etk/uri/Uri.hpp>
#include <etk/uri/provider/provider.hpp>
namespace etk {
namespace uri {
/**
* @brief Check if an URI really exist.
* @param[in] _uri Uri to check.
* @return true if exist, false ortherwise
*/
bool exist(const etk::Uri& _uri);
/**
* @brief Check if the path is a directory.
* @param[in] _uri Uri to check.
* @return true This is a directory.
* @return false This is something else...
*/
bool isDirectory(const etk::Uri& _uri);
/**
* @brief Check if the path is a file (regular).
* @param[in] _uri Uri to check.
* @return true This is a file.
* @return false This is something else...
*/
bool isFile(const etk::Uri& _uri);
/**
* @brief check if the path is a symbolink link.
* @param[in] _uri Uri to check.
* @return true This is a synbolic link.
* @return false This is something else...
*/
bool isSymLink(const etk::Uri& _uri);
/**
* @brief Get the File size
* @param[in] _uri URI of the file
* @return the requested size
*/
uint64_t fileSize(const etk::Uri& _uri);
/**
* @brief Get the list of sub-element in the Uri
* @param[in] _uri Uri requested as parent.
* @return list of sub-uri
*/
etk::Vector<etk::Uri> list(const etk::Uri& _uri);
/**
* @brief Get the list of sub-element in the Uri reursively
* @param[in] _uri Uri requested as parent.
* @return list of sub-uri
*/
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri);
/**
* @brief Get an IO interface with a specific URI
* @param[in] _uri Data interface requested
* @return The interface requested.
*/
ememory::SharedPtr<etk::io::Interface> get(const etk::Uri& _uri);
/**
* @brief Check if an URI Can be moved.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
bool canMove(const etk::Uri& _uri);
/**
* @brief Move an element for a source to a destination.
* @param[in] _uriSource Source Uri.
* @param[in] _uriDestination Destination Uri.
* @return true if moved, false ortherwise
*/
bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination);
/**
* @brief Check if an URI Can be copy.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
bool canCopy(const etk::Uri& _uri);
/**
* @brief Copy an element for a source to a destination.
* @param[in] _uriSource Source Uri.
* @param[in] _uriDestination Destination Uri.
* @return true if copied, false ortherwise
*/
bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination);
/**
* @brief Check if an URI Can be removed.
* @param[in] _uri Uri to check.
* @return true if it is possible, false ortherwise
*/
bool canRemove(const etk::Uri& _uri);
/**
* @brief Remove an element.
* @param[in] _uri Uri to remove.
* @return true if removed, false ortherwise
*/
bool remove(const etk::Uri& _uri);
/**
* @brief Write all a string in a uri (if possible)
* @param[in] _uri Uri destination.
* @param[in] _data Data to write.
* @return true All data are write, false otherwise.
*/
bool writeAll(const etk::Uri& _uri, const etk::String& _data);
/**
* @brief Read all a string in a uri (if possible)
* @param[in] _uri Uri destination.
* @param[out] _data Data readed.
* @return true All data are read, false otherwise.
*/
bool readAll(const etk::Uri& _uri, etk::String& _data);
}
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
@ -37,6 +37,7 @@ def configure(target, my_module):
'etk-core/Allocator.cpp',
'etk-core/typeInfo.cpp',
'etk-core/Exception.cpp',
'etk-core/system.cpp',
])
my_module.add_header_file([
@ -44,7 +45,6 @@ def configure(target, my_module):
'etk-core/Allocator.hpp',
'etk-core/types.hpp',
'etk-core/stdTools.hpp',
'etk-core/Buffer.hpp',
'etk-core/String.hpp',
'etk-core/UString.hpp',
'etk-core/utf8.hpp',
@ -59,7 +59,8 @@ def configure(target, my_module):
'etk-core/Function.hpp',
'etk-core/NullPtr.hpp',
'etk-core/typeInfo.hpp',
'etk-core/Exception.hpp'
'etk-core/Exception.hpp',
'etk-core/system.hpp',
], 'etk')
# build in C++ mode
@ -70,7 +71,11 @@ def configure(target, my_module):
'm',
"pthread",
])
"""
my_module.add_flag('c++', [
"-DETK_MEMORY_CHECKER=2"
], export=True)
"""
if "Android" in target.get_type():
my_module.add_depend("SDK")
if "MacOs" in target.get_type():

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
@ -43,6 +43,7 @@ def configure(target, my_module):
'etk/io/File.cpp',
'etk/io/ZipFile.cpp',
'etk/theme/theme.cpp',
'etk/theme/ProviderTheme.cpp',
'etk/math/Matrix2x2.cpp',
'etk/math/Matrix2x3.cpp',
'etk/math/Matrix3x3.cpp',
@ -58,6 +59,7 @@ def configure(target, my_module):
'etk/uri/uri.cpp',
'etk/uri/Query.cpp',
'etk/uri/provider/provider.cpp',
'etk/uri/provider/Interface.cpp',
'etk/uri/provider/ProviderFile.cpp',
'etk/uri/provider/ProviderFileZip.cpp',
])
@ -65,6 +67,7 @@ def configure(target, my_module):
my_module.add_header_file([
'etk/etk.hpp',
'etk/debug.hpp',
'etk/Buffer.hpp',
'etk/tool.hpp',
'etk/Noise.hpp',
'etk/Color.hpp',
@ -78,6 +81,7 @@ def configure(target, my_module):
'etk/io/File.hpp',
'etk/io/ZipFile.hpp',
'etk/theme/theme.hpp',
'etk/theme/ProviderTheme.hpp',
'etk/math/Matrix2x2.hpp',
'etk/math/Matrix2x3.hpp',
'etk/math/Matrix3x3.hpp',

View File

@ -85,6 +85,20 @@ TEST(TestPath, assignation) {
}
TEST(TestPath, operator_devide) {
etk::Path path;
EXPECT_EQ(path.getString(), "");
path = "/home";
EXPECT_EQ(path.getString(), "/home");
path /= "rastapopoulos";
EXPECT_EQ(path.getString(), "/home/rastapopoulos");
path = "";
path /= "plouf.txt";
EXPECT_EQ(path.getString(), "plouf.txt");
path = "";
path = path / "plouf.txt";
EXPECT_EQ(path.getString(), "plouf.txt");}
TEST(TestPath, simplification) {
etk::Path path("/home/../plouf");
EXPECT_EQ(path.getString(), "/plouf");
@ -135,6 +149,10 @@ TEST(TestPath, parent) {
EXPECT_EQ(path.getString(), "/home/plouf/plaf");
path = "/";
EXPECT_EQ(path.getParent(), "/");
path = "/wxdvsdf";
EXPECT_EQ(path.getParent(), "/");
path = "plouf.txt";
EXPECT_EQ(path.getParent(), "");
}
TEST(TestPath, getRelative) {

View File

@ -10,12 +10,14 @@
#define NAME "etk:String"
TEST(TestString, constructor) {
TEST(TestString, constructor_1) {
// Test contructor value
etk::String test0;
EXPECT_EQ(test0.size(), 0);
EXPECT_EQ(test0.c_str()[0], '\0');
}
TEST(TestString, constructor_2) {
etk::String test1("hello");
EXPECT_EQ(test1.size(), 5);
EXPECT_EQ(test1.c_str()[0], 'h');
@ -24,7 +26,10 @@ TEST(TestString, constructor) {
EXPECT_EQ(test1.c_str()[3], 'l');
EXPECT_EQ(test1.c_str()[4], 'o');
EXPECT_EQ(test1.c_str()[5], '\0');
}
TEST(TestString, constructor_3) {
etk::String test1("hello");
etk::String test2(test1);
EXPECT_EQ(test2.size(), 5);
EXPECT_EQ(test2.c_str()[0], 'h');
@ -33,21 +38,33 @@ TEST(TestString, constructor) {
EXPECT_EQ(test2.c_str()[3], 'l');
EXPECT_EQ(test2.c_str()[4], 'o');
EXPECT_EQ(test2.c_str()[5], '\0');
}
TEST(TestString, constructor_4) {
etk::String test1("hello");
etk::String test3(test1, 2);
EXPECT_EQ(test3.size(), 3);
EXPECT_EQ(test3.c_str()[0], 'l');
EXPECT_EQ(test3.c_str()[1], 'l');
EXPECT_EQ(test3.c_str()[2], 'o');
EXPECT_EQ(test3.c_str()[3], '\0');
}
TEST(TestString, constructor_5) {
etk::String test1("hello");
etk::String test4(test1, 1, 3);
EXPECT_EQ(test4.size(), 3);
EXPECT_EQ(test4.c_str()[0], 'e');
EXPECT_EQ(test4.c_str()[1], 'l');
EXPECT_EQ(test4.c_str()[2], 'l');
EXPECT_EQ(test4.c_str()[3], '\0');
}
TEST(TestString, constructor_6) {
etk::String test0{""};
EXPECT_EQ(test0.size(), 0);
EXPECT_EQ(test0.c_str()[0], '\0');
EXPECT_NE(uint64_t(&test0.c_str()[0]), 0);
}
TEST(TestString, equality) {

View File

@ -13,28 +13,28 @@
TEST(TestTheme, init_uninit) {
etk::theme::init();
etk::theme::setName("AAA", "aaa");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), "");
EXPECT_EQ(etk::theme::getName("AAA"), "aaa");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), etk::Path("default"));
EXPECT_EQ(etk::theme::getName("AAA"), etk::Path("aaa"));
etk::theme::unInit();
EXPECT_EQ(etk::theme::getNameDefault("AAA"), "");
EXPECT_EQ(etk::theme::getName("AAA"), "");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), etk::Path("default"));
EXPECT_EQ(etk::theme::getName("AAA"), etk::Path());
}
TEST(TestTheme, set) {
etk::theme::init();
etk::theme::setNameDefault("AAA", "aaa");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), "aaa");
EXPECT_EQ(etk::theme::getName("AAA"), "aaa");
etk::theme::setNameDefault("AAA", etk::Path("aaa"));
EXPECT_EQ(etk::theme::getNameDefault("AAA"), etk::Path("aaa"));
EXPECT_EQ(etk::theme::getName("AAA"), etk::Path());
etk::theme::unInit();
EXPECT_EQ(etk::theme::getNameDefault("AAA"), "");
EXPECT_EQ(etk::theme::getName("AAA"), "");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), etk::Path("default"));
EXPECT_EQ(etk::theme::getName("AAA"), etk::Path());
}
TEST(TestTheme, set2) {
etk::theme::init();
etk::theme::setNameDefault("AAA", "aaa");
etk::theme::setName("AAA", "bbb");
EXPECT_EQ(etk::theme::getNameDefault("AAA"), "aaa");
EXPECT_EQ(etk::theme::getName("AAA"), "bbb");
etk::theme::setNameDefault("AAA", etk::Path("aaa"));
etk::theme::setName("AAA", etk::Path("bbb"));
EXPECT_EQ(etk::theme::getNameDefault("AAA"), etk::Path("aaa"));
EXPECT_EQ(etk::theme::getName("AAA"), etk::Path("bbb"));
etk::theme::unInit();
}

View File

@ -34,10 +34,23 @@ namespace {
bool exist(const etk::Uri& _uri) override {
return false;
}
bool isDirectory(const etk::Uri& _uri) override {
return false;
}
bool isFile(const etk::Uri& _uri) override {
return false;
}
bool isSymLink(const etk::Uri& _uri) override {
return false;
}
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override {
etk::Vector<etk::Uri> out;
return out;
}
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override {
etk::Vector<etk::Uri> out;
return out;
}
};
class ProviderTest2 : public etk::uri::provider::Interface {
public:
@ -48,10 +61,23 @@ namespace {
bool exist(const etk::Uri& _uri) override {
return false;
}
bool isDirectory(const etk::Uri& _uri) override {
return false;
}
bool isFile(const etk::Uri& _uri) override {
return false;
}
bool isSymLink(const etk::Uri& _uri) override {
return false;
}
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override {
etk::Vector<etk::Uri> out;
return out;
}
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override {
etk::Vector<etk::Uri> out;
return out;
}
};
}
@ -60,7 +86,7 @@ TEST(TestUriProvider, checkPlouf) {
etk::uri::provider::clear();
s_plouf = 0;
EXPECT_EQ(etk::uri::provider::exist(""), true);
EXPECT_EQ(etk::uri::provider::exist("RAW"), true);
EXPECT_EQ(etk::uri::provider::exist("FILE"), true);
EXPECT_EQ(etk::uri::provider::exist("PLOUF_1"), false);
EXPECT_EQ(etk::uri::provider::exist("PLOUF_2"), false);
etk::uri::provider::add("PLOUF_1", ememory::makeShared<::ProviderTest1>());
@ -202,7 +228,7 @@ TEST(TestUriProvider, checkZipAccess) {
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null);
TEST_VERBOSE("List DATA path:");
etk::Uri searchBase("DATA://");
etk::Uri searchBase("DATA:///");
auto elems = provider->list(searchBase);
for (auto& it: elems) {
TEST_VERBOSE(" " << it);