diff options
| author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-11-05 15:29:46 +0100 | 
|---|---|---|
| committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-11-05 15:29:46 +0100 | 
| commit | 6f29f345dc06c1a1033475eac1d1340781d1d603 (patch) | |
| tree | 6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /klm/util/exception.hh | |
| parent | b510da2e562c695c90d565eb295c749569c59be8 (diff) | |
| parent | c615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff) | |
merge upstream/master
Diffstat (limited to 'klm/util/exception.hh')
| -rw-r--r-- | klm/util/exception.hh | 22 | 
1 files changed, 22 insertions, 0 deletions
diff --git a/klm/util/exception.hh b/klm/util/exception.hh index 6d6a37cb..053a850b 100644 --- a/klm/util/exception.hh +++ b/klm/util/exception.hh @@ -2,9 +2,12 @@  #define UTIL_EXCEPTION__  #include <exception> +#include <limits>  #include <sstream>  #include <string> +#include <stdint.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__  | 
