------------------------------------------------------------------------------
| 448 | |
| 449 | //------------------------------------------------------------------------------ |
| 450 | void vtkTable::InsertColumn(vtkAbstractArray* arr, vtkIdType index) |
| 451 | { |
| 452 | if (this->GetNumberOfColumns() > 0 && arr->GetNumberOfTuples() != this->GetNumberOfRows()) |
| 453 | { |
| 454 | vtkErrorMacro(<< "Column \"" << arr->GetName() << "\" must have " << this->GetNumberOfRows() |
| 455 | << " rows, but has " << arr->GetNumberOfTuples() << "."); |
| 456 | return; |
| 457 | } |
| 458 | // ensure index is sensible |
| 459 | index = std::max<vtkIdType>(0, std::min<vtkIdType>(this->GetNumberOfColumns(), index)); |
| 460 | |
| 461 | // insert at end? |
| 462 | if (index == this->GetNumberOfColumns()) |
| 463 | { |
| 464 | this->AddColumn(arr); |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | // remove all arrays from RowData, then insert them again in correct order with new array inserted |
| 469 | // note: use vtkSmartPointer to preserve a reference count, else this->RowData->RemoveArray(0) |
| 470 | // will delete the array |
| 471 | vtkIdType ncols = this->GetNumberOfColumns(); |
| 472 | std::vector<vtkSmartPointer<vtkAbstractArray>> store; |
| 473 | store.reserve(ncols); |
| 474 | |
| 475 | for (int c = 0; c < ncols; c++) |
| 476 | { |
| 477 | if (c == index) |
| 478 | { |
| 479 | store.emplace_back(arr); |
| 480 | } |
| 481 | store.emplace_back(this->GetColumn(0)); |
| 482 | this->RowData->RemoveArray(0); |
| 483 | } |
| 484 | |
| 485 | for (unsigned long c = 0; c < store.size(); c++) |
| 486 | { |
| 487 | this->RowData->AddArray(store[c]); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | //------------------------------------------------------------------------------ |
| 492 | void vtkTable::RemoveColumnByName(const char* name) |