Compare commits

..

5 Commits

9 changed files with 48 additions and 8 deletions

View File

@ -21,7 +21,7 @@ File to read: "read.xml"
Reading a file is done like this:
@snippet read.cpp exml_sample_read_file
The file naming is manage by @ref etk::FSNode that provide "DATA:" start string for internal application asset. You can use external path like "./plop/file.xml" too.
The file naming is manage by @ref etk::FSNode that provide "DATA:///" start string for internal application asset. You can use external path like "./plop/file.xml" too.
Read an XML Stream {#exml_tutorial_read_stream}

View File

@ -7,6 +7,8 @@
#include <exml/Document.hpp>
#include <exml/debug.hpp>
#include <exml/internal/Document.hpp>
#include <etk/path/fileSystem.hpp>
#include <etk/uri/uri.hpp>
exml::Document::Document(ememory::SharedPtr<exml::internal::Node> _internalNode) :
exml::Element(_internalNode) {
@ -82,6 +84,35 @@ bool exml::Document::store(const etk::Uri& _uri) {
return static_cast<exml::internal::Document*>(m_data.get())->store(_uri);
}
bool exml::Document::storeSafe(const etk::Path& _path) {
if (m_data == null) {
EXML_DEBUG("Can not store (null) ...");
return false;
}
bool done = static_cast<exml::internal::Document*>(m_data.get())->store(_path+".tmp");
if (done == false) {
return false;
}
return etk::path::move(_path+".tmp", _path);
}
bool exml::Document::storeSafe(const etk::Uri& _uri) {
if (m_data == null) {
EXML_DEBUG("Can not store (null) ...");
return false;
}
if (etk::uri::canMove(_uri) == false) {
return static_cast<exml::internal::Document*>(m_data.get())->store(_uri);
}
etk::Uri uriTmp = _uri;
uriTmp.setPath(uriTmp.getPath() + ".tmp");
bool done = static_cast<exml::internal::Document*>(m_data.get())->store(uriTmp);
if (done == false) {
return false;
}
return etk::uri::move(uriTmp, _uri);
}
void exml::Document::display() {
if (m_data == null) {
EXML_DEBUG("Can not display (null) ...");

View File

@ -78,6 +78,15 @@ namespace exml {
bool store(const etk::Path& _path);
/// @previous
bool store(const etk::Uri& _uri);
/**
* @brief Store the Json in the file (safe mode mean that the file is store in a second file xxx.tmp and moved in the file xxx (only one mode to be really safe with filesystem ...)
* @param[in] _path/_uri Path/URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool storeSafe(const etk::Path& _path);
/// @previous
bool storeSafe(const etk::Uri& _uri);
/**
* @brief Display the Document on console
*/

View File

@ -84,7 +84,7 @@ bool exml::internal::Document::store(const etk::Uri& _uri) {
EXML_ERROR("Can not open (r) the file : " << _uri);
return false;
}
fileIo->fileWriteAll(createData);
fileIo->writeAll(createData);
fileIo->close();
return true;
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
def 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

View File

@ -17,7 +17,7 @@ static void readFromFile() {
exml::Document doc;
//! [exml_sample_declare_doc]
//! [exml_sample_read_file]
bool retParse = doc.load("DATA:read.xml");
bool retParse = doc.load(etk::Uri("DATA:///read.xml"));
//! [exml_sample_read_file]
TEST_INFO("parse ret = " << retParse);
TEST_INFO("Debug display of the tree:");
@ -56,7 +56,7 @@ static void readFromString2() {
static void readFull() {
exml::Document doc;
TEST_INFO("parse");
bool retParse = doc.load("DATA:read.xml");
bool retParse = doc.load(etk::Uri("DATA:///read.xml"));
TEST_INFO("parse ret = " << retParse);
TEST_INFO("Debug display of the tree:");
doc.display();

View File

@ -18,7 +18,7 @@ static void writeToFile() {
doc.nodes.add(exml::Comment("basic comment"));
TEST_INFO("store");
//! [exml_sample_write_file]
bool retGenerate = doc.store("generate.xml");
bool retGenerate = doc.store(etk::Path("generate.xml"));
//! [exml_sample_write_file]
TEST_INFO("parse ret = " << retGenerate);
TEST_INFO("Debug display of the tree:");