Constructor
| 15 | { |
| 16 | /// Constructor |
| 17 | Subtypes::Subtypes() |
| 18 | { |
| 19 | auto const & classificator = classif(); |
| 20 | |
| 21 | // Get the stream to the CSV file. |
| 22 | Platform & platform = GetPlatform(); |
| 23 | unique_ptr<ModelReader> reader = platform.GetReader(SUBTYPES_FILE); |
| 24 | ReaderStreamBuf buffer(std::move(reader)); |
| 25 | istream stream(&buffer); |
| 26 | |
| 27 | // Load the CSV file and go through the lines of it one by one. |
| 28 | for (auto const & columns : coding::CSVRunner(coding::CSVReader(stream, true, ';'))) |
| 29 | { |
| 30 | // Skip empty lines. |
| 31 | if (columns.empty()) |
| 32 | continue; |
| 33 | |
| 34 | // There only should be two columns. |
| 35 | if (columns.size() != 2) |
| 36 | { |
| 37 | ASSERT(false, ("Parsing of subtypes file: Invalid columns \"", columns, "\"")); |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | // Parse the column. The first column has the type definitions(s) and the second one has the associated subtype |
| 42 | // definitions(s). |
| 43 | vector<uint32_t> types; |
| 44 | vector<uint32_t> subtypes; |
| 45 | for (int columnIndex = 0; columnIndex < 2; columnIndex++) |
| 46 | { |
| 47 | string_view const column = columns[columnIndex]; |
| 48 | |
| 49 | // Separate the different type definitions by the `,`. There needs to be at least one. |
| 50 | vector<string_view> const typeDefinitions = strings::Tokenize(column, ","); |
| 51 | if (typeDefinitions.size() < 1) |
| 52 | { |
| 53 | ASSERT(columnIndex != 0, ("Parsing of subtypes file: Invalid or missing types definition \"", column, "\"")); |
| 54 | ASSERT(columnIndex == 0, ("Parsing of subtypes file: Invalid or missing subtypes definition \"", column, "\"")); |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | // Parse the type definitions and convert them to actual types. Invalid types are getting skipped. |
| 59 | vector<uint32_t> typesInColumn; |
| 60 | for (auto typeDefinition : typeDefinitions) |
| 61 | { |
| 62 | vector<string_view> const typePath = strings::Tokenize(typeDefinition, "|"); |
| 63 | uint32_t const type = classificator.GetTypeByPathSafe(typePath); |
| 64 | if (type != IndexAndTypeMapping::INVALID_TYPE) |
| 65 | { |
| 66 | typesInColumn.push_back(type); |
| 67 | |
| 68 | vector<string> typesAndSubtypesPath(typePath.begin(), typePath.end()); |
| 69 | if (find(m_typesAndSubtypesPaths.begin(), m_typesAndSubtypesPaths.end(), typesAndSubtypesPath) == |
| 70 | m_typesAndSubtypesPaths.end()) |
| 71 | m_typesAndSubtypesPaths.push_back(typesAndSubtypesPath); |
| 72 | } |
| 73 | else |
| 74 | { |
nothing calls this directly
no test coverage detected