"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "example/tutorial/tutorial.cpp" between
rapidjson-1.0.2.tar.gz and rapidjson-1.1.0.tar.gz

About: RapidJSON is a fast JSON parser/generator for C++ with both SAX/DOM style API.

tutorial.cpp  (rapidjson-1.0.2):tutorial.cpp  (rapidjson-1.1.0)
skipping to change at line 124 skipping to change at line 124
// So it is for literal and string that exists within value's life-cycle. // So it is for literal and string that exists within value's life-cycle.
{ {
document["hello"] = "rapidjson"; // This will invoke strlen() document["hello"] = "rapidjson"; // This will invoke strlen()
// Faster version: // Faster version:
// document["hello"].SetString("rapidjson", 9); // document["hello"].SetString("rapidjson", 9);
} }
// This version of SetString() needs an allocator, which means it will alloc ate a new buffer and copy the the string into the buffer. // This version of SetString() needs an allocator, which means it will alloc ate a new buffer and copy the the string into the buffer.
Value author; Value author;
{ {
char buffer[10]; char buffer2[10];
int len = sprintf(buffer, "%s %s", "Milo", "Yip"); // synthetic example int len = sprintf(buffer2, "%s %s", "Milo", "Yip"); // synthetic exampl
of dynamically created string. e of dynamically created string.
author.SetString(buffer, static_cast<size_t>(len), document.GetAllocator ()); author.SetString(buffer2, static_cast<SizeType>(len), document.GetAlloca tor());
// Shorter but slower version: // Shorter but slower version:
// document["hello"].SetString(buffer, document.GetAllocator()); // document["hello"].SetString(buffer, document.GetAllocator());
// Constructor version: // Constructor version:
// Value author(buffer, len, document.GetAllocator()); // Value author(buffer, len, document.GetAllocator());
// Value author(buffer, document.GetAllocator()); // Value author(buffer, document.GetAllocator());
memset(buffer, 0, sizeof(buffer)); // For demonstration purpose. memset(buffer2, 0, sizeof(buffer2)); // For demonstration purpose.
} }
// Variable 'buffer' is unusable now but 'author' has already made a copy. // Variable 'buffer' is unusable now but 'author' has already made a copy.
document.AddMember("author", author, document.GetAllocator()); document.AddMember("author", author, document.GetAllocator());
assert(author.IsNull()); // Move semantic for assignment. After this variable is assigned as a member, the variable becomes null. assert(author.IsNull()); // Move semantic for assignment. After this variable is assigned as a member, the variable becomes null.
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// 4. Stringify JSON // 4. Stringify JSON
printf("\nModified JSON with reformatting:\n"); printf("\nModified JSON with reformatting:\n");
 End of changes. 3 change blocks. 
5 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)