[DOC] Add sample of safe store

This commit is contained in:
Edouard DUPIN 2017-01-04 22:22:25 +01:00
parent 389f1788a9
commit 6ed77119d4
4 changed files with 11 additions and 0 deletions

View File

@ -59,8 +59,11 @@ Access to a boolean in an Object:
Access to a Number in an Object:
---------------------------------
By default a number is a double (herited from the js internal property)
@snippet read.cpp ejson_sample_read_get_number
But it is possible to read large number directly in 64 bits mode (better for entier number, no round generated.)
@snippet read.cpp ejson_sample_read_get_number_64_bits
Access to a Array in an Object:
---------------------------------

View File

@ -18,6 +18,8 @@ Write an JSON file {#ejson_tutorial_write_file}
Write an json tree is done like:
@snippet write.cpp ejson_sample_write_file
When you acces on the fileSystem, it is hard to have atoimic access, then the best way to not corupt your previous file (chash when writing the new) is to store the file in a second one and move the file at the corretc position. This is all done in the single commmand:
@snippet write.cpp ejson_sample_write_file_safe_mode
Write an JSON Stream {#ejson_tutorial_write_stream}
===================

View File

@ -201,6 +201,9 @@ static void readFull() {
//! [ejson_sample_read_get_number]
double value = doc["object D"].toNumber().get();
//! [ejson_sample_read_get_number]
//! [ejson_sample_read_get_number_64_bits]
uint64_t value = doc["object D"].toNumber().getU64();
//! [ejson_sample_read_get_number_64_bits]
TEST_INFO(" Number Value:" << value);
}

View File

@ -18,6 +18,9 @@ static void writeToFile() {
//! [ejson_sample_write_file]
bool retGenerate = doc.store("generate.json");
//! [ejson_sample_write_file]
//! [ejson_sample_write_file_safe_mode]
bool retGenerate = doc.storeSafe("generate.json");
//! [ejson_sample_write_file_safe_mode]
TEST_INFO("parse ret = " << retGenerate);
TEST_INFO("Debug display of the tree:");
doc.display();