QtGStreamer  1.2.0
 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::copy(GError *error)
36 {
37  return Error(error ? g_error_copy(error) : NULL);
38 }
39 
40 Error::Error(const Error & other)
41  : std::exception()
42 {
43  m_error = other.m_error ? g_error_copy(other.m_error) : NULL;
44 }
45 
46 Error & Error::operator=(const Error & other)
47 {
48  if (m_error != other.m_error) {
49  if(m_error) {
50  g_error_free(m_error);
51  }
52 
53  m_error = other.m_error ? g_error_copy(other.m_error) : NULL;
54  }
55  return *this;
56 }
57 
58 Error::~Error() throw()
59 {
60  if (m_error) {
61  g_error_free(m_error);
62  }
63 }
64 
65 const char* Error::what() const throw()
66 {
67  return m_error ? m_error->message : "";
68 }
69 
71 {
72  return m_error ? m_error->domain : 0;
73 }
74 
75 int Error::code() const
76 {
77  return m_error ? m_error->code : 0;
78 }
79 
80 QString Error::message() const
81 {
82  return m_error ? QString::fromUtf8(m_error->message) : QString();
83 }
84 
85 Error::operator GError *()
86 {
87  return m_error;
88 }
89 
90 Error::operator const GError *() const
91 {
92  return m_error;
93 }
94 
95 QDebug operator<<(QDebug dbg, const Error & error)
96 {
97  return dbg << error.message();
98 }
99 
100 } //namespace QGlib
Error(GError *error=NULL)
Definition: error.cpp:23
int code() const
Definition: error.cpp:75
Quark domain() const
Definition: error.cpp:70
virtual const char * what() const
Definition: error.cpp:65
QString message() const
Definition: error.cpp:80
Wrapper class for GQuark.
Definition: quark.h:42
Wrapper class for GError.
Definition: error.h:30