QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
error.cpp
1 /*
2  Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "error.h"
18 #include <glib.h>
19 #include <QtCore/QDebug>
20 
21 namespace QGlib {
22 
23 Error::Error(GError *error)
24  : std::exception()
25 {
26  m_error = error;
27 }
28 
29 Error::Error(Quark domain, int code, const QString & message)
30  : std::exception()
31 {
32  m_error = g_error_new_literal(domain, code, message.toUtf8());
33 }
34 
35 Error::Error(const Error & other)
36  : std::exception()
37 {
38  m_error = g_error_copy(other.m_error);
39 }
40 
41 Error & Error::operator=(const Error & other)
42 {
43  g_error_free(m_error);
44  m_error = g_error_copy(other.m_error);
45  return *this;
46 }
47 
48 Error::~Error() throw()
49 {
50  g_error_free(m_error);
51 }
52 
53 const char* Error::what() const throw()
54 {
55  return m_error->message;
56 }
57 
59 {
60  return m_error->domain;
61 }
62 
63 int Error::code() const
64 {
65  return m_error->code;
66 }
67 
68 QString Error::message() const
69 {
70  return QString::fromUtf8(m_error->message);
71 }
72 
73 Error::operator GError *()
74 {
75  return m_error;
76 }
77 
78 Error::operator const GError *() const
79 {
80  return m_error;
81 }
82 
83 QDebug operator<<(QDebug dbg, const Error & error)
84 {
85  return dbg << error.message();
86 }
87 
88 } //namespace QGlib