Skip to content

Commit a9e3d08

Browse files
committed
<refactor>[JSON]: redefined JSON output for Sets
1 parent 41d2068 commit a9e3d08

4 files changed

Lines changed: 12 additions & 21 deletions

File tree

sbg/multidim_inter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,13 @@ MaybeMDI MultiDimInter::compact(const MultiDimInter& other) const
259259
rapidjson::Value toJSON(MultiDimInter mdi
260260
, rapidjson::Document::AllocatorType& alloc)
261261
{
262-
rapidjson::Value result{rapidjson::kArrayType};
263-
264262
rapidjson::Value interval_array{rapidjson::kArrayType};
265263
for (const Interval& i : mdi) {
266264
rapidjson::Value jth = toJSON(i, alloc);
267265
interval_array.PushBack(jth, alloc);
268266
}
269-
rapidjson::Value mdi_obj{rapidjson::kObjectType};
270-
mdi_obj.AddMember("bounds", interval_array, alloc);
271-
result.PushBack(mdi_obj, alloc);
267+
rapidjson::Value result{rapidjson::kObjectType};
268+
result.AddMember("bounds", interval_array, alloc);
272269

273270
return result;
274271
}

sbg/ord_set.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,16 +681,13 @@ void OrderedSet::compact()
681681

682682
rapidjson::Value toJSON(OrderedSet s, rapidjson::Document::AllocatorType& alloc)
683683
{
684-
rapidjson::Value result{rapidjson::kArrayType};
685-
686684
rapidjson::Value mdi_array{rapidjson::kArrayType};
687685
for (const MultiDimInter& mdi : s) {
688686
rapidjson::Value jth = detail::toJSON(mdi, alloc);
689687
mdi_array.PushBack(jth, alloc);
690688
}
691-
rapidjson::Value mdi_obj{rapidjson::kObjectType};
692-
mdi_obj.AddMember("pieces", mdi_array, alloc);
693-
result.PushBack(mdi_obj, alloc);
689+
rapidjson::Value result{rapidjson::kObjectType};
690+
result.AddMember("pieces", mdi_array, alloc);
694691

695692
return result;
696693
}

sbg/ord_unidim_dense_set.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,16 @@ OrdUnidimDenseSet OrdUnidimDenseSet::traverse(
492492
rapidjson::Value toJSON(OrdUnidimDenseSet s
493493
, rapidjson::Document::AllocatorType& alloc)
494494
{
495-
rapidjson::Value result{rapidjson::kArrayType};
496-
497495
rapidjson::Value interval_array{rapidjson::kArrayType};
498496
for (const Interval& i : s) {
499-
rapidjson::Value jth = detail::toJSON(i, alloc);
497+
rapidjson::Value jth_array{rapidjson::kArrayType};
498+
jth_array.PushBack(detail::toJSON(i, alloc), alloc);
499+
rapidjson::Value jth{rapidjson::kObjectType};
500+
jth.AddMember("bounds", jth_array, alloc);
500501
interval_array.PushBack(jth, alloc);
501502
}
502-
rapidjson::Value mdi_obj{rapidjson::kObjectType};
503-
mdi_obj.AddMember("pieces", interval_array, alloc);
504-
result.PushBack(mdi_obj, alloc);
503+
rapidjson::Value result{rapidjson::kObjectType};
504+
result.AddMember("pieces", interval_array, alloc);
505505

506506
return result;
507507
}

sbg/unord_set.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,13 @@ void UnorderedSet::compact()
484484
rapidjson::Value toJSON(UnorderedSet s
485485
, rapidjson::Document::AllocatorType& alloc)
486486
{
487-
rapidjson::Value result{rapidjson::kArrayType};
488-
489487
rapidjson::Value mdi_array{rapidjson::kArrayType};
490488
for (const MultiDimInter& mdi : s) {
491489
rapidjson::Value jth = detail::toJSON(mdi, alloc);
492490
mdi_array.PushBack(jth, alloc);
493491
}
494-
rapidjson::Value mdi_obj{rapidjson::kObjectType};
495-
mdi_obj.AddMember("pieces", mdi_array, alloc);
496-
result.PushBack(mdi_obj, alloc);
492+
rapidjson::Value result{rapidjson::kObjectType};
493+
result.AddMember("pieces", mdi_array, alloc);
497494

498495
return result;
499496
}

0 commit comments

Comments
 (0)