diff options
author | Kenneth Heafield <github@kheafield.com> | 2013-01-20 16:25:58 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2013-01-20 16:25:58 +0400 |
commit | a52d97f99f743b81781d1106c9a17266b901ee6f (patch) | |
tree | aac20d2a0467284b70da1e9a7203c9364f8e459f /lm | |
parent | 8a3b93c72e7b24a6a1bf8a0fd409765539cbc507 (diff) |
Cross platform fixes
Diffstat (limited to 'lm')
-rw-r--r-- | lm/filter/arpa_io.cc | 32 | ||||
-rw-r--r-- | lm/filter/arpa_io.hh | 21 |
2 files changed, 16 insertions, 37 deletions
diff --git a/lm/filter/arpa_io.cc b/lm/filter/arpa_io.cc index 51264f750..f8568ac46 100644 --- a/lm/filter/arpa_io.cc +++ b/lm/filter/arpa_io.cc @@ -12,36 +12,22 @@ namespace lm { -ARPAInputException::ARPAInputException(const StringPiece &message) throw() : what_("Error: ") { - what_.append(message.data(), message.size()); +ARPAInputException::ARPAInputException(const StringPiece &message) throw() { + *this << message; } ARPAInputException::ARPAInputException(const StringPiece &message, const StringPiece &line) throw() { - what_ = "Error: "; - what_.append(message.data(), message.size()); - what_ += " in line '"; - what_.append(line.data(), line.size()); - what_ += "'."; + *this << message << " in line " << line; } -ARPAOutputException::ARPAOutputException(const char *message, const std::string &file_name) throw() - : what_(std::string(message) + " file " + file_name), file_name_(file_name) { - if (errno) { - char buf[1024]; - buf[0] = 0; -#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE - const char *add = buf; - if (!strerror_r(errno, buf, 1024)) { -#else - int add = strerror_r(errno, buf, 1024); - if (add) { -#endif - what_ += " :"; - what_ += add; - } - } +ARPAInputException::~ARPAInputException() throw() {} + +ARPAOutputException::ARPAOutputException(const char *message, const std::string &file_name) throw() { + *this << message << " in file " << file_name; } +ARPAOutputException::~ARPAOutputException() throw() {} + // Seeking is the responsibility of the caller. void WriteCounts(std::ostream &out, const std::vector<uint64_t> &number) { out << "\n\\data\\\n"; diff --git a/lm/filter/arpa_io.hh b/lm/filter/arpa_io.hh index 2a9579cc5..5b31620b5 100644 --- a/lm/filter/arpa_io.hh +++ b/lm/filter/arpa_io.hh @@ -16,6 +16,7 @@ #include <err.h> #include <string.h> +#include <stdint.h> namespace util { class FilePiece; } @@ -25,25 +26,17 @@ class ARPAInputException : public util::Exception { public: explicit ARPAInputException(const StringPiece &message) throw(); explicit ARPAInputException(const StringPiece &message, const StringPiece &line) throw(); - virtual ~ARPAInputException() throw() {} - - const char *what() const throw() { return what_.c_str(); } - - private: - std::string what_; + virtual ~ARPAInputException() throw(); }; -class ARPAOutputException : public std::exception { +class ARPAOutputException : public util::ErrnoException { public: ARPAOutputException(const char *prefix, const std::string &file_name) throw(); - virtual ~ARPAOutputException() throw() {} - - const char *what() const throw() { return what_.c_str(); } + virtual ~ARPAOutputException() throw(); const std::string &File() const throw() { return file_name_; } private: - std::string what_; const std::string file_name_; }; @@ -52,7 +45,7 @@ size_t SizeNeededForCounts(const std::vector<uint64_t> &number); /* Writes an ARPA file. This has to be seekable so the counts can be written * at the end. Hence, I just have it own a std::fstream instead of accepting - * a separately held std::ostream. + * a separately held std::ostream. TODO: use the fast one from estimation. */ class ARPAOutput : boost::noncopyable { public: @@ -92,10 +85,10 @@ class ARPAOutput : boost::noncopyable { }; -template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, size_t number, Output &out) { +template <class Output> void ReadNGrams(util::FilePiece &in, unsigned int length, uint64_t number, Output &out) { ReadNGramHeader(in, length); out.BeginLength(length); - for (size_t i = 0; i < number; ++i) { + for (uint64_t i = 0; i < number; ++i) { StringPiece line = in.ReadLine(); util::TokenIter<util::SingleCharacter> tabber(line, '\t'); if (!tabber) throw ARPAInputException("blank line", line); |