| 24 | {} |
| 25 | |
| 26 | void WikiUrlDumper::Dump(size_t cpuCount) const |
| 27 | { |
| 28 | CHECK_GREATER(cpuCount, 0, ()); |
| 29 | |
| 30 | base::ComputationalThreadPool threadPool(cpuCount); |
| 31 | std::vector<std::future<std::string>> futures; |
| 32 | futures.reserve(m_dataFiles.size()); |
| 33 | |
| 34 | auto const fn = [](std::string const & filename) |
| 35 | { |
| 36 | std::stringstream stringStream; |
| 37 | DumpOne(filename, stringStream); |
| 38 | return stringStream.str(); |
| 39 | }; |
| 40 | |
| 41 | for (auto const & path : m_dataFiles) |
| 42 | { |
| 43 | auto result = threadPool.Submit(fn, path); |
| 44 | futures.emplace_back(std::move(result)); |
| 45 | } |
| 46 | |
| 47 | std::ofstream stream; |
| 48 | stream.exceptions(std::fstream::failbit | std::fstream::badbit); |
| 49 | stream.open(m_path); |
| 50 | stream << "MwmPath\tosmId\twikipediaUrl\n"; |
| 51 | for (auto & f : futures) |
| 52 | { |
| 53 | auto lines = f.get(); |
| 54 | stream << lines; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // static |
| 59 | void WikiUrlDumper::DumpOne(std::string const & path, std::ostream & stream) |