Soprano  2.7.4
/srv/build/STABLE_8/pkgs/soprano/BUILD/soprano-2.7.4/soprano/error.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of Soprano Project.
00003  *
00004  * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #ifndef _SOPRANO_ERROR_H_
00023 #define _SOPRANO_ERROR_H_
00024 
00025 #include "soprano_export.h"
00026 
00027 #include <QtCore/QString>
00028 #include <QtCore/QSharedDataPointer>
00029 
00030 
00031 namespace Soprano {
00032     namespace Error {
00040         enum ErrorCode {
00041             ErrorNone = 0x0,             
00042             ErrorInvalidArgument = 0x1,  
00043             ErrorInvalidStatement = ErrorInvalidArgument, 
00044             ErrorNotSupported = 0x2,     
00045             ErrorParsingFailed = 0x3,    
00046             ErrorPermissionDenied = 0x4, 
00047             ErrorTimeout = 0x5,          
00048             ErrorUnknown = 0x1000        
00049         };
00050 
00054         SOPRANO_EXPORT QString errorMessage( ErrorCode );
00055 
00063         SOPRANO_EXPORT ErrorCode convertErrorCode( int code );
00064 
00065         class ErrorData;
00066         class ParserError;
00067 
00077         class SOPRANO_EXPORT Error
00078         {
00079         public:
00083             Error();
00084 
00093             Error( const QString& message, int code = ErrorUnknown );
00094 
00098             Error( const Error& );
00099 
00103             virtual ~Error();
00104 
00105             Error& operator=( const Error& );
00106 
00121             operator bool() const { return code() != ErrorNone; }
00122 
00131             QString message() const;
00132 
00147             int code() const;
00148 
00153             bool isParserError() const;
00154 
00167             ParserError toParserError() const;
00168 
00169         protected:
00171             Error( ErrorData* );
00172             QSharedDataPointer<ErrorData> d;
00174         };
00175 
00176         class Locator;
00177 
00200         class SOPRANO_EXPORT ParserError : public Error
00201         {
00202         public:
00206             ParserError();
00207 
00208             ParserError( const Locator&, const QString& message = QString(), int code = ErrorParsingFailed );
00209 
00210             ParserError( const Error& );
00211 
00212             ~ParserError();
00213 
00214             ParserError& operator=( const Error& );
00215 
00216             Locator locator() const;
00217         };
00218 
00234         class SOPRANO_EXPORT ErrorCache
00235         {
00236         public:
00237             virtual ~ErrorCache();
00238 
00242             virtual Error lastError() const;
00243 
00244         protected:
00245             ErrorCache();
00246 
00250             void clearError() const;
00251 
00257             void setError( const Error& ) const;
00258 
00263             void setError( const QString& errorMessage, int code = ErrorUnknown ) const;
00264 
00265         private:
00266             class Private;
00267             Private* const d;
00268         };
00269     }
00270 }
00271 
00272 class QDebug;
00273 class QTextStream;
00274 
00275 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::Error::Error& );
00276 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::Error::Error& );
00277 
00278 #endif