blocky/conv/fcode_bidx.cc
2022-09-09 11:26:01 +09:00

59 lines
1.2 KiB
C++

#include <fstream>
#include <iostream>
#include <string>
#include <args.hxx>
#include "common.hh"
namespace param {
using namespace ::args;
ArgumentParser parser {
"converter: feature codes -> block indices"
};
HelpFlag help {
parser, "help", "display this menu", {'h', "help"},
};
ValueFlag<std::string> fcmap {
parser, "path", "feature code map", {"fc-map"},
};
} // namespace param
static void Exec() {
std::ifstream fcmap_st {args::get(param::fcmap)};
Enforce(!!fcmap_st, "fcmap path is invalid");
const auto fcmap = ReadMatrix<uint32_t>(fcmap_st);
Enforce(fcmap.size() > 0, "empty fcmap");
for (auto& idxs : fcmap) {
Enforce(idxs.size() > 0, "fcmap has empty item");
}
size_t fcode;
while (std::cin >> fcode) {
Enforce(fcode < fcmap.size(), "fcode overflow");
for (const auto idx : fcmap[fcode]) {
std::cout << idx << ' ';
}
std::cout << '\n';
}
}
int main(int argc, char** argv)
try {
param::parser.ParseCLI(argc, argv);
Exec();
return EXIT_SUCCESS;
} catch (const args::Help&) {
std::cout << param::parser << std::endl;
return EXIT_SUCCESS;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}