28 if (!binary) os <<
" ";
30 KALDI_ERR <<
"Write failure in WriteBasicType<bool>";
36 if (!binary) is >> std::ws;
41 }
else if (c ==
'F') {
45 KALDI_ERR <<
"Read failure in ReadBasicType<bool>, file position is " 55 os.write(reinterpret_cast<const char *>(&f),
sizeof(f));
66 os.write(reinterpret_cast<const char *>(&f),
sizeof(f));
78 if (c ==
sizeof(*f)) {
80 is.read(reinterpret_cast<char*>(f),
sizeof(*f));
81 }
else if (c ==
sizeof(d)) {
85 KALDI_ERR <<
"ReadBasicType: expected float, saw " << is.peek()
86 <<
", at file position " << is.tellg();
92 KALDI_ERR <<
"ReadBasicType: failed to read, at file position " 103 if (c ==
sizeof(*
d)) {
105 is.read(reinterpret_cast<char*>(
d),
sizeof(*
d));
106 }
else if (c ==
sizeof(f)) {
110 KALDI_ERR <<
"ReadBasicType: expected float, saw " << is.peek()
111 <<
", at file position " << is.tellg();
117 KALDI_ERR <<
"ReadBasicType: failed to read, at file position " 124 KALDI_ERR <<
"Token is empty (not a valid token)";
125 const char *orig_token = token;
126 while (*token !=
'\0') {
127 if (::isspace(*token))
128 KALDI_ERR <<
"Token is not a valid token (contains space): '" 129 << orig_token <<
"'";
134 void WriteToken(std::ostream &os,
bool binary,
const char *token) {
141 KALDI_ERR <<
"Write failure in WriteToken.";
145 int Peek(std::istream &is,
bool binary) {
146 if (!binary) is >> std::ws;
150 void WriteToken(std::ostream &os,
bool binary,
const std::string & token) {
154 void ReadToken(std::istream &is,
bool binary, std::string *str) {
156 if (!binary) is >> std::ws;
159 KALDI_ERR <<
"ReadToken, failed to read token at file position " 162 if (!isspace(is.peek())) {
163 KALDI_ERR <<
"ReadToken, expected space after token, saw instead " 165 <<
", at file position " << is.tellg();
171 if (!binary) is >> std::ws;
173 if (static_cast<char>(is.peek()) ==
'<') {
177 read_bracket =
false;
191 void ExpectToken(std::istream &is,
bool binary,
const char *token) {
192 int pos_at_start = is.tellg();
195 if (!binary) is >> std::ws;
200 KALDI_ERR <<
"Failed to read token [started at file position " 201 << pos_at_start <<
"], expected " << token;
207 if (strcmp(str.c_str(), token) != 0 &&
208 !(token[0] ==
'<' && strcmp(str.c_str(), token + 1) == 0)) {
209 KALDI_ERR <<
"Expected token \"" << token <<
"\", got instead \"" 214 void ExpectToken(std::istream &is,
bool binary,
const std::string &token) {
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void WriteBasicType< float >(std::ostream &os, bool binary, float f)
void CheckToken(const char *token)
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
void WriteBasicType< bool >(std::ostream &os, bool binary, bool b)
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
int Peek(std::istream &is, bool binary)
Peek consumes whitespace (if binary == false) and then returns the peek() value of the stream...
void WriteBasicType< double >(std::ostream &os, bool binary, double f)
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
#define KALDI_PARANOID_ASSERT(cond)
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
int PeekToken(std::istream &is, bool binary)
PeekToken will return the first character of the next token, or -1 if end of file.
std::string CharToString(const char &c)
#define KALDI_ASSERT(cond)
void ReadBasicType< bool >(std::istream &is, bool binary, bool *b)
void ReadBasicType< double >(std::istream &is, bool binary, double *d)
void ReadBasicType< float >(std::istream &is, bool binary, float *f)