summaryrefslogtreecommitdiff
path: root/libjingle/xmllite/qname.h
blob: 1e772d3d676a39ad23a81fa5f06fd4adbf97cce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
#define WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_

#include <string>

namespace buzz {

class QName;

// StaticQName is used to represend constant quailified names. They
// can be initialized statically and don't need intializers code, e.g.
//   const StaticQName QN_FOO = { "foo_namespace", "foo" };
//
// Beside this use case, QName should be used everywhere
// else. StaticQName instances are implicitly converted to QName
// objects.
struct StaticQName {
  const char* const ns;
  const char* const local;

  bool operator==(const QName& other) const;
  bool operator!=(const QName& other) const;
};

class QName {
 public:
  QName();
  QName(const QName& qname);
  QName(const StaticQName& const_value);
  QName(const std::string& ns, const std::string& local);
  explicit QName(const std::string& merged_or_local);
  ~QName();

  const std::string& Namespace() const { return namespace_; }
  const std::string& LocalPart() const { return local_part_; }
  std::string Merged() const;
  bool IsEmpty() const;

  int Compare(const StaticQName& other) const;
  int Compare(const QName& other) const;

  bool operator==(const StaticQName& other) const {
    return Compare(other) == 0;
  }
  bool operator==(const QName& other) const {
    return Compare(other) == 0;
  }
  bool operator!=(const StaticQName& other) const {
    return Compare(other) != 0;
  }
  bool operator!=(const QName& other) const {
    return Compare(other) != 0;
  }
  bool operator<(const QName& other) const {
    return Compare(other) < 0;
  }

 private:
  std::string namespace_;
  std::string local_part_;
};

inline bool StaticQName::operator==(const QName& other) const {
  return other.Compare(*this) == 0;
}

inline bool StaticQName::operator!=(const QName& other) const {
  return other.Compare(*this) != 0;
}

}  // namespace buzz

#endif  // WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_