[DEV] update for build URI

This commit is contained in:
Edouard DUPIN 2018-09-29 21:58:19 +02:00
parent 7d95093c36
commit 6b6c81844e
6 changed files with 64 additions and 18 deletions

View File

@ -7,7 +7,8 @@
*/ */
#pragma once #pragma once
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <etk/io/File.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
// minimum gapSize when allocated // minimum gapSize when allocated
@ -93,17 +94,15 @@ namespace etk {
* @return true if the data correctly stored * @return true if the data correctly stored
* @return false if an error occurred * @return false if an error occurred
*/ */
bool dumpIn(const etk::String& _file) { bool dumpIn(const etk::Path& _file) {
etk::FSNode file(_file); etk::io::File fileIO(_file);
if (false == file.fileOpenWrite()) { if (fileIO.open(etk::io::OpenMode::Write) == false) {
return false; return false;
} }
bool ret = true; fileIO.write(m_data, sizeof(int8_t), m_gapStart);
// write Data fileIO.write(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd);
file.fileWrite(m_data, sizeof(int8_t), m_gapStart); fileIO.close();
file.fileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd); return true;
file.fileClose();
return ret;
} }
/** /**
* @brief Load data from a selected file name. * @brief Load data from a selected file name.
@ -111,13 +110,12 @@ namespace etk {
* @return true if the data correctly stored * @return true if the data correctly stored
* @return false if an error occurred * @return false if an error occurred
*/ */
bool dumpFrom(const etk::String& _file) { bool dumpFrom(const etk::Path& _file) {
etk::FSNode file(_file); etk::io::File fileIO(_file);
if (false == file.fileOpenRead()) { if (fileIO.open(etk::io::OpenMode::Read) == false) {
return false; return false;
} }
bool ret = true; int64_t length = fileIO.size();
int64_t length = file.fileSize();
// error case ... // error case ...
if (length > 2000000000) { if (length > 2000000000) {
return false; return false;
@ -125,9 +123,10 @@ namespace etk {
// allocate the current buffer : // allocate the current buffer :
changeAllocation(length + GAP_SIZE_MIN); changeAllocation(length + GAP_SIZE_MIN);
// insert Data // 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); TK_INFO("load data : fileSize=" << length << ", readData=" << nbReadData);
// check ERROR // check ERROR
bool ret = true;
if (nbReadData != length) { if (nbReadData != length) {
TK_ERROR("load data error: fileSize=" << length << ", readData=" << nbReadData); TK_ERROR("load data error: fileSize=" << length << ", readData=" << nbReadData);
ret = false; ret = false;
@ -135,7 +134,7 @@ namespace etk {
// set the gap size at the buffer ... // set the gap size at the buffer ...
m_gapStart = 0; m_gapStart = 0;
m_gapEnd = GAP_SIZE_MIN; m_gapEnd = GAP_SIZE_MIN;
file.fileClose(); fileIO.close();
return ret; return ret;
} }

View File

@ -463,3 +463,24 @@ bool etk::operator<= (const Path& _left, const Path& _right) {
return _left.getString() <= _right.getString(); 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

@ -5,6 +5,8 @@
*/ */
#include <etk/uri/Query.hpp> #include <etk/uri/Query.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::uri::Query);
static const etk::String hexData = "0123456789ABCDEF"; static const etk::String hexData = "0123456789ABCDEF";

View File

@ -6,6 +6,8 @@
#include <etk/uri/Uri.hpp> #include <etk/uri/Uri.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::Uri);
etk::Uri::Uri() { etk::Uri::Uri() {
@ -302,3 +304,25 @@ void etk::Uri::display() const {
TK_PRINT(" m_fragment = '" << m_fragment << "'"); 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

@ -44,7 +44,6 @@ def configure(target, my_module):
'etk-core/Allocator.hpp', 'etk-core/Allocator.hpp',
'etk-core/types.hpp', 'etk-core/types.hpp',
'etk-core/stdTools.hpp', 'etk-core/stdTools.hpp',
'etk-core/Buffer.hpp',
'etk-core/String.hpp', 'etk-core/String.hpp',
'etk-core/UString.hpp', 'etk-core/UString.hpp',
'etk-core/utf8.hpp', 'etk-core/utf8.hpp',

View File

@ -65,6 +65,7 @@ def configure(target, my_module):
my_module.add_header_file([ my_module.add_header_file([
'etk/etk.hpp', 'etk/etk.hpp',
'etk/debug.hpp', 'etk/debug.hpp',
'etk/Buffer.hpp',
'etk/tool.hpp', 'etk/tool.hpp',
'etk/Noise.hpp', 'etk/Noise.hpp',
'etk/Color.hpp', 'etk/Color.hpp',