| 326 | } |
| 327 | |
| 328 | lbug_state lbug_value_create_list(uint64_t num_elements, lbug_value** elements, |
| 329 | lbug_value** out_value) { |
| 330 | if (out_value == nullptr) { |
| 331 | return LbugError; |
| 332 | } |
| 333 | if (num_elements == 0) { |
| 334 | *out_value = createCAPIValue(std::make_unique<Value>(LogicalType::LIST(LogicalType::ANY()), |
| 335 | std::vector<std::unique_ptr<Value>>{})); |
| 336 | return LbugSuccess; |
| 337 | } |
| 338 | if (elements == nullptr) { |
| 339 | return LbugError; |
| 340 | } |
| 341 | std::vector<std::unique_ptr<Value>> children; |
| 342 | |
| 343 | auto first_element = static_cast<Value*>(elements[0]->_value); |
| 344 | auto type = first_element->getDataType().copy(); |
| 345 | |
| 346 | for (uint64_t i = 0; i < num_elements; ++i) { |
| 347 | auto child = static_cast<Value*>(elements[i]->_value); |
| 348 | LogicalType resultType; |
| 349 | if (!tryGetMaxParameterType(type, child->getDataType(), resultType)) { |
| 350 | setLastCAPIErrorMessage(incompatibleParameterTypeMessage(type, child->getDataType())); |
| 351 | return LbugError; |
| 352 | } |
| 353 | type = std::move(resultType); |
| 354 | } |
| 355 | for (uint64_t i = 0; i < num_elements; ++i) { |
| 356 | auto child = static_cast<Value*>(elements[i]->_value); |
| 357 | if (!canCopyValueForNested(*child, type)) { |
| 358 | setLastCAPIErrorMessage(incompatibleParameterTypeMessage(child->getDataType(), type)); |
| 359 | return LbugError; |
| 360 | } |
| 361 | children.push_back(copyValueForNested(*child, type)); |
| 362 | } |
| 363 | auto* c_value = createCAPIValue( |
| 364 | std::make_unique<Value>(LogicalType::LIST(type.copy()), std::move(children))); |
| 365 | *out_value = c_value; |
| 366 | return LbugSuccess; |
| 367 | } |
| 368 | |
| 369 | lbug_state lbug_value_create_struct(uint64_t num_fields, const char** field_names, |
| 370 | lbug_value** field_values, lbug_value** out_value) { |