diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2015-04-10 22:26:57 -0700 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2015-04-10 22:26:57 -0700 |
commit | e90d2ac8ba44fbcf4d5702643f708f2c86bde42e (patch) | |
tree | a52fe8e4efee8176da169998c203c1a93f6a6ff1 /docs/samples/load_memory.cpp | |
parent | 6457f0941204a79ec5ba359a12aa00bf06f0e621 (diff) | |
parent | 405fefc8777c55900a4e44561b545a9abb5276ba (diff) |
Merge branch 'master' into compact
Diffstat (limited to 'docs/samples/load_memory.cpp')
-rw-r--r-- | docs/samples/load_memory.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/docs/samples/load_memory.cpp b/docs/samples/load_memory.cpp index 490f7e4..80bba3c 100644 --- a/docs/samples/load_memory.cpp +++ b/docs/samples/load_memory.cpp @@ -5,41 +5,42 @@ int main() { -//[code_load_memory_decl +// tag::decl[] const char source[] = "<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>"; size_t size = sizeof(source); -//] +// end::decl[] pugi::xml_document doc; { - //[code_load_memory_buffer + // tag::load_buffer[] // You can use load_buffer to load document from immutable memory block: pugi::xml_parse_result result = doc.load_buffer(source, size); - //] + // end::load_buffer[] std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl; } { - //[code_load_memory_buffer_inplace + // tag::load_buffer_inplace_begin[] // You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document char* buffer = new char[size]; memcpy(buffer, source, size); // The block can be allocated by any method; the block is modified during parsing pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size); + // end::load_buffer_inplace_begin[] - //<- std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl; - //-> + + // tag::load_buffer_inplace_end[] // You have to destroy the block yourself after the document is no longer used delete[] buffer; - //] + // end::load_buffer_inplace_end[] } { - //[code_load_memory_buffer_inplace_own + // tag::load_buffer_inplace_own[] // You can use load_buffer_inplace_own to load document from mutable memory block and to pass the ownership of this block // The block has to be allocated via pugixml allocation function - using i.e. operator new here is incorrect char* buffer = static_cast<char*>(pugi::get_memory_allocation_function()(size)); @@ -47,16 +48,16 @@ int main() // The block will be deleted by the document pugi::xml_parse_result result = doc.load_buffer_inplace_own(buffer, size); - //] + // end::load_buffer_inplace_own[] std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl; } { - //[code_load_memory_string + // tag::load_string[] // You can use load to load document from null-terminated strings, for example literals: pugi::xml_parse_result result = doc.load_string("<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>"); - //] + // end::load_string[] std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl; } |