diff options
author | Barry Haddow <barry.haddow@gmail.com> | 2012-10-08 20:54:59 +0400 |
---|---|---|
committer | Barry Haddow <barry.haddow@gmail.com> | 2012-10-08 20:54:59 +0400 |
commit | 848aafb64478f843e25a800c57243b38609465ef (patch) | |
tree | be3dce6647a1a300b48ccbd32b36dc65b56c998f /util/exception.hh | |
parent | e7e4dbd405e8d29a9a429c6b5eb366a2fe0ecf9a (diff) | |
parent | 2aa10c3012328d8fd66ceee26c25e3d8771f9f31 (diff) |
Merge remote branch 'github/master' into miramerge
Conflicts:
moses/src/AlignmentInfo.cpp
moses/src/AlignmentInfo.h
moses/src/ChartHypothesis.cpp
moses/src/ChartTrellisNode.cpp
moses/src/LM/Implementation.cpp
moses/src/LM/Ken.cpp
moses/src/TargetPhrase.cpp
moses/src/TargetPhrase.h
Diffstat (limited to 'util/exception.hh')
-rw-r--r-- | util/exception.hh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/util/exception.hh b/util/exception.hh index 6d6a37cb1..83f99cd6f 100644 --- a/util/exception.hh +++ b/util/exception.hh @@ -2,9 +2,12 @@ #define UTIL_EXCEPTION__ #include <exception> +#include <limits> #include <sstream> #include <string> +#include <inttypes.h> + namespace util { template <class Except, class Data> typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data); @@ -111,6 +114,25 @@ class EndOfFileException : public Exception { ~EndOfFileException() throw(); }; +class OverflowException : public Exception { + public: + OverflowException() throw(); + ~OverflowException() throw(); +}; + +template <unsigned len> inline std::size_t CheckOverflowInternal(uint64_t value) { + UTIL_THROW_IF(value > static_cast<uint64_t>(std::numeric_limits<std::size_t>::max()), OverflowException, "Integer overflow detected. This model is too big for 32-bit code."); + return value; +} + +template <> inline std::size_t CheckOverflowInternal<8>(uint64_t value) { + return value; +} + +inline std::size_t CheckOverflow(uint64_t value) { + return CheckOverflowInternal<sizeof(std::size_t)>(value); +} + } // namespace util #endif // UTIL_EXCEPTION__ |