genesys: Support message argument to exceptions

merge-requests/86/head
Povilas Kanapickas 2019-07-06 02:10:03 +03:00
rodzic 72d68c7367
commit 9d07e2108a
1 zmienionych plików z 33 dodań i 2 usunięć

Wyświetl plik

@ -104,11 +104,42 @@
class SaneException : std::exception {
public:
SaneException(SANE_Status status) : status_(status) {}
SaneException(SANE_Status status) : status_(status)
{
set_msg(nullptr);
}
SaneException(SANE_Status status, const char* msg) : status_(status)
{
set_msg(msg);
}
SaneException(const char* msg) : SaneException(SANE_STATUS_INVAL, msg) {}
SANE_Status status() const { return status_; }
virtual const char* what() const noexcept override { return sane_strstatus(status_); }
virtual const char* what() const noexcept override { return msg_.c_str(); }
private:
void set_msg(const char* msg)
{
const char* status_msg = sane_strstatus(status_);
std::size_t status_msg_len = std::strlen(status_msg);
if (msg) {
std::size_t msg_len = std::strlen(msg);
msg_.reserve(msg_len + status_msg_len + 3);
msg_ = msg;
msg_ += " : ";
msg_ += status_msg;
return;
}
msg_.reserve(status_msg_len);
msg_ = status_msg;
}
std::string msg_;
SANE_Status status_;
};