serial.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dns/serial.h>
  15. namespace isc {
  16. namespace dns {
  17. bool
  18. Serial::operator==(const Serial& other) const {
  19. return (value_ == other.getValue());
  20. }
  21. bool
  22. Serial::operator!=(const Serial& other) const {
  23. return (value_ != other.getValue());
  24. }
  25. bool
  26. Serial::operator<(const Serial& other) const {
  27. uint32_t other_val = other.getValue();
  28. bool result = false;
  29. if (value_ < other_val) {
  30. result = ((other_val - value_) <= MAX_SERIAL_INCREMENT);
  31. } else if (other_val < value_) {
  32. result = ((value_ - other_val) > MAX_SERIAL_INCREMENT);
  33. }
  34. return (result);
  35. }
  36. bool
  37. Serial::operator<=(const Serial& other) const {
  38. return (operator==(other) || operator<(other));
  39. }
  40. bool
  41. Serial::operator>(const Serial& other) const {
  42. return (!operator==(other) && !operator<(other));
  43. }
  44. bool
  45. Serial::operator>=(const Serial& other) const {
  46. return (!operator<(other));
  47. }
  48. Serial
  49. Serial::operator+(uint32_t other_val) const {
  50. uint64_t new_val = static_cast<uint64_t>(value_) +
  51. static_cast<uint64_t>(other_val);
  52. return Serial(static_cast<uint32_t>(new_val % MAX_SERIAL_VALUE));
  53. }
  54. Serial
  55. Serial::operator+(const Serial& other) const {
  56. return (operator+(other.getValue()));
  57. }
  58. std::ostream&
  59. operator<<(std::ostream& os, const Serial& serial) {
  60. return (os << serial.getValue());
  61. }
  62. } // end namespace dns
  63. } // end namespace isc