gloox  1.0.28
error.h
1 /*
2  Copyright (c) 2007-2023 by Jakob Schröter <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 
89  void setAppError( Tag* appError );
90 
100  const std::string& text( const std::string& lang = EmptyString ) const;
101 
109  void setText( const std::string& text, const std::string& lang = EmptyString )
110  {
111  m_text[lang] = text;
112  }
113 
114  // reimplemented from StanzaExtension
115  virtual const std::string& filterString() const;
116 
117  // reimplemented from StanzaExtension
118  virtual StanzaExtension* newInstance( const Tag* tag ) const
119  {
120  return new Error( tag );
121  }
122 
123  // reimplemented from StanzaExtension
124  virtual Tag* tag() const;
125 
126  // reimplemented from StanzaExtension
127  virtual StanzaExtension* clone() const
128  {
129  return new Error( *this );
130  }
131 
132  private:
133  Error( const Error& error );
134 
135  void setValues( const Tag* tag );
136 
137  StanzaErrorType m_type;
138  StanzaError m_error;
139  Tag* m_appError;
140  StringMap m_text;
141  };
142 
143 }
144 
145 #endif // ERROR_H__
A stanza error abstraction implemented as a StanzaExtension.
Definition: error.h:35
StanzaErrorType type() const
Definition: error.h:69
void setText(const std::string &text, const std::string &lang=EmptyString)
Definition: error.h:109
Error(StanzaErrorType type, StanzaError error, Tag *appError=0)
Definition: error.h:55
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: error.h:118
const Tag * appError() const
Definition: error.h:83
StanzaError error() const
Definition: error.h:75
virtual StanzaExtension * clone() const
Definition: error.h:127
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28
const std::string EmptyString
Definition: gloox.cpp:124
StanzaError
Definition: gloox.h:872
StanzaErrorType
Definition: gloox.h:857
std::map< std::string, std::string > StringMap
Definition: gloox.h:1261