Kea 2.2.0
rrset_collection_base.h
Go to the documentation of this file.
1// Copyright (C) 2012-2015,2017 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 : std::iterator<std::forward_iterator_tag,
157 const isc::dns::AbstractRRset>
158 {
159 public:
160 explicit Iterator(IterPtr iter) :
161 iter_(iter)
162 {}
163
164 reference operator*() {
165 return (iter_->getValue());
166 }
167
169 iter_ = iter_->getNext();
170 return (*this);
171 }
172
174 Iterator tmp(iter_);
175 ++*this;
176 return (tmp);
177 }
178
179 bool operator==(const Iterator& other) const {
180 return (iter_->equals(*other.iter_));
181 }
182
183 bool operator!=(const Iterator& other) const {
184 return (!iter_->equals(*other.iter_));
185 }
186
187 private:
188 IterPtr iter_;
189 };
190
194 return Iterator(getBeginning());
195 }
196
200 return Iterator(getEnd());
201 }
202};
203
204typedef boost::shared_ptr<RRsetCollectionBase> RRsetCollectionPtr;
205
206} // end of namespace dns
207} // end of namespace isc
208
209#endif // RRSET_COLLECTION_BASE_H
210
211// Local Variables:
212// mode: c++
213// End:
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
bool operator!=(const Iterator &other) const
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.