Home | History | Annotate | Download | only in xmllite
      1 /*
      2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
     12 #define WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
     13 
     14 #include <string>
     15 
     16 namespace buzz {
     17 
     18 class QName;
     19 
     20 // StaticQName is used to represend constant quailified names. They
     21 // can be initialized statically and don't need intializers code, e.g.
     22 //   const StaticQName QN_FOO = { "foo_namespace", "foo" };
     23 //
     24 // Beside this use case, QName should be used everywhere
     25 // else. StaticQName instances are implicitly converted to QName
     26 // objects.
     27 struct StaticQName {
     28   const char* const ns;
     29   const char* const local;
     30 
     31   bool operator==(const QName& other) const;
     32   bool operator!=(const QName& other) const;
     33 };
     34 
     35 class QName {
     36  public:
     37   QName();
     38   QName(const QName& qname);
     39   QName(const StaticQName& const_value);
     40   QName(const std::string& ns, const std::string& local);
     41   explicit QName(const std::string& merged_or_local);
     42   ~QName();
     43 
     44   const std::string& Namespace() const { return namespace_; }
     45   const std::string& LocalPart() const { return local_part_; }
     46   std::string Merged() const;
     47   bool IsEmpty() const;
     48 
     49   int Compare(const StaticQName& other) const;
     50   int Compare(const QName& other) const;
     51 
     52   bool operator==(const StaticQName& other) const {
     53     return Compare(other) == 0;
     54   }
     55   bool operator==(const QName& other) const {
     56     return Compare(other) == 0;
     57   }
     58   bool operator!=(const StaticQName& other) const {
     59     return Compare(other) != 0;
     60   }
     61   bool operator!=(const QName& other) const {
     62     return Compare(other) != 0;
     63   }
     64   bool operator<(const QName& other) const {
     65     return Compare(other) < 0;
     66   }
     67 
     68  private:
     69   std::string namespace_;
     70   std::string local_part_;
     71 };
     72 
     73 inline bool StaticQName::operator==(const QName& other) const {
     74   return other.Compare(*this) == 0;
     75 }
     76 
     77 inline bool StaticQName::operator!=(const QName& other) const {
     78   return other.Compare(*this) != 0;
     79 }
     80 
     81 }  // namespace buzz
     82 
     83 #endif  // WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
     84