• Main Page
  • Classes
  • Files
  • File List

Swiften/JID/JID.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <string>
00010 //#include <iosfwd>
00011 #include <iostream>
00012 
00013 #include <Swiften/Base/API.h>
00014 
00015 namespace Swift {
00027   class SWIFTEN_API JID {
00028     public:
00029       enum CompareType {
00030         WithResource, WithoutResource
00031       };
00032 
00044       JID(const std::string& jid = std::string());
00045 
00049       JID(const char*);
00050 
00060       JID(const std::string& node, const std::string& domain);
00071       JID(const std::string& node, const std::string& domain, const std::string& resource);
00072 
00076       bool isValid() const {
00077         return valid_;
00078       }
00079 
00084       const std::string& getNode() const {
00085         return node_;
00086       }
00087 
00091       const std::string& getDomain() const {
00092         return domain_;
00093       }
00094 
00099       const std::string& getResource() const {
00100         return resource_;
00101       }
00102 
00106       bool isBare() const {
00107         return !hasResource_;
00108       }
00109 
00115       static std::string getEscapedNode(const std::string& node);
00116 
00120       std::string getUnescapedNode() const;
00121 
00126       JID toBare() const {
00127         JID result(*this);
00128         result.hasResource_ = false;
00129         result.resource_ = "";
00130         return result;
00131       }
00132 
00133       std::string toString() const;
00134 
00135       bool equals(const JID& o, CompareType compareType) const {
00136         return compare(o, compareType) == 0;
00137       }
00138 
00139       int compare(const JID& o, CompareType compareType) const;
00140 
00141       operator std::string() const {
00142         return toString();
00143       }
00144 
00145       bool operator<(const Swift::JID& b) const {
00146         return compare(b, Swift::JID::WithResource) < 0;
00147       }
00148 
00149       friend std::ostream& operator<<(std::ostream& os, const Swift::JID& j) {
00150         os << j.toString();
00151         return os;
00152       }
00153 
00154       friend bool operator==(const Swift::JID& a, const Swift::JID& b) {
00155         return a.compare(b, Swift::JID::WithResource) == 0;
00156       }
00157 
00158       friend bool operator!=(const Swift::JID& a, const Swift::JID& b) {
00159         return a.compare(b, Swift::JID::WithResource) != 0;
00160       }
00161 
00162     private:
00163       void nameprepAndSetComponents(const std::string& node, const std::string& domain, const std::string& resource);
00164       void initializeFromString(const std::string&);
00165   
00166     private:
00167       bool valid_;
00168       std::string node_;
00169       std::string domain_;
00170       bool hasResource_;
00171       std::string resource_;
00172   };
00173 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1