gloox  1.0.9
stanza.h
1 /*
2  Copyright (c) 2005-2013 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 
126  void setEmbeddedStanza() { m_hasEmbeddedStanza = true; }
127 
135  bool hasEmbeddedStanza() const { return m_hasEmbeddedStanza; }
136 
145  Stanza* embeddedStanza() const;
146 
156  Tag* embeddedTag() const;
157 
166  virtual Tag* tag() const = 0;
167 
168  protected:
174  Stanza( Tag* tag );
175 
181  Stanza( const JID& to );
182 
183  StanzaExtensionList m_extensionList;
184  std::string m_id;
185  std::string m_xmllang;
186  JID m_from;
187  JID m_to;
188 
189  static const std::string& findLang( const StringMap* map,
190  const std::string& defaultData,
191  const std::string& lang );
192 
193  static void setLang( StringMap** map,
194  std::string& defaultLang,
195  const Tag* tag );
196 
197  static void setLang( StringMap** map,
198  std::string& defaultLang,
199  const std::string& data,
200  const std::string& xmllang );
201 
202  static void getLangs( const StringMap* map,
203  const std::string& defaultData,
204  const std::string& name, Tag* tag );
205 
206  private:
207  Stanza( const Stanza& );
208 
209  bool m_hasEmbeddedStanza;
210 
211  };
212 
213 }
214 
215 #endif // STANZA_H__