#include "mappings.hpp" #include #include #include #include #include #include #include #include #include namespace fs = boost::filesystem; namespace mappings { void loadFile(std::string path, std::map *map) { std::ifstream file(path); std::string line; while (std::getline(file, line)) { std::vector splits; boost::algorithm::split(splits, line, boost::is_any_of(",\t|")); if (splits.size() < 2) { BOOST_LOG_TRIVIAL(warning) << "found invalid mapping '" << line << "'"; continue; } (*map)[splits[0]] = splits[1]; } } Mappings Mappings::load() { std::map mappings; std::map renames; // load mappings fs::directory_iterator end_itr; for (fs::directory_iterator itr("mappings"); itr != end_itr; ++itr) { if (fs::is_directory(itr->status()) || !boost::algorithm::ends_with(itr->path().string(), ".csv")) continue; loadFile(itr->path().string(), &mappings); } if (fs::is_regular_file("renames.csv")) { loadFile("renames.csv", &renames); } BOOST_LOG_TRIVIAL(info) << "loaded " << mappings.size() << " mappings and " << renames.size() << " renames"; return {mappings, renames}; } std::string Mappings::map(std::string inp) { if (!this->mappings.count(inp)) { BOOST_LOG_TRIVIAL(warning) << "unknown mapping '" << inp << "'"; return ""; } auto mapped = this->mappings[inp]; if (this->renames.count(mapped)) return renames[mapped]; return mapped; } } // namespace mappings