------------------------------------------------------------------------------
| 312 | |
| 313 | //------------------------------------------------------------------------------ |
| 314 | vtkIdType vtkNewickTreeReader::BuildTree(char* buffer, vtkMutableDirectedGraph* g, |
| 315 | vtkDoubleArray* weights, vtkStringArray* names, vtkIdType parent) |
| 316 | { |
| 317 | char* current; |
| 318 | char* start; |
| 319 | char* colon = nullptr; |
| 320 | char temp; |
| 321 | int childCount; |
| 322 | vtkIdType node; |
| 323 | |
| 324 | start = buffer; |
| 325 | |
| 326 | if (*start != '(') |
| 327 | { |
| 328 | // Leaf node. Separate name from weight (if it exists). |
| 329 | current = buffer; |
| 330 | while (*current != '\0') |
| 331 | { |
| 332 | if (*current == ':') |
| 333 | { |
| 334 | colon = current; |
| 335 | } |
| 336 | current++; |
| 337 | } |
| 338 | node = g->AddChild(parent); |
| 339 | if (colon == nullptr) |
| 340 | { |
| 341 | // Name only |
| 342 | std::string name(start, strlen(start)); |
| 343 | names->SetValue(node, name); |
| 344 | } |
| 345 | else |
| 346 | { |
| 347 | // Name |
| 348 | *colon = '\0'; |
| 349 | std::string name(start, strlen(start)); |
| 350 | names->SetValue(node, name); |
| 351 | *colon = ':'; |
| 352 | // Weight |
| 353 | colon++; |
| 354 | double weight; |
| 355 | VTK_FROM_CHARS_IF_ERROR_BREAK(colon, weight); |
| 356 | weights->SetValue(g->GetEdgeId(parent, node), weight); |
| 357 | } |
| 358 | } |
| 359 | else |
| 360 | { |
| 361 | // Create node |
| 362 | if (parent == -1) |
| 363 | { |
| 364 | node = g->AddVertex(); |
| 365 | names->SetValue(node, ""); |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | node = g->AddChild(parent); |
| 370 | } |
| 371 |
no test coverage detected