Added a return value to visitors

This commit is contained in:
Benoit Blanchon
2020-08-29 18:40:27 +02:00
parent f448e805e9
commit 5ab53f42b2
20 changed files with 298 additions and 198 deletions

View File

@@ -18,44 +18,48 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
public:
PrettyJsonSerializer(TWriter &writer) : base(writer), _nesting(0) {}
void visitArray(const CollectionData &array) {
size_t visitArray(const CollectionData &array) {
VariantSlot *slot = array.head();
if (!slot)
return base::write("[]");
if (slot) {
base::write("[\r\n");
_nesting++;
while (slot != 0) {
indent();
slot->data()->accept(*this);
base::write("[\r\n");
_nesting++;
while (slot != 0) {
slot = slot->next();
base::write(slot ? ",\r\n" : "\r\n");
}
_nesting--;
indent();
slot->data()->accept(*this);
slot = slot->next();
base::write(slot ? ",\r\n" : "\r\n");
base::write("]");
} else {
base::write("[]");
}
_nesting--;
indent();
base::write("]");
return this->bytesWritten();
}
void visitObject(const CollectionData &object) {
size_t visitObject(const CollectionData &object) {
VariantSlot *slot = object.head();
if (!slot)
return base::write("{}");
if (slot) {
base::write("{\r\n");
_nesting++;
while (slot != 0) {
indent();
base::visitString(slot->key());
base::write(": ");
slot->data()->accept(*this);
base::write("{\r\n");
_nesting++;
while (slot != 0) {
slot = slot->next();
base::write(slot ? ",\r\n" : "\r\n");
}
_nesting--;
indent();
base::visitString(slot->key());
base::write(": ");
slot->data()->accept(*this);
slot = slot->next();
base::write(slot ? ",\r\n" : "\r\n");
base::write("}");
} else {
base::write("{}");
}
_nesting--;
indent();
base::write("}");
return this->bytesWritten();
}
private: