MCPcopy Create free account
hub / github.com/Kitware/VTK / SetAttribute

Method SetAttribute

Common/DataModel/vtkXMLDataElement.cxx:197–247  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

195
196//------------------------------------------------------------------------------
197void vtkXMLDataElement::SetAttribute(const char* name, const char* value)
198{
199 if (!name || !name[0] || !value || !value[0])
200 {
201 return;
202 }
203
204 int i;
205
206 // Set an existing attribute
207
208 for (i = 0; i < this->NumberOfAttributes; ++i)
209 {
210 if (!strcmp(this->AttributeNames[i], name))
211 {
212 delete[] this->AttributeValues[i];
213 this->AttributeValues[i] = new char[strlen(value) + 1];
214 strcpy(this->AttributeValues[i], value);
215 return;
216 }
217 }
218
219 // Or add an attribute
220
221 if (this->NumberOfAttributes == this->AttributesSize)
222 {
223 int newSize = this->AttributesSize * 2;
224 char** newAttributeNames = new char*[newSize];
225 char** newAttributeValues = new char*[newSize];
226 for (i = 0; i < this->NumberOfAttributes; ++i)
227 {
228 newAttributeNames[i] = new char[strlen(this->AttributeNames[i]) + 1];
229 strcpy(newAttributeNames[i], this->AttributeNames[i]);
230 delete[] this->AttributeNames[i];
231 newAttributeValues[i] = new char[strlen(this->AttributeValues[i]) + 1];
232 strcpy(newAttributeValues[i], this->AttributeValues[i]);
233 delete[] this->AttributeValues[i];
234 }
235 delete[] this->AttributeNames;
236 delete[] this->AttributeValues;
237 this->AttributeNames = newAttributeNames;
238 this->AttributeValues = newAttributeValues;
239 this->AttributesSize = newSize;
240 }
241
242 i = this->NumberOfAttributes++;
243 this->AttributeNames[i] = new char[strlen(name) + 1];
244 strcpy(this->AttributeNames[i], name);
245 this->AttributeValues[i] = new char[strlen(value) + 1];
246 strcpy(this->AttributeValues[i], value);
247}
248
249//------------------------------------------------------------------------------
250void vtkXMLDataElement::AddNestedElement(vtkXMLDataElement* element)

Callers 2

DeepCopyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected