iterator.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef __DATASRC_ZONE_ITERATOR_H
  15. #define __DATASRC_ZONE_ITERATOR_H 1
  16. #include <dns/rrset.h>
  17. #include <boost/noncopyable.hpp>
  18. #include <datasrc/zone.h>
  19. namespace isc {
  20. namespace datasrc {
  21. /**
  22. * \brief Read-only iterator to a zone.
  23. *
  24. * You can get an instance of (descendand of) ZoneIterator from
  25. * DataSourceClient::getIterator() method. The actual concrete implementation
  26. * will be different depending on the actual data source used. This is the
  27. * abstract interface.
  28. *
  29. * There's no way to start iterating from the beginning again or return.
  30. */
  31. class ZoneIterator : public boost::noncopyable {
  32. public:
  33. /**
  34. * \brief Destructor
  35. *
  36. * Virtual destructor. It is empty, but ensures the right destructor from
  37. * descendant is called.
  38. */
  39. virtual ~ ZoneIterator() { }
  40. /**
  41. * \brief Get next RRset from the zone.
  42. *
  43. * This returns the next RRset in the zone as a shared pointer. The
  44. * shared pointer is used to allow both accessing in-memory data and
  45. * automatic memory management.
  46. *
  47. * Any special order is not guaranteed.
  48. *
  49. * While this can potentially throw anything (including standard allocation
  50. * errors), it should be rare.
  51. *
  52. * \return Pointer to the next RRset or NULL pointer when the iteration
  53. * gets to the end of the zone.
  54. */
  55. virtual isc::dns::ConstRRsetPtr getNextRRset() = 0;
  56. /**
  57. * \brief Return the SOA record of the zone in the iterator context.
  58. *
  59. * This method returns the zone's SOA record (if any, and a valid zone
  60. * should have it) in the form of an RRset object. This SOA is identical
  61. * to that (again, if any) contained in the sequence of RRsets returned
  62. * by the iterator. In that sense this method is redundant, but is
  63. * provided as a convenient utility for the application of the
  64. * iterator; the application may need to know the SOA serial or the
  65. * SOA RR itself for the purpose of protocol handling or skipping the
  66. * expensive iteration processing.
  67. *
  68. * If the zone doesn't have an SOA (which is broken, but some data source
  69. * may allow that situation), this method returns NULL. Also, in the
  70. * normal and valid case, the SOA should have exactly one RDATA, but
  71. * this API does not guarantee it as some data source may accept such an
  72. * abnormal condition. It's up to the caller whether to check the number
  73. * of RDATA and how to react to the unexpected case.
  74. *
  75. * Each concrete derived method must ensure that the SOA returned by this
  76. * method is identical to the zone's SOA returned via the iteration.
  77. * For example, even if another thread or process updates the SOA while
  78. * the iterator is working, the result of this method must not be
  79. * affected by the update. For database based data sources, this can
  80. * be done by making the entire iterator operation as a single database
  81. * transaction, but the actual implementation can differ.
  82. *
  83. * \exception None
  84. *
  85. * \return A shared pointer to an SOA RRset that would be returned
  86. * from the iteration. It will be NULL if the zone doesn't have an SOA.
  87. */
  88. virtual isc::dns::ConstRRsetPtr getSOA() const = 0;
  89. };
  90. }
  91. }
  92. #endif // __DATASRC_ZONE_ITERATOR_H
  93. // Local Variables:
  94. // mode: c++
  95. // End: