! * \brief feed different data to diffferent parser * \param path data file path or data string */
| 10 | * \param path data file path or data string |
| 11 | */ |
| 12 | void DataParser::feed(const std::string& path) { |
| 13 | std::string blob_name = "data", blob_string = path; |
| 14 | size_t sep = path.find(":"); |
| 15 | if (sep != std::string::npos) { |
| 16 | blob_name = path.substr(0, sep); |
| 17 | blob_string = path.substr(sep + 1); |
| 18 | } |
| 19 | |
| 20 | auto endWith = [blob_string](std::string suffix) -> bool { |
| 21 | const auto index = blob_string.rfind(suffix); |
| 22 | if (index != std::string::npos and |
| 23 | index == blob_string.length() - suffix.length()) { |
| 24 | return true; |
| 25 | } |
| 26 | return false; |
| 27 | }; |
| 28 | |
| 29 | if (endWith(".ppm") || endWith(".pgm")) { |
| 30 | parse_image(blob_name, blob_string); |
| 31 | } else if (endWith(".json")) { |
| 32 | parse_json(blob_string); |
| 33 | } else if (endWith(".npy")) { |
| 34 | parse_npy(blob_name, blob_string); |
| 35 | } else { |
| 36 | parse_string(blob_name, blob_string); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void DataParser::parse_json(const std::string& path) { |
| 41 | mgb::JsonLoader json; |
no test coverage detected