30 #include <string_view> 37 std::vector<WeightClass> *potentials) {
38 std::ifstream istrm(source);
40 LOG(ERROR) <<
"ReadPotentials: Can't open file: " << source;
43 static constexpr
int kLineLen = 8096;
47 while (!istrm.getline(line, kLineLen).fail()) {
49 std::vector<std::string_view> col =
51 if (col.empty() || col[0].empty())
continue;
52 if (col.size() != 2) {
53 FSTERROR() <<
"ReadPotentials: Bad number of columns, " 54 <<
"file = " << source <<
", line = " << nline;
57 const ssize_t s =
StrToInt64(col[0], source, nline,
false);
59 while (potentials->size() <= s) {
62 potentials->back() = weight;
69 const std::vector<WeightClass> &potentials) {
71 if (!source.empty()) {
74 LOG(ERROR) <<
"WritePotentials: Can't open file: " << source;
78 std::ostream &strm = ostrm.is_open() ? ostrm : std::cout;
80 for (
size_t s = 0; s < potentials.size(); ++s) {
81 strm << s <<
"\t" << potentials[s] <<
"\n";
84 LOG(ERROR) <<
"WritePotentials: Write failed: " 85 << (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 allow_negative, bool *error=nullptr)