gloox  1.0.1
error.h
1 /*
2  Copyright (c) 2007-2012 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 #ifndef ERROR_H__
14 #define ERROR_H__
15 
16 #include "gloox.h"
17 #include "stanzaextension.h"
18 
19 #include <string>
20 #include <map>
21 
22 namespace gloox
23 {
24 
25  class Tag;
26 
34  class GLOOX_API Error : public StanzaExtension
35  {
36  public:
37 
38 // Error()
39 // : StanzaExtension( ExtError ), m_type( StanzaErrorTypeUndefined ),
40 // m_error( StanzaErrorUndefined ), m_appError( 0 )
41 // {}
42 
47  Error( const Tag* tag = 0 );
48 
55  Error( StanzaErrorType type, StanzaError error, Tag* appError = 0 )
56  : StanzaExtension( ExtError ), m_type( type ),
57  m_error( error ), m_appError( appError )
58  {}
59 
63  virtual ~Error();
64 
69  StanzaErrorType type() const { return m_type; }
70 
75  StanzaError error() const { return m_error; }
76 
83  const Tag* appError() const { return m_appError; }
84 
94  const std::string& text( const std::string& lang = EmptyString ) const;
95 
103  void setText( const std::string& text, const std::string& lang = EmptyString )
104  {
105  m_text[lang] = text;
106  }
107 
108  // reimplemented from StanzaExtension
109  virtual const std::string& filterString() const;
110 
111  // reimplemented from StanzaExtension
112  virtual StanzaExtension* newInstance( const Tag* tag ) const
113  {
114  return new Error( tag );
115  }
116 
117  // reimplemented from StanzaExtension
118  virtual Tag* tag() const;
119 
120  // reimplemented from StanzaExtension
121  virtual StanzaExtension* clone() const
122  {
123  return new Error( *this );
124  }
125 
126  private:
127  Error( const Error& error );
128 
129  void setValues( const Tag* tag );
130 
131  StanzaErrorType m_type;
132  StanzaError m_error;
133  Tag* m_appError;
134  StringMap m_text;
135  };
136 
137 }
138 
139 #endif /* ERROR_H__ */