Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2014-07-19 02:54:01 +0400
committerKenneth Heafield <github@kheafield.com>2014-07-19 02:54:01 +0400
commitc83c5a3ee6f3ef7480e7a782d2023af9e99c1711 (patch)
treefb662565ba0d21c35958d00bc6f672966eacaf99 /util
parent07d325876cbac72e538c0f03b5933c705c8efc09 (diff)
D'ph forgot to copy util
Diffstat (limited to 'util')
-rw-r--r--util/exception.hh8
-rw-r--r--util/read_compressed.cc11
-rw-r--r--util/read_compressed.hh4
3 files changed, 19 insertions, 4 deletions
diff --git a/util/exception.hh b/util/exception.hh
index 2fb00667f..4e50a6f3a 100644
--- a/util/exception.hh
+++ b/util/exception.hh
@@ -1,5 +1,5 @@
-#ifndef UTIL_EXCEPTION__
-#define UTIL_EXCEPTION__
+#ifndef UTIL_EXCEPTION_H
+#define UTIL_EXCEPTION_H
#include <exception>
#include <limits>
@@ -84,7 +84,7 @@ template <class Except, class Data> typename Except::template ExceptionTag<Excep
UTIL_THROW_BACKEND(NULL, Exception, , Modify);
#define UTIL_THROW2(Modify) \
- UTIL_THROW_BACKEND(NULL, util::Exception, , Modify);
+ UTIL_THROW_BACKEND(NULL, util::Exception, , Modify);
#if __GNUC__ >= 3
#define UTIL_UNLIKELY(x) __builtin_expect (!!(x), 0)
@@ -146,4 +146,4 @@ inline std::size_t CheckOverflow(uint64_t value) {
} // namespace util
-#endif // UTIL_EXCEPTION__
+#endif // UTIL_EXCEPTION_H
diff --git a/util/read_compressed.cc b/util/read_compressed.cc
index 71ef0e251..e1f4cd7e3 100644
--- a/util/read_compressed.cc
+++ b/util/read_compressed.cc
@@ -435,4 +435,15 @@ std::size_t ReadCompressed::Read(void *to, std::size_t amount) {
return internal_->Read(to, amount, *this);
}
+std::size_t ReadCompressed::ReadOrEOF(void *const to_in, std::size_t amount) {
+ uint8_t *to = reinterpret_cast<uint8_t*>(to_in);
+ while (amount) {
+ std::size_t got = Read(to, amount);
+ if (!got) break;
+ to += got;
+ amount -= got;
+ }
+ return to - reinterpret_cast<uint8_t*>(to_in);
+}
+
} // namespace util
diff --git a/util/read_compressed.hh b/util/read_compressed.hh
index 763e6bbd3..767ee94b2 100644
--- a/util/read_compressed.hh
+++ b/util/read_compressed.hh
@@ -62,6 +62,10 @@ class ReadCompressed {
std::size_t Read(void *to, std::size_t amount);
+ // Repeatedly call read to fill a buffer unless EOF is hit.
+ // Return number of bytes read.
+ std::size_t ReadOrEOF(void *const to, std::size_t amount);
+
uint64_t RawAmount() const { return raw_amount_; }
private: