Skip to content

Commit dab9c06

Browse files
committed
Merge remote-tracking branch 'willstott101/bugfix/dynamic-sequence-print' into ch3/hotfix-dynamic-data-helper
2 parents 5c1bc2e + 7c04c8d commit dab9c06

File tree

1 file changed

+51
-14
lines changed

1 file changed

+51
-14
lines changed

src/cpp/dynamic-types/DynamicDataHelper.cpp

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,33 @@ void DynamicDataHelper::aux_index_position(
251251
void DynamicDataHelper::print_basic_collection(
252252
DynamicData* data)
253253
{
254-
const std::vector<uint32_t>& bounds = data->type_->descriptor_->bound_;
254+
if (data->type_->get_kind() == TK_SEQUENCE)
255+
{
256+
auto count = data->get_item_count();
257+
std::cout << "[";
258+
for (size_t i = 0; i < count; ++i)
259+
{
260+
print_basic_element(data, i, data->type_->get_element_type()->get_kind());
261+
std::cout << (i == count - 1 ? "]" : ", ");
262+
}
263+
if (count == 0)
264+
{
265+
std::cout << "]";
266+
}
267+
}
268+
else
269+
{
270+
const std::vector<uint32_t>& bounds = data->type_->descriptor_->bound_;
255271

256-
std::vector<std::vector<uint32_t>> positions;
257-
fill_array_positions(bounds, positions);
272+
std::vector<std::vector<uint32_t>> positions;
273+
fill_array_positions(bounds, positions);
258274

259-
std::cout << "[";
260-
for (size_t i = 0; i < positions.size(); ++i)
261-
{
262-
print_basic_element(data, data->get_array_index(positions[i]), data->type_->get_element_type()->get_kind());
263-
std::cout << (i == positions.size() - 1 ? "]" : ", ");
275+
std::cout << "[";
276+
for (size_t i = 0; i < positions.size(); ++i)
277+
{
278+
print_basic_element(data, data->get_array_index(positions[i]), data->type_->get_element_type()->get_kind());
279+
std::cout << (i == positions.size() - 1 ? "]" : ", ");
280+
}
264281
}
265282
std::cout << std::endl;
266283
}
@@ -270,15 +287,35 @@ void DynamicDataHelper::print_complex_collection(
270287
const std::string& tabs)
271288
{
272289
std::cout << std::endl;
273-
const std::vector<uint32_t>& bounds = data->type_->descriptor_->bound_;
290+
if (data->type_->get_kind() == TK_SEQUENCE)
291+
{
292+
auto count = data->get_item_count();
274293

275-
std::vector<std::vector<uint32_t>> positions;
276-
fill_array_positions(bounds, positions);
294+
for (size_t i = 0; i < count; ++i)
295+
{
296+
std::cout << tabs << "[" << i << "] = ";
297+
print_complex_element(data, i, tabs);
298+
std::cout << std::endl;
299+
}
277300

278-
for (size_t i = 0; i < positions.size(); ++i)
301+
if (count == 0)
302+
{
303+
std::cout << "[]";
304+
}
305+
}
306+
else
279307
{
280-
std::cout << tabs << "[" << i << "] = ";
281-
print_complex_element(data, data->get_array_index(positions[i]), tabs);
308+
const std::vector<uint32_t>& bounds = data->type_->descriptor_->bound_;
309+
310+
std::vector<std::vector<uint32_t>> positions;
311+
fill_array_positions(bounds, positions);
312+
313+
for (size_t i = 0; i < positions.size(); ++i)
314+
{
315+
std::cout << tabs << "[" << i << "] = ";
316+
print_complex_element(data, data->get_array_index(positions[i]), tabs);
317+
std::cout << std::endl;
318+
}
282319
}
283320
}
284321

0 commit comments

Comments
 (0)