20 #include <sys/types.h> 32 #include <string_view> 39 std::vector<WeightClass> *potentials) {
40 std::ifstream istrm(source);
42 LOG(ERROR) <<
"ReadPotentials: Can't open file: " << source;
45 static constexpr
int kLineLen = 8096;
49 while (!istrm.getline(line, kLineLen).fail()) {
51 std::vector<std::string_view> col =
53 if (col.empty() || col[0].empty())
continue;
54 if (col.size() != 2) {
55 FSTERROR() <<
"ReadPotentials: Bad number of columns, " 56 <<
"file = " << source <<
", line = " << nline;
59 const ssize_t s =
StrToInt64(col[0], source, nline);
61 while (potentials->size() <= s) {
64 potentials->back() = weight;
71 const std::vector<WeightClass> &potentials) {
73 if (!source.empty()) {
76 LOG(ERROR) <<
"WritePotentials: Can't open file: " << source;
80 std::ostream &strm = ostrm.is_open() ? ostrm : std::cout;
82 for (
size_t s = 0; s < potentials.size(); ++s) {
83 strm << s <<
"\t" << potentials[s] <<
"\n";
86 LOG(ERROR) <<
"WritePotentials: Write failed: " 87 << (source.empty() ?
"standard output" : source);
bool WritePotentials(const std::string &source, const std::vector< WeightClass > &potentials)
internal::StringSplitter StrSplit(std::string_view full, ByAnyChar delim)
static WeightClass Zero(std::string_view weight_type)
bool ReadPotentials(std::string_view weight_type, const std::string &source, std::vector< WeightClass > *potentials)
int64_t StrToInt64(std::string_view s, std::string_view source, size_t nline, bool *error=nullptr)