24
static char* s_errorMessages[] = {
25
#include <QtCore/QHash>
26
#include <QtCore/QThread>
27
#include <QtCore/QDebug>
32
class ErrorData : public QSharedData
35
ErrorData( const QString& m = QString(), int c = ErrorNone )
40
virtual ~ErrorData() {
50
Soprano::Error::Error::Error()
51
: d( new ErrorData() )
56
Soprano::Error::Error::Error( ErrorData* data )
62
Soprano::Error::Error::Error( const QString& message, int code )
63
: d( new ErrorData( message, code ) )
65
if ( d->message.isEmpty() && code < ErrorUnknown ) {
66
d->message = errorMessage( ( ErrorCode )code );
71
Soprano::Error::Error::Error( const Error& other )
77
Soprano::Error::Error::~Error()
82
Soprano::Error::Error& Soprano::Error::Error::operator=( const Error& other )
89
QString Soprano::Error::Error::message() const
95
int Soprano::Error::Error::code() const
103
class ParserErrorData : public Soprano::Error::ErrorData
106
ParserErrorData( const Locator& loc = Locator(), const QString& message = QString(), int code = ErrorNone )
107
: ErrorData( message, code ),
116
bool Soprano::Error::Error::isParserError() const
118
return dynamic_cast<const ParserErrorData*>( d.constData() ) != 0;
122
Soprano::Error::ParserError Soprano::Error::Error::toParserError() const
124
return ParserError( *this );
128
Soprano::Error::ParserError::ParserError()
129
: Error( new ParserErrorData() )
134
Soprano::Error::ParserError::ParserError( const Locator& loc, const QString& message, int code )
135
: Error( new ParserErrorData( loc, message, code ) )
140
Soprano::Error::ParserError::ParserError( const Error& other )
146
Soprano::Error::ParserError::~ParserError()
151
Soprano::Error::ParserError& Soprano::Error::ParserError::operator=( const Error& other )
153
Error::operator=( other );
158
Soprano::Error::Locator Soprano::Error::ParserError::locator() const
160
const ParserErrorData* data = dynamic_cast<const ParserErrorData*>( d.constData() );
162
return data->locator;
171
// /////////////////////////////////////
173
// /////////////////////////////////////
176
class Soprano::Error::ErrorCache::Private
179
QHash<QThread*, Error> errorMap;
30
QString Soprano::errorMessage( ErrorCode code )
32
// FIXME: translate the strings.
33
return s_errorMessages[(int)code];
183
Soprano::Error::ErrorCache::ErrorCache()
189
Soprano::Error::ErrorCache::~ErrorCache()
195
Soprano::Error::Error Soprano::Error::ErrorCache::lastError() const
197
return d->errorMap[QThread::currentThread()];
201
void Soprano::Error::ErrorCache::setError( const Error& error ) const
204
qDebug() << "(Soprano) Error occured in thread" << QThread::currentThreadId() << ":" << error;
207
d->errorMap[QThread::currentThread()] = error;
211
void Soprano::Error::ErrorCache::setError( const QString& errorMessage, int code ) const
213
setError( Error( errorMessage, code ) );
217
void Soprano::Error::ErrorCache::clearError() const
219
d->errorMap[QThread::currentThread()] = Error();
224
const int s_maxErr = 3;
225
const char* s_errorMessages[] = {
228
"Unsupported operation",
234
QString Soprano::Error::errorMessage( ErrorCode code )
236
// FIXME: translate the strings.
237
if ( code >= 0 && code <= s_maxErr ) {
238
return s_errorMessages[(int)code];
241
return "Unknown error";
246
Soprano::Error::ErrorCode Soprano::Error::convertErrorCode( int code )
248
if ( code >= 0 && code <= s_maxErr ) {
249
return ( ErrorCode )code;
257
QDebug operator<<( QDebug s, const Soprano::Error::Error& error )
259
if ( error.code() < Soprano::Error::ErrorUnknown ) {
260
s.nospace() << errorMessage( ( Soprano::Error::ErrorCode )error.code() ) << ": ";
262
s.nospace() << error.message();
264
if ( error.isParserError() ) {
265
Soprano::Error::ParserError pe( error );
266
s.nospace() << " (line: " << pe.locator().line() << ", column: " << pe.locator().column() << ")";
273
QTextStream& operator<<( QTextStream& s, const Soprano::Error::Error& error )
275
if ( error.code() < Soprano::Error::ErrorUnknown ) {
276
s << errorMessage( ( Soprano::Error::ErrorCode )error.code() ) << ": ";
278
s << error.message();
280
if ( error.isParserError() ) {
281
Soprano::Error::ParserError pe( error );
282
s << " (line: " << pe.locator().line() << ", column: " << pe.locator().column() << ")";