audio_codec_pair_id.h 2.3 KB

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