gloox  1.0
error.h
00001 /*
00002   Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 #ifndef ERROR_H__
00014 #define ERROR_H__
00015 
00016 #include "gloox.h"
00017 #include "stanzaextension.h"
00018 
00019 #include <string>
00020 #include <map>
00021 
00022 namespace gloox
00023 {
00024 
00025   class Tag;
00026 
00034   class GLOOX_API Error : public StanzaExtension
00035   {
00036     public:
00037 
00038 //       Error()
00039 //         : StanzaExtension( ExtError ), m_type( StanzaErrorTypeUndefined ),
00040 //           m_error( StanzaErrorUndefined ), m_appError( 0 )
00041 //       {}
00042 
00047       Error( const Tag* tag = 0 );
00048 
00055       Error( StanzaErrorType type, StanzaError error, Tag* appError = 0 )
00056         : StanzaExtension( ExtError ), m_type( type ),
00057           m_error( error ), m_appError( appError )
00058       {}
00059 
00063       virtual ~Error();
00064 
00069       StanzaErrorType type() const { return m_type; }
00070 
00075       StanzaError error() const { return m_error; }
00076 
00083       const Tag* appError() const { return m_appError; }
00084 
00094       const std::string& text( const std::string& lang = EmptyString ) const;
00095 
00103       void setText( const std::string& text, const std::string& lang = EmptyString )
00104       {
00105         m_text[lang] = text;
00106       }
00107 
00108       // reimplemented from StanzaExtension
00109       virtual const std::string& filterString() const;
00110 
00111       // reimplemented from StanzaExtension
00112       virtual StanzaExtension* newInstance( const Tag* tag ) const
00113       {
00114         return new Error( tag );
00115       }
00116 
00117       // reimplemented from StanzaExtension
00118       virtual Tag* tag() const;
00119 
00120       // reimplemented from StanzaExtension
00121       virtual StanzaExtension* clone() const
00122       {
00123         return new Error( *this );
00124       }
00125 
00126     private:
00127       Error( const Error& error );
00128 
00129       void setValues( const Tag* tag );
00130 
00131       StanzaErrorType m_type;
00132       StanzaError m_error;
00133       Tag* m_appError;
00134       StringMap m_text;
00135   };
00136 
00137 }
00138 
00139 #endif /* ERROR_H__ */