rrsetlist.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <vector>
  16. #include <boost/foreach.hpp>
  17. #include <exceptions/exceptions.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrtype.h>
  20. #include <dns/rrset.h>
  21. #include <dns/rrsetlist.h>
  22. namespace isc {
  23. namespace dns {
  24. void
  25. RRsetList::addRRset(RRsetPtr rrsetptr) {
  26. ConstRRsetPtr rrset_found = findRRset(rrsetptr->getType(),
  27. rrsetptr->getClass());
  28. if (rrset_found != NULL) {
  29. isc_throw(DuplicateRRset, "RRset is being doubly added to RRsetList: "
  30. "type=" << rrsetptr->getType() << ", class=" <<
  31. rrsetptr->getClass());
  32. }
  33. rrsets_.push_back(rrsetptr);
  34. }
  35. RRsetPtr
  36. RRsetList::findRRset(const RRType& rrtype, const RRClass& rrclass) {
  37. BOOST_FOREACH(RRsetPtr rrsetptr, rrsets_) {
  38. if ((rrsetptr->getClass() == rrclass) &&
  39. (rrsetptr->getType() == rrtype)) {
  40. return rrsetptr;
  41. }
  42. }
  43. return RRsetPtr();
  44. }
  45. }
  46. }