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