[DEV] update new insterface IO of etk
This commit is contained in:
parent
7ae4ea7215
commit
be5702b029
@ -50,20 +50,36 @@ bool exml::Document::generate(etk::String& _data) {
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->generate(_data);
|
||||
}
|
||||
|
||||
bool exml::Document::load(const etk::String& _file) {
|
||||
bool exml::Document::load(const etk::Path& _path) {
|
||||
if (m_data == null) {
|
||||
EXML_DEBUG("Can not load (null) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->load(_file);
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->load(_path);
|
||||
}
|
||||
|
||||
bool exml::Document::store(const etk::String& _file) {
|
||||
bool exml::Document::load(const etk::Uri& _uri) {
|
||||
if (m_data == null) {
|
||||
EXML_DEBUG("Can not load (null) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->load(_uri);
|
||||
}
|
||||
|
||||
bool exml::Document::store(const etk::Path& _path) {
|
||||
if (m_data == null) {
|
||||
EXML_DEBUG("Can not store (null) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->store(_file);
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->store(_path);
|
||||
}
|
||||
|
||||
bool exml::Document::store(const etk::Uri& _uri) {
|
||||
if (m_data == null) {
|
||||
EXML_DEBUG("Can not store (null) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<exml::internal::Document*>(m_data.get())->store(_uri);
|
||||
}
|
||||
|
||||
void exml::Document::display() {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <exml/Element.hpp>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace exml {
|
||||
/**
|
||||
@ -61,18 +62,22 @@ namespace exml {
|
||||
bool generate(etk::String& _data);
|
||||
/**
|
||||
* @brief Load the file that might contain the xml
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @param[in] _path/_uri Path/URI of the xml
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool load(const etk::String& _file);
|
||||
bool load(const etk::Path& _path);
|
||||
/// @previous
|
||||
bool load(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Store the Xml in the file
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @param[in] _path/_uri Path/URI of the xml
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool store(const etk::String& _file);
|
||||
bool store(const etk::Path& _path);
|
||||
/// @previous
|
||||
bool store(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Display the Document on console
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <exml/internal/Document.hpp>
|
||||
#include <exml/debug.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/provider/provider.hpp>
|
||||
|
||||
ememory::SharedPtr<exml::internal::Document> exml::internal::Document::create() {
|
||||
return ememory::SharedPtr<exml::internal::Document>(ETK_NEW(exml::internal::Document));
|
||||
@ -46,57 +46,46 @@ bool exml::internal::Document::generate(etk::String& _data) {
|
||||
return iGenerate(_data,0);
|
||||
}
|
||||
|
||||
bool exml::internal::Document::load(const etk::String& _file) {
|
||||
bool exml::internal::Document::load(const etk::Uri& _uri) {
|
||||
// Start loading the XML :
|
||||
EXML_VERBOSE("open file (xml) \"" << _file << "\"");
|
||||
EXML_VERBOSE("open file (xml) " << _uri);
|
||||
clear();
|
||||
etk::FSNode tmpFile(_file);
|
||||
if (tmpFile.exist() == false) {
|
||||
EXML_ERROR("File Does not exist : " << _file);
|
||||
auto fileIo = etk::uri::get(_uri);
|
||||
if (fileIo == null) {
|
||||
EXML_ERROR("File Does not exist : " << _uri);
|
||||
return false;
|
||||
}
|
||||
int64_t fileSize = tmpFile.fileSize();
|
||||
if (fileSize == 0) {
|
||||
EXML_ERROR("This file is empty : " << _file);
|
||||
if (fileIo->open(etk::io::OpenMode::Read) == false) {
|
||||
EXML_ERROR("Can not open (r) the file : " << _uri);
|
||||
return false;
|
||||
}
|
||||
if (tmpFile.fileOpenRead() == false) {
|
||||
EXML_ERROR("Can not open (r) the file : " << _file);
|
||||
return false;
|
||||
}
|
||||
// allocate data
|
||||
etk::Vector<char> fileBuffer;
|
||||
fileBuffer.resize(fileSize+5, 0);
|
||||
// load data from the file :
|
||||
tmpFile.fileRead(&fileBuffer[0], 1, fileSize);
|
||||
// load data from the file:
|
||||
etk::String tmpDataUnicode = fileIo->readAllString();
|
||||
// close the file:
|
||||
tmpFile.fileClose();
|
||||
|
||||
// convert in UTF8 :
|
||||
etk::String tmpDataUnicode(&fileBuffer[0]);
|
||||
// parse the data :
|
||||
fileIo->close();
|
||||
// parse the data:
|
||||
bool ret = parse(tmpDataUnicode);
|
||||
//Display();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool exml::internal::Document::store(const etk::String& _file) {
|
||||
bool exml::internal::Document::store(const etk::Uri& _uri) {
|
||||
etk::String createData;
|
||||
if (generate(createData) == false) {
|
||||
EXML_ERROR("Error while creating the XML : " << _file);
|
||||
EXML_ERROR("Error while creating the XML: " << _uri);
|
||||
return false;
|
||||
}
|
||||
etk::FSNode tmpFile(_file);
|
||||
if (tmpFile.fileOpenWrite() == false) {
|
||||
EXML_ERROR("Can not open (w) the file : " << _file);
|
||||
auto fileIo = etk::uri::get(_uri);
|
||||
if (fileIo == null) {
|
||||
EXML_ERROR("Can not create the uri: " << _uri);
|
||||
return false;
|
||||
}
|
||||
if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != (int64_t)createData.size()) {
|
||||
EXML_ERROR("Error while writing output XML file : " << _file);
|
||||
tmpFile.fileClose();
|
||||
if (fileIo->open(etk::io::OpenMode::Write) == false) {
|
||||
EXML_ERROR("Can not open (r) the file : " << _uri);
|
||||
return false;
|
||||
}
|
||||
tmpFile.fileClose();
|
||||
fileIo->fileWriteAll(createData);
|
||||
fileIo->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <exml/internal/Element.hpp>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace exml {
|
||||
namespace internal {
|
||||
@ -59,18 +60,18 @@ namespace exml {
|
||||
bool generate(etk::String& _data);
|
||||
/**
|
||||
* @brief Load the file that might contain the xml
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @param[in] _uri URI of the xml
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool load(const etk::String& _file);
|
||||
bool load(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Store the Xml in the file
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @param[in] _uri URI of the xml
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool store(const etk::String& _file);
|
||||
bool store(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Display the Document on console
|
||||
*/
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etest/etest.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
@ -22,6 +21,5 @@ int main(int argc, const char *argv[]) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
etk::initDefaultFolder("exml_test");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user