Kea 2.5.5
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
17namespace isc {
18namespace dns {
19
27public:
28 RRsetCollectionError(const char* file, size_t line, const char* what) :
29 Exception(file, line, what)
30 {}
31};
32
45public:
92 (const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
93 const isc::dns::RRType& rrtype)
94 const = 0;
95
98
99protected:
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
151public:
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
209typedef boost::shared_ptr<RRsetCollectionBase> RRsetCollectionPtr;
210
211} // end of namespace dns
212} // end of namespace isc
213
214#endif // RRSET_COLLECTION_BASE_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The AbstractRRset class is an abstract base class that models a DNS RRset.
Definition: rrset.h:154
The Name class encapsulates DNS names.
Definition: name.h:223
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
A helper iterator interface for RRsetCollectionBase.
virtual IterPtr getNext()=0
Returns an IterPtr wrapping an Iter pointing to the next AbstractRRset in sequence in the collection.
virtual const isc::dns::AbstractRRset & getValue()=0
Returns the AbstractRRset currently pointed to by the iterator.
virtual bool equals(Iter &other)=0
Check if another iterator is equal to this one.
A forward std::iterator for RRsetCollectionBase.
bool operator==(const Iterator &other) const
isc::dns::AbstractRRset const * pointer
bool operator!=(const Iterator &other) const
isc::dns::AbstractRRset const value_type
isc::dns::AbstractRRset const & reference
Generic class to represent a set of RRsets.
boost::shared_ptr< Iter > IterPtr
Wraps Iter with a reference count.
virtual ~RRsetCollectionBase()
Destructor.
virtual IterPtr getEnd()=0
Returns an IterPtr wrapping an Iter pointing past the end of the collection.
Iterator end()
Returns an iterator pointing past the end of the collection.
virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name &name, const isc::dns::RRClass &rrclass, const isc::dns::RRType &rrtype) const =0
Find a matching RRset in the collection.
Iterator begin()
Returns an iterator pointing to the beginning of the collection.
virtual IterPtr getBeginning()=0
Returns an IterPtr wrapping an Iter pointing to the beginning of the collection.
Error during RRsetCollectionBase find() operation.
RRsetCollectionError(const char *file, size_t line, const char *what)
boost::shared_ptr< RRsetCollectionBase > RRsetCollectionPtr
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition: rrset.h:60
Defines the logger used by the top-level component of kea-lfc.