Download mosesdecoder/util/exception.hh from suricodes/hindi-sindhi-docker: direct link, hf CLI and curl.
- Browser
- Download file 4.51 kB
-
https://huggingface.co/spaces/suricodes/hindi-sindhi-docker/resolve/main/mosesdecoder/util/exception.hh
- Command line
-
hf download hf://spaces/suricodes/hindi-sindhi-docker/mosesdecoder/util/exception.hh
-
curl -L -o exception.hh https://huggingface.co/spaces/suricodes/hindi-sindhi-docker/resolve/main/mosesdecoder/util/exception.hh
4.51 kB
| // TODO(hieu): delete this | |
| namespace util { | |
| template <class Except, class Data> typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data); | |
| class Exception : public std::exception { | |
| public: | |
| Exception() throw(); | |
| virtual ~Exception() throw(); | |
| const char *what() const throw() { return what_.str().c_str(); } | |
| // For use by the UTIL_THROW macros. | |
| void SetLocation( | |
| const char *file, | |
| unsigned int line, | |
| const char *func, | |
| const char *child_name, | |
| const char *condition); | |
| private: | |
| template <class Except, class Data> friend typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data); | |
| // This helps restrict operator<< defined below. | |
| template <class T> struct ExceptionTag { | |
| typedef T Identity; | |
| }; | |
| StringStream what_; | |
| }; | |
| /* This implements the normal operator<< for Exception and all its children. | |
| * SFINAE means it only applies to Exception. Think of this as an ersatz | |
| * boost::enable_if. | |
| */ | |
| template <class Except, class Data> typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data) { | |
| // TODO(hieu): delete this. | |
| std::stringstream moses_hack; | |
| moses_hack << data; | |
| e.what_ << moses_hack.str(); | |
| return e; | |
| } | |
| /* Create an instance of Exception, add the message Modify, and throw it. | |
| * Modify is appended to the what() message and can contain << for ostream | |
| * operations. | |
| * | |
| * do .. while kludge to swallow trailing ; character | |
| * http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html . | |
| * Arg can be a constructor argument to the exception. | |
| */ | |
| // Exception that records errno and adds it to the message. | |
| class ErrnoException : public Exception { | |
| public: | |
| ErrnoException() throw(); | |
| virtual ~ErrnoException() throw(); | |
| int Error() const throw() { return errno_; } | |
| private: | |
| int errno_; | |
| }; | |
| // file wasn't there, or couldn't be open for some reason | |
| class FileOpenException : public Exception { | |
| public: | |
| FileOpenException() throw() {} | |
| ~FileOpenException() throw() {} | |
| }; | |
| // Utilities for overflow checking. | |
| 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); | |
| } | |
| /* Thrown for Windows specific operations. */ | |
| class WindowsException : public Exception { | |
| public: | |
| WindowsException() throw(); | |
| ~WindowsException() throw(); | |
| }; | |
| } // namespace util | |