------------------------------------------------------------------------------
| 117 | |
| 118 | //------------------------------------------------------------------------------ |
| 119 | void vtkAbstractArray::SetComponentName(vtkIdType component, const char* name) |
| 120 | { |
| 121 | if (component < 0 || name == nullptr) |
| 122 | { |
| 123 | return; |
| 124 | } |
| 125 | unsigned int index = static_cast<unsigned int>(component); |
| 126 | if (this->ComponentNames == nullptr) |
| 127 | { |
| 128 | // delayed allocate |
| 129 | this->ComponentNames = new vtkAbstractArray::vtkInternalComponentNames(); |
| 130 | } |
| 131 | |
| 132 | if (index == this->ComponentNames->size()) |
| 133 | { |
| 134 | // the array isn't large enough, so we will resize |
| 135 | this->ComponentNames->push_back(new std::string(name)); |
| 136 | return; |
| 137 | } |
| 138 | else if (index > this->ComponentNames->size()) |
| 139 | { |
| 140 | this->ComponentNames->resize(index + 1, nullptr); |
| 141 | } |
| 142 | |
| 143 | // replace an existing element |
| 144 | std::string* compName = this->ComponentNames->at(index); |
| 145 | if (!compName) |
| 146 | { |
| 147 | compName = new std::string(name); |
| 148 | this->ComponentNames->at(index) = compName; |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | compName->assign(name); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | //------------------------------------------------------------------------------ |
| 157 | const char* vtkAbstractArray::GetComponentName(vtkIdType component) const |