qname.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMLLITE_QNAME_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMLLITE_QNAME_H_
  12. #include <string>
  13. namespace jingle_xmpp {
  14. class QName;
  15. // StaticQName is used to represend constant quailified names. They
  16. // can be initialized statically and don't need intializers code, e.g.
  17. // const StaticQName QN_FOO = { "foo_namespace", "foo" };
  18. //
  19. // Beside this use case, QName should be used everywhere
  20. // else. StaticQName instances are implicitly converted to QName
  21. // objects.
  22. struct StaticQName {
  23. const char* const ns;
  24. const char* const local;
  25. bool operator==(const QName& other) const;
  26. bool operator!=(const QName& other) const;
  27. };
  28. class QName {
  29. public:
  30. QName();
  31. QName(const QName& qname);
  32. QName(const StaticQName& const_value);
  33. QName(const std::string& ns, const std::string& local);
  34. explicit QName(const std::string& merged_or_local);
  35. ~QName();
  36. const std::string& Namespace() const { return namespace_; }
  37. const std::string& LocalPart() const { return local_part_; }
  38. std::string Merged() const;
  39. bool IsEmpty() const;
  40. int Compare(const StaticQName& other) const;
  41. int Compare(const QName& other) const;
  42. bool operator==(const StaticQName& other) const {
  43. return Compare(other) == 0;
  44. }
  45. bool operator==(const QName& other) const {
  46. return Compare(other) == 0;
  47. }
  48. bool operator!=(const StaticQName& other) const {
  49. return Compare(other) != 0;
  50. }
  51. bool operator!=(const QName& other) const {
  52. return Compare(other) != 0;
  53. }
  54. bool operator<(const QName& other) const {
  55. return Compare(other) < 0;
  56. }
  57. private:
  58. std::string namespace_;
  59. std::string local_part_;
  60. };
  61. inline bool StaticQName::operator==(const QName& other) const {
  62. return other.Compare(*this) == 0;
  63. }
  64. inline bool StaticQName::operator!=(const QName& other) const {
  65. return other.Compare(*this) != 0;
  66. }
  67. } // namespace jingle_xmpp
  68. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMLLITE_QNAME_H_