"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "example/serialize/serialize.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.

serialize.cpp  (rapidjson-1.0.2):serialize.cpp  (rapidjson-1.1.0)
skipping to change at line 14 skipping to change at line 14
#include "rapidjson/prettywriter.h" // for stringify JSON #include "rapidjson/prettywriter.h" // for stringify JSON
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <vector> #include <vector>
using namespace rapidjson; using namespace rapidjson;
class Person { class Person {
public: public:
Person(const std::string& name, unsigned age) : name_(name), age_(age) {} Person(const std::string& name, unsigned age) : name_(name), age_(age) {}
Person(const Person& rhs) : name_(rhs.name_), age_(rhs.age_) {}
virtual ~Person(); virtual ~Person();
Person& operator=(const Person& rhs) {
name_ = rhs.name_;
age_ = rhs.age_;
return *this;
}
protected: protected:
template <typename Writer> template <typename Writer>
void Serialize(Writer& writer) const { void Serialize(Writer& writer) const {
// This base class just write out name-value pairs, without wrapping wit hin an object. // This base class just write out name-value pairs, without wrapping wit hin an object.
writer.String("name"); writer.String("name");
#ifdef RAPIDJSON_HAS_STDSTRING #if RAPIDJSON_HAS_STDSTRING
writer.String(name_); writer.String(name_);
#else #else
writer.String(name_.c_str(), (SizeType)name_.length()); // Supplying len gth of string is faster. writer.String(name_.c_str(), static_cast<SizeType>(name_.length())); // Supplying length of string is faster.
#endif #endif
writer.String("age"); writer.String("age");
writer.Uint(age_); writer.Uint(age_);
} }
private: private:
std::string name_; std::string name_;
unsigned age_; unsigned age_;
}; };
Person::~Person() { Person::~Person() {
} }
class Education { class Education {
public: public:
Education(const std::string& school, double GPA) : school_(school), GPA_(GPA ) {} Education(const std::string& school, double GPA) : school_(school), GPA_(GPA ) {}
Education(const Education& rhs) : school_(rhs.school_), GPA_(rhs.GPA_) {}
template <typename Writer> template <typename Writer>
void Serialize(Writer& writer) const { void Serialize(Writer& writer) const {
writer.StartObject(); writer.StartObject();
writer.String("school"); writer.String("school");
#ifdef RAPIDJSON_HAS_STDSTRING #if RAPIDJSON_HAS_STDSTRING
writer.String(school_); writer.String(school_);
#else #else
writer.String(school_.c_str(), (SizeType)school_.length()); writer.String(school_.c_str(), static_cast<SizeType>(school_.length()));
#endif #endif
writer.String("GPA"); writer.String("GPA");
writer.Double(GPA_); writer.Double(GPA_);
writer.EndObject(); writer.EndObject();
} }
private: private:
std::string school_; std::string school_;
skipping to change at line 105 skipping to change at line 113
Education *education_; Education *education_;
}; };
Dependent::~Dependent() { Dependent::~Dependent() {
delete education_; delete education_;
} }
class Employee : public Person { class Employee : public Person {
public: public:
Employee(const std::string& name, unsigned age, bool married) : Person(name, age), dependents_(), married_(married) {} Employee(const std::string& name, unsigned age, bool married) : Person(name, age), dependents_(), married_(married) {}
Employee(const Employee& rhs) : Person(rhs), dependents_(rhs.dependents_), m arried_(rhs.married_) {}
virtual ~Employee(); virtual ~Employee();
Employee& operator=(const Employee& rhs) {
static_cast<Person&>(*this) = rhs;
dependents_ = rhs.dependents_;
married_ = rhs.married_;
return *this;
}
void AddDependent(const Dependent& dependent) { void AddDependent(const Dependent& dependent) {
dependents_.push_back(dependent); dependents_.push_back(dependent);
} }
template <typename Writer> template <typename Writer>
void Serialize(Writer& writer) const { void Serialize(Writer& writer) const {
writer.StartObject(); writer.StartObject();
Person::Serialize(writer); Person::Serialize(writer);
 End of changes. 9 change blocks. 
4 lines changed or deleted 20 lines changed or added

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