| 343 | } |
| 344 | |
| 345 | void StatisticsFileCSV::readHeaderFromFile(StatisticsData &statisticsData) |
| 346 | { |
| 347 | // TODO: Why is there a try block here? I see no throwing of anything ... |
| 348 | // We should get rid of this and just set an error and return on failure. |
| 349 | try |
| 350 | { |
| 351 | if (!this->file.isOk()) |
| 352 | return; |
| 353 | |
| 354 | statisticsData.clear(); |
| 355 | |
| 356 | // scan header lines first |
| 357 | // also count the lines per Frame for more efficient memory allocation |
| 358 | // if an ID is used twice, the data of the first gets overwritten |
| 359 | bool typeParsingActive = false; |
| 360 | StatisticsType aType; |
| 361 | |
| 362 | while (!this->file.atEnd()) |
| 363 | { |
| 364 | // read one line |
| 365 | auto aLineByteArray = this->file.readLine(); |
| 366 | QString aLine(aLineByteArray); |
| 367 | |
| 368 | // get components of this line |
| 369 | auto rowItemList = parseCSVLine(aLine, ';'); |
| 370 | |
| 371 | if (rowItemList[0].isEmpty()) |
| 372 | continue; |
| 373 | |
| 374 | // either a new type or a line which is not header finishes the last type |
| 375 | if (((rowItemList[1] == "type") || (rowItemList[0][0] != '%')) && typeParsingActive) |
| 376 | { |
| 377 | // Last type is complete. Store this initial state. |
| 378 | aType.setInitialState(); |
| 379 | statisticsData.addStatType(aType); |
| 380 | |
| 381 | // start from scratch for next item |
| 382 | aType = StatisticsType(); |
| 383 | typeParsingActive = false; |
| 384 | |
| 385 | // if we found a non-header line, stop here |
| 386 | if (rowItemList[0][0] != '%') |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | if (rowItemList[1] == "type") // new type |
| 391 | { |
| 392 | aType.typeID = rowItemList[2].toInt(); |
| 393 | aType.typeName = rowItemList[3]; |
| 394 | |
| 395 | // The next entry (4) is "map", "range", or "vector" |
| 396 | if (rowItemList.count() >= 5) |
| 397 | { |
| 398 | if (rowItemList[4] == "map" || rowItemList[4] == "range") |
| 399 | { |
| 400 | aType.hasValueData = true; |
| 401 | aType.renderValueData = true; |
| 402 | } |
no test coverage detected