Kea  2.3.5-git
rrset_collection_base.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef RRSET_COLLECTION_BASE_H
8 #define RRSET_COLLECTION_BASE_H 1
9 
10 #include <dns/rrset.h>
11 #include <dns/name.h>
12 
13 #include <boost/shared_ptr.hpp>
14 
15 #include <iterator>
16 
17 namespace isc {
18 namespace dns {
19 
27 public:
28  RRsetCollectionError(const char* file, size_t line, const char* what) :
29  Exception(file, line, what)
30  {}
31 };
32 
45 public:
91  virtual isc::dns::ConstRRsetPtr find
92  (const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
93  const isc::dns::RRType& rrtype)
94  const = 0;
95 
97  virtual ~RRsetCollectionBase() {}
98 
99 protected:
100  class Iter; // forward declaration
101 
103  typedef boost::shared_ptr<Iter> IterPtr;
104 
113  class Iter {
114  public:
115  virtual ~Iter() {};
116 
119  virtual const isc::dns::AbstractRRset& getValue() = 0;
120 
123  virtual IterPtr getNext() = 0;
124 
134  virtual bool equals(Iter& other) = 0;
135  };
136 
142  virtual IterPtr getBeginning() = 0;
143 
149  virtual IterPtr getEnd() = 0;
150 
151 public:
156  class Iterator {
157  public:
158  // Aliases used to enable iterator behavior on this class
159  using iterator_category = std::forward_iterator_tag;
161  using difference_type = std::ptrdiff_t;
164 
165  explicit Iterator(IterPtr iter) :
166  iter_(iter)
167  {}
168 
170  return (iter_->getValue());
171  }
172 
174  iter_ = iter_->getNext();
175  return (*this);
176  }
177 
179  Iterator tmp(iter_);
180  ++*this;
181  return (tmp);
182  }
183 
184  bool operator==(const Iterator& other) const {
185  return (iter_->equals(*other.iter_));
186  }
187 
188  bool operator!=(const Iterator& other) const {
189  return (!iter_->equals(*other.iter_));
190  }
191 
192  private:
193  IterPtr iter_;
194  };
195 
199  return Iterator(getBeginning());
200  }
201 
205  return Iterator(getEnd());
206  }
207 };
208 
209 typedef boost::shared_ptr<RRsetCollectionBase> RRsetCollectionPtr;
210 
211 } // end of namespace dns
212 } // end of namespace isc
213 
214 #endif // RRSET_COLLECTION_BASE_H
The Name class encapsulates DNS names.
Definition: name.h:223
Iterator end()
Returns an iterator pointing past the end of the collection.
virtual ~RRsetCollectionBase()
Destructor.
Iterator begin()
Returns an iterator pointing to the beginning of the collection.
boost::shared_ptr< Iter > IterPtr
Wraps Iter with a reference count.
bool operator!=(const Iterator &other) const
A helper iterator interface for RRsetCollectionBase.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
isc::dns::AbstractRRset const value_type
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
boost::shared_ptr< RRsetCollectionBase > RRsetCollectionPtr
bool operator==(const Iterator &other) const
Error during RRsetCollectionBase find() operation.
Defines the logger used by the top-level component of kea-lfc.
The AbstractRRset class is an abstract base class that models a DNS RRset.
Definition: rrset.h:154
A forward std::iterator for RRsetCollectionBase.
isc::dns::AbstractRRset const & reference
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
isc::dns::AbstractRRset const * pointer
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition: rrset.h:60
RRsetCollectionError(const char *file, size_t line, const char *what)
Generic class to represent a set of RRsets.