gloox  0.9.9.12
jid.h
1 /*
2  Copyright (c) 2005-2008 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 
15 #ifndef JID_H__
16 #define JID_H__
17 
18 #include "macros.h"
19 
20 #include <string>
21 
22 namespace gloox
23 {
30  class GLOOX_API JID
31  {
32  public:
33 
37  JID() {}
38 
43  JID( const std::string& jid ) { setJID( jid ); }
44 
48  ~JID() {}
49 
54  void setJID( const std::string& jid );
55 
60  const std::string& full() const { return m_full; }
61 
66  const std::string& bare() const { return m_bare; }
67 
73  JID bareJID() const { return JID( bare() ); }
74 
81  GLOOX_DEPRECATED JID fullJID() const { return JID( full() ); }
82 
87  void setUsername( const std::string& username );
88 
93  void setServer( const std::string& server );
94 
99  void setResource( const std::string& resource );
100 
105  const std::string& username() const { return m_username; }
106 
111  const std::string& server() const { return m_server; }
112 
117  const std::string& serverRaw() const { return m_serverRaw; }
118 
123  const std::string& resource() const { return m_resource; }
124 
130  GLOOX_DEPRECATED bool empty() const { return m_server.empty(); }
131 
136  bool operator==( const JID& right ) const { return full() == right.full(); }
137 
142  bool operator!=( const JID& right ) const { return full() != right.full(); }
143 
147  operator bool() const { return !m_server.empty(); }
148 
149  private:
150  std::string m_resource;
151  std::string m_username;
152  std::string m_server;
153  std::string m_serverRaw;
154  std::string m_bare;
155  std::string m_full;
156 
160  void setStrings() { setBare(); setFull(); }
161 
166  void setBare();
167 
171  void setFull();
172  };
173 
174 }
175 
176 #endif // JID_H__