00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "error.h"
00018 #include <glib.h>
00019 #include <QtCore/QDebug>
00020
00021 namespace QGlib {
00022
00023 Error::Error(GError *error)
00024 : std::exception()
00025 {
00026 m_error = error;
00027 }
00028
00029 Error::Error(Quark domain, int code, const QString & message)
00030 : std::exception()
00031 {
00032 m_error = g_error_new_literal(domain, code, message.toUtf8());
00033 }
00034
00035 Error::Error(const Error & other)
00036 : std::exception()
00037 {
00038 m_error = g_error_copy(other.m_error);
00039 }
00040
00041 Error & Error::operator=(const Error & other)
00042 {
00043 g_error_free(m_error);
00044 m_error = g_error_copy(other.m_error);
00045 return *this;
00046 }
00047
00048 Error::~Error() throw()
00049 {
00050 g_error_free(m_error);
00051 }
00052
00053 const char* Error::what() const throw()
00054 {
00055 return m_error->message;
00056 }
00057
00058 Quark Error::domain() const
00059 {
00060 return m_error->domain;
00061 }
00062
00063 int Error::code() const
00064 {
00065 return m_error->code;
00066 }
00067
00068 QString Error::message() const
00069 {
00070 return QString::fromUtf8(m_error->message);
00071 }
00072
00073 Error::operator GError *()
00074 {
00075 return m_error;
00076 }
00077
00078 Error::operator const GError *() const
00079 {
00080 return m_error;
00081 }
00082
00083 QDebug operator<<(QDebug dbg, const Error & error)
00084 {
00085 return dbg << error.message();
00086 }
00087
00088 }