blob: b10f14ea66d28017b3aaa702c8cb119d116fd918 [file] [log] [blame]
Karl Wiberg98900742018-03-01 12:03:49 +01001/*
2 * Copyright (c) 2018 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 API_AUDIO_CODECS_AUDIO_CODEC_PAIR_ID_H_
12#define API_AUDIO_CODECS_AUDIO_CODEC_PAIR_ID_H_
13
14#include <stdint.h>
15
16#include <utility>
17
18namespace webrtc {
19
20class AudioCodecPairId final {
21 public:
22 // Copyable, but not default constructible.
23 AudioCodecPairId() = delete;
24 AudioCodecPairId(const AudioCodecPairId&) = default;
25 AudioCodecPairId(AudioCodecPairId&&) = default;
26 AudioCodecPairId& operator=(const AudioCodecPairId&) = default;
27 AudioCodecPairId& operator=(AudioCodecPairId&&) = default;
28
29 friend void swap(AudioCodecPairId& a, AudioCodecPairId& b) {
30 using std::swap;
31 swap(a.id_, b.id_);
32 }
33
34 // Creates a new ID, unequal to any previously created ID.
35 static AudioCodecPairId Create();
36
37 // IDs can be tested for equality.
38 friend bool operator==(AudioCodecPairId a, AudioCodecPairId b) {
39 return a.id_ == b.id_;
40 }
41 friend bool operator!=(AudioCodecPairId a, AudioCodecPairId b) {
42 return a.id_ != b.id_;
43 }
44
45 // Comparisons. The ordering of ID values is completely arbitrary, but
46 // stable, so it's useful e.g. if you want to use IDs as keys in an ordered
47 // map.
48 friend bool operator<(AudioCodecPairId a, AudioCodecPairId b) {
49 return a.id_ < b.id_;
50 }
51 friend bool operator<=(AudioCodecPairId a, AudioCodecPairId b) {
52 return a.id_ <= b.id_;
53 }
54 friend bool operator>=(AudioCodecPairId a, AudioCodecPairId b) {
55 return a.id_ >= b.id_;
56 }
57 friend bool operator>(AudioCodecPairId a, AudioCodecPairId b) {
58 return a.id_ > b.id_;
59 }
60
61 // Returns a numeric representation of the ID. The numeric values are
62 // completely arbitrary, but stable, collision-free, and reasonably evenly
63 // distributed, so they are e.g. useful as hash values in unordered maps.
64 uint64_t NumericRepresentation() const { return id_; }
65
66 private:
67 explicit AudioCodecPairId(uint64_t id) : id_(id) {}
68
69 uint64_t id_;
70};
71
72} // namespace webrtc
73
74#endif // API_AUDIO_CODECS_AUDIO_CODEC_PAIR_ID_H_