#include "archiver.h"
#include <iostream>
#include <vector>
Go to the source code of this file.
◆ main()
◆ operator&() [1/7]
Definition at line 195 of file archivertest.cpp.
195 {
196 ar &
static_cast<Shape&
>(b);
197 ar.Member("width") & b.width_;
198 ar.Member("height") & b.height_;
199 return ar;
200}
◆ operator&() [2/7]
Definition at line 245 of file archivertest.cpp.
245 {
246 size_t shapeCount = c.shapes_.size();
247 ar.StartArray(&shapeCount);
248 if (ar.IsReader) {
250 c.shapes_.resize(shapeCount);
251 }
252 for (size_t i = 0; i < shapeCount; i++)
253 ar & c.shapes_[i];
254 return ar.EndArray();
255}
◆ operator&() [3/7]
Definition at line 169 of file archivertest.cpp.
169 {
170 ar &
static_cast<Shape&
>(c);
171 ar.Member("radius") & c.radius_;
172 return ar;
173}
◆ operator&() [4/7]
Definition at line 68 of file archivertest.cpp.
68 {
69 ar.StartObject();
70
71 ar.Member("groupName");
73
74 ar.Member("students");
75 size_t studentCount = g.
students.size();
76 ar.StartArray(&studentCount);
77 if (ar.IsReader)
79 for (size_t i = 0; i < studentCount; i++)
81 ar.EndArray();
82
83 return ar.EndObject();
84}
std::vector< Student > students
◆ operator&() [5/7]
Definition at line 143 of file archivertest.cpp.
143 {
144 ar.Member(
"x") &
s.x_;
145 ar.Member(
"y") &
s.y_;
146 return ar;
147}
◆ operator&() [6/7]
Definition at line 229 of file archivertest.cpp.
229 {
230 std::string type = ar.IsReader ?
"" : shape->
GetType();
231 ar.StartObject();
232 ar.Member(
"type") &
type;
233 if (type == "Circle") {
234 if (ar.IsReader) shape =
new Circle;
235 ar &
static_cast<Circle&
>(*shape);
236 }
237 else if (type == "Box") {
238 if (ar.IsReader) shape =
new Box;
239 ar &
static_cast<Box&
>(*shape);
240 }
241 return ar.EndObject();
242}
virtual const char * GetType() const =0
◆ operator&() [7/7]
Definition at line 21 of file archivertest.cpp.
21 {
22 ar.StartObject();
23 ar.Member(
"name") &
s.name;
24 ar.Member(
"age") &
s.age;
25 ar.Member(
"height") &
s.height;
26 ar.Member(
"canSwim") &
s.canSwim;
27 return ar.EndObject();
28}
◆ operator<<() [1/2]
std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
const Group & | g ) |
Definition at line 86 of file archivertest.cpp.
86 {
88 for (std::vector<Student>::const_iterator itr = g.
students.begin(); itr != g.
students.end(); ++itr)
89 os << *itr << std::endl;
91}
◆ operator<<() [2/2]
std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
const Student & | s ) |
Definition at line 30 of file archivertest.cpp.
30 {
31 return os <<
s.name <<
" " <<
s.age <<
" " <<
s.height <<
" " <<
s.canSwim;
32}
◆ test1()
Definition at line 34 of file archivertest.cpp.
34 {
35 std::string json;
36
37
38 {
40
44 std::cout << json << std::endl;
45 }
46
47
48 {
52 std::cout <<
s << std::endl;
53 }
54}
Represents a JSON reader which implements Archiver concept.
const char * GetString() const
Obtains the serialized JSON string.
◆ test2()
Definition at line 93 of file archivertest.cpp.
93 {
94 std::string json;
95
96
97 {
100
101 Student s1(
"Lua", 9, 150.5,
true);
102 Student s2(
"Mio", 7, 120.0,
false);
105
107 writer & g;
109 std::cout << json << std::endl;
110 }
111
112
113 {
116 reader & g;
117 std::cout << g << std::endl;
118 }
119}
◆ test3()
Definition at line 257 of file archivertest.cpp.
257 {
258 std::string json;
259
260
261 {
265
267 writer & c;
269 std::cout << json << std::endl;
270 }
271
272
273 {
276 reader & c;
278 }
279}
void AddShape(Shape *shape)
void Print(std::ostream &os)