rrsetlist.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2010 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. // $Id$
  15. #ifndef __RRSETLIST_H
  16. #define __RRSETLIST_H 1
  17. #include <iostream>
  18. #include <iterator>
  19. #include <vector>
  20. #include <boost/shared_ptr.hpp>
  21. #include "rrset.h"
  22. #include "rrclass.h"
  23. #include "rrtype.h"
  24. namespace isc {
  25. namespace dns {
  26. class DuplicateRRset : public Exception {
  27. public:
  28. DuplicateRRset(const char* file, size_t line, const char* what) :
  29. isc::Exception(file, line, what) {}
  30. };
  31. template <typename T, typename P, typename R>
  32. class RRsetListIterator :
  33. public std::iterator<std::input_iterator_tag, RRsetPtr> {
  34. public:
  35. RRsetListIterator() {}
  36. explicit RRsetListIterator(const T& it) :
  37. it_(it) {}
  38. RRsetListIterator& operator++()
  39. {
  40. ++it_;
  41. return (*this);
  42. }
  43. RRsetListIterator operator++(int)
  44. {
  45. RRsetListIterator tmp(*this);
  46. ++it_;
  47. return (tmp);
  48. }
  49. R operator*() const
  50. {
  51. return (*it_);
  52. }
  53. P operator->() const
  54. {
  55. return (it_.operator->());
  56. }
  57. bool operator==(const RRsetListIterator& other)
  58. {
  59. return (it_ == other.it_);
  60. }
  61. bool operator!=(const RRsetListIterator& other)
  62. {
  63. return (it_ != other.it_);
  64. }
  65. private:
  66. T it_;
  67. };
  68. class RRsetList {
  69. private:
  70. RRsetList(const RRsetList& source);
  71. RRsetList& operator=(const RRsetList& source);
  72. public:
  73. RRsetList() {}
  74. void addRRset(RRsetPtr new_rrsetptr);
  75. RRsetPtr findRRset(const RRType& rrtype,
  76. const RRClass& rrclass = RRClass::IN());
  77. RRsetPtr findRRset(ConstRRsetPtr rrsetptr);
  78. RRsetPtr operator[](const RRType& t) { return (this->findRRset(t)); }
  79. typedef RRsetListIterator<std::vector<RRsetPtr>::iterator,
  80. RRsetPtr*,
  81. RRsetPtr&> iterator;
  82. typedef RRsetListIterator<std::vector<RRsetPtr>::const_iterator,
  83. const RRsetPtr*,
  84. const RRsetPtr&> const_iterator;
  85. const_iterator begin() const { return (const_iterator(rrsets_.begin())); }
  86. const_iterator end() const { return (const_iterator(rrsets_.end())); }
  87. iterator begin() { return (iterator(rrsets_.begin())); }
  88. iterator end() { return (iterator(rrsets_.end())); }
  89. size_t size() const { return (rrsets_.size()); }
  90. private:
  91. std::vector<RRsetPtr> rrsets_;
  92. };
  93. } // end of namespace dns
  94. } // end of namespace isc
  95. #endif // __RRSETLIST_H
  96. // Local Variables:
  97. // mode: c++
  98. // End: