13 Person(
const std::string& name,
unsigned age) : name_(name), age_(age) {}
24 template <
typename Writer>
28 #if RAPIDJSON_HAS_STDSTRING 31 writer.
String(name_.c_str(),
static_cast<SizeType>(name_.length()));
47 Education(
const std::string& school,
double GPA) : school_(school), GPA_(GPA) {}
50 template <
typename Writer>
55 #if RAPIDJSON_HAS_STDSTRING 58 writer.
String(school_.c_str(),
static_cast<SizeType>(school_.length()));
86 template <
typename Writer>
92 writer.
String(
"education");
94 education_->Serialize(writer);
112 Employee(
const std::string& name,
unsigned age,
bool married) :
Person(name, age), dependents_(), married_(married) {}
117 static_cast<Person&
>(*this) = rhs;
124 dependents_.push_back(dependent);
127 template <
typename Writer>
134 writer.
Bool(married_);
136 writer.
String((
"dependents"));
138 for (std::vector<Dependent>::const_iterator dependentItr = dependents_.begin(); dependentItr != dependents_.end(); ++dependentItr)
139 dependentItr->Serialize(writer);
154 std::vector<Employee> employees;
156 employees.push_back(
Employee(
"Milo YIP", 34,
true));
157 employees.back().AddDependent(
Dependent(
"Lua YIP", 3,
new Education(
"Happy Kindergarten", 3.5)));
158 employees.back().AddDependent(
Dependent(
"Mio YIP", 1));
160 employees.push_back(
Employee(
"Percy TSE", 30,
false));
166 for (std::vector<Employee>::const_iterator employeeItr = employees.begin(); employeeItr != employees.end(); ++employeeItr)
167 employeeItr->Serialize(writer);
bool EndArray(SizeType elementCount=0)
bool EndObject(SizeType memberCount=0)
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Education(const std::string &school, double GPA)
Person(const Person &rhs)
std::vector< Dependent > dependents_
const Ch * GetString() const
Dependent & operator=(const Dependent &rhs)
bool Double(double d)
Writes the given double value to the stream.
bool String(const Ch *str, SizeType length, bool copy=false)
void Serialize(Writer &writer) const
Employee & operator=(const Employee &rhs)
Education(const Education &rhs)
void Serialize(Writer &writer) const
Person & operator=(const Person &rhs)
void Serialize(Writer &writer) const
void AddDependent(const Dependent &dependent)
Dependent(const Dependent &rhs)
void Serialize(Writer &writer) const
bool EndArray(SizeType memberCount=0)
Employee(const Employee &rhs)
Employee(const std::string &name, unsigned age, bool married)
Dependent(const std::string &name, unsigned age, Education *education=0)
Person(const std::string &name, unsigned age)
Writer with indentation and spacing.