gloox  1.1-svn
stanza.h
1 /*
2  Copyright (c) 2005-2009 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 
14 #ifndef STANZA_H__
15 #define STANZA_H__
16 
17 #include "gloox.h"
18 #include "tag.h"
19 #include "jid.h"
20 #include "stanzaextension.h"
21 
22 namespace gloox
23 {
24 
25  class Error;
26 
33  class GLOOX_API Stanza
34  {
35  public:
39  virtual ~Stanza();
40 
45  void setFrom( const JID& from ) { m_from = from; }
46 
51  const JID& from() const { return m_from; }
52 
57  const JID& to() const { return m_to; }
58 
63  const std::string& id() const { return m_id; }
64 
69  const Error* error() const;
70 
76  const std::string& xmlLang() const { return m_xmllang; }
77 
85  void addExtension( const StanzaExtension* se );
86 
92  const StanzaExtension* findExtension( int type ) const;
93 
103  template< class T >
104  inline const T* findExtension( int type ) const
105  {
106  return static_cast<const T*>( findExtension( type ) );
107  }
108 
113  const StanzaExtensionList& extensions() const { return m_extensionList; }
114 
118  void removeExtensions();
119 
127  virtual Tag* tag() const = 0;
128 
129  protected:
135  Stanza( Tag* tag );
136 
142  Stanza( const JID& to );
143 
144  StanzaExtensionList m_extensionList;
145  std::string m_id;
146  std::string m_xmllang;
147  JID m_from;
148  JID m_to;
149 
150  static const std::string& findLang( const StringMap* map,
151  const std::string& defaultData,
152  const std::string& lang );
153 
154  static void setLang( StringMap** map,
155  std::string& defaultLang,
156  const Tag* tag );
157 
158  static void setLang( StringMap** map,
159  std::string& defaultLang,
160  const std::string& data,
161  const std::string& xmllang );
162 
163  static void getLangs( const StringMap* map,
164  const std::string& defaultData,
165  const std::string& name, Tag* tag );
166 
167  private:
168  Stanza( const Stanza& );
169 
170  };
171 
172 }
173 
174 #endif // STANZA_H__