Kea: rrset_collection.h Source File

| Kea 2.2.0

rrset_collection.h
Go to the documentation of this file.
1// Copyright (C) 2012-2015 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_H
8#define RRSET_COLLECTION_H 1
9
10#include <dns/rrset_collection_base.h>
11#include <dns/rrclass.h>
12
13#include <boost/tuple/tuple.hpp>
14#include <boost/tuple/tuple_comparison.hpp>
15
16#include <map>
17
18namespace isc {
19namespace dns {
20
23 class RRsetCollection : public RRsetCollectionBase {
24public:
30 RRsetCollection() {}
31
44 RRsetCollection(const char* filename, const isc::dns::Name& origin,
45 const isc::dns::RRClass& rrclass);
46
57 RRsetCollection(std::istream& input_stream, const isc::dns::Name& origin,
58 const isc::dns::RRClass& rrclass);
59
61 virtual ~RRsetCollection() {}
62
76 void addRRset(isc::dns::RRsetPtr rrset);
77
85 bool removeRRset(const isc::dns::Name& name,
86 const isc::dns::RRClass& rrclass,
87 const isc::dns::RRType& rrtype);
88
99 virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name& name,
100 const isc::dns::RRClass& rrclass,
101 const isc::dns::RRType& rrtype) const;
102
107 isc::dns::RRsetPtr find(const isc::dns::Name& name,
108 const isc::dns::RRClass& rrclass,
109 const isc::dns::RRType& rrtype);
110
111private:
112 template<typename T>
113 void constructHelper(T source, const isc::dns::Name& origin,
114 const isc::dns::RRClass& rrclass);
115 void loaderCallback(const std::string&, size_t, const std::string&);
116
117 typedef boost::tuple<isc::dns::RRClass, isc::dns::RRType, isc::dns::Name>
118 CollectionKey;
119 typedef std::map<CollectionKey, isc::dns::RRsetPtr> CollectionMap;
120
121 CollectionMap rrsets_;
122
123protected:
124 class DnsIter : public RRsetCollectionBase::Iter {
125 public:
126 DnsIter(CollectionMap::iterator& iter) :
127 iter_(iter)
128 {}
129
130 virtual const isc::dns::AbstractRRset& getValue() {
131 isc::dns::RRsetPtr& rrset = iter_->second;
132 return (*rrset);
133 }
134
135 virtual IterPtr getNext() {
136 CollectionMap::iterator it = iter_;
137 ++it;
138 return (RRsetCollectionBase::IterPtr(new DnsIter(it)));
139 }
140
141 virtual bool equals(Iter& other) {
142 const DnsIter* other_real = dynamic_cast<DnsIter*>(&other);
143 if (other_real == NULL) {
144 return (false);
145 }
146 return (iter_ == other_real->iter_);
147 }
148
149 private:
150 CollectionMap::iterator iter_;
151 };
152
153 virtual RRsetCollectionBase::IterPtr getBeginning();
154 virtual RRsetCollectionBase::IterPtr getEnd();
155};
156
157} // end of namespace dns
158} // end of namespace isc
159
160#endif // RRSET_COLLECTION_H
161
162// Local Variables:
163// mode: c++
164// End:
isc::dns::AbstractRRset
The AbstractRRset class is an abstract base class that models a DNS RRset.
Definition: rrset.h:154
isc::dns::Name
The Name class encapsulates DNS names.
Definition: name.h:223
isc::dns::RRClass
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
isc::dns::RRType
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
isc::dns::RRsetCollectionBase::Iter
A helper iterator interface for RRsetCollectionBase.
Definition: rrset_collection_base.h:113
isc::dns::RRsetCollectionBase
Generic class to represent a set of RRsets.
Definition: rrset_collection_base.h:44
isc::dns::RRsetCollectionBase::IterPtr
boost::shared_ptr< Iter > IterPtr
Wraps Iter with a reference count.
Definition: rrset_collection_base.h:100
isc::dns::RRsetCollection::DnsIter
Definition: rrset_collection.h:124
isc::dns::RRsetCollection::DnsIter::getNext
virtual IterPtr getNext()
Returns an IterPtr wrapping an Iter pointing to the next AbstractRRset in sequence in the collection.
Definition: rrset_collection.h:135
isc::dns::RRsetCollection::DnsIter::DnsIter
DnsIter(CollectionMap::iterator &iter)
Definition: rrset_collection.h:126
isc::dns::RRsetCollection::DnsIter::getValue
virtual const isc::dns::AbstractRRset & getValue()
Returns the AbstractRRset currently pointed to by the iterator.
Definition: rrset_collection.h:130
isc::dns::RRsetCollection::DnsIter::equals
virtual bool equals(Iter &other)
Check if another iterator is equal to this one.
Definition: rrset_collection.h:141
isc::dns::RRsetCollection
libdns++ implementation of RRsetCollectionBase using an STL container.
Definition: rrset_collection.h:23
isc::dns::RRsetCollection::RRsetCollection
RRsetCollection()
Constructor.
Definition: rrset_collection.h:30
isc::dns::RRsetCollection::getBeginning
virtual RRsetCollectionBase::IterPtr getBeginning()
Returns an IterPtr wrapping an Iter pointing to the beginning of the collection.
Definition: rrset_collection.cc:111
isc::dns::RRsetCollection::getEnd
virtual RRsetCollectionBase::IterPtr getEnd()
Returns an IterPtr wrapping an Iter pointing past the end of the collection.
Definition: rrset_collection.cc:117
isc::dns::RRsetCollection::find
virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name &name, const isc::dns::RRClass &rrclass, const isc::dns::RRType &rrtype) const
Find a matching RRset in the collection.
Definition: rrset_collection.cc:84
isc::dns::RRsetCollection::addRRset
void addRRset(isc::dns::RRsetPtr rrset)
Add an RRset to the collection.
Definition: rrset_collection.cc:31
isc::dns::RRsetCollection::removeRRset
bool removeRRset(const isc::dns::Name &name, const isc::dns::RRClass &rrclass, const isc::dns::RRType &rrtype)
Remove an RRset from the collection.
Definition: rrset_collection.cc:96
isc::dns::RRsetCollection::~RRsetCollection
virtual ~RRsetCollection()
Destructor.
Definition: rrset_collection.h:61
isc::dns::RRsetPtr
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
isc::dns::ConstRRsetPtr
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition: rrset.h:60
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
rrclass.h
rrset_collection_base.h