Commit 72095c67 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

applied some proposed patch:

- clarify the use of constness
- don't expose vector iterators directly


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1019 e5f2f494-b856-4b98-b285-d166d9295462
parent a4182403
......@@ -28,31 +28,31 @@ namespace isc {
namespace dns {
void
RRsetList::addRRset(const RRsetPtr rrsetptr)
RRsetList::addRRset(RRsetPtr rrsetptr)
{
const RRsetPtr rrset_found = findRRset(rrsetptr->getType(),
rrsetptr->getClass());
if (rrset_found) {
ConstRRsetPtr rrset_found = findRRset(rrsetptr->getType(),
rrsetptr->getClass());
if (rrset_found != NULL) {
dns_throw(DuplicateRRset, "");
}
rrsets_.push_back(rrsetptr);
}
const RRsetPtr
RRsetList::findRRset(const RRsetPtr rrsetptr)
RRsetPtr
RRsetList::findRRset(ConstRRsetPtr rrsetptr)
{
BOOST_FOREACH(const RRsetPtr t, rrsets_) {
BOOST_FOREACH(RRsetPtr t, rrsets_) {
if (rrsetptr == t) {
return rrsetptr;
return t;
}
}
return RRsetPtr();
}
const RRsetPtr
RRsetPtr
RRsetList::findRRset(const RRType& rrtype, const RRClass& rrclass)
{
BOOST_FOREACH(const RRsetPtr rrsetptr, rrsets_) {
BOOST_FOREACH(RRsetPtr rrsetptr, rrsets_) {
if ((rrsetptr->getClass() == rrclass) &&
(rrsetptr->getType() == rrtype)) {
return rrsetptr;
......
......@@ -18,6 +18,7 @@
#define __RRSETLIST_H 1
#include <iostream>
#include <iterator>
#include <vector>
#include <boost/shared_ptr.hpp>
......@@ -35,22 +36,59 @@ public:
isc::Exception(file, line, what) {}
};
template <typename T>
class RRsetListIterator :
public std::iterator<std::input_iterator_tag, RRsetPtr> {
public:
RRsetListIterator() {}
explicit RRsetListIterator(const T& it) :
it_(it) {}
RRsetListIterator& operator++()
{
++it_;
return (*this);
}
RRsetListIterator operator++(int)
{
RRsetListIterator tmp(*this);
++it_;
return (tmp);
}
RRsetPtr& operator*() const
{
return (it_.operator*());
}
RRsetPtr* operator->() const
{
return (it_.operator->());
}
bool operator==(const RRsetListIterator& other)
{
return (it_ == other.it_);
}
private:
T it_;
};
class RRsetList {
public:
void addRRset(const RRsetPtr new_rrsetptr);
const RRsetPtr findRRset(const RRType& rrtype,
const RRClass& rrclass = RRClass::IN());
const RRsetPtr findRRset(const RRsetPtr);
void addRRset(RRsetPtr new_rrsetptr);
RRsetPtr findRRset(const RRType& rrtype,
const RRClass& rrclass = RRClass::IN());
RRsetPtr findRRset(ConstRRsetPtr rrsetptr);
RRsetPtr operator[](RRType t) { return (this->findRRset(t)); }
const RRsetPtr operator[](RRType t) { return (this->findRRset(t)); }
typedef RRsetListIterator<std::vector<RRsetPtr>::iterator> iterator;
typedef RRsetListIterator<std::vector<RRsetPtr>::const_iterator>
const_iterator;
typedef std::vector<RRsetPtr>::const_iterator const_iterator;
const_iterator begin() const { return (rrsets_.begin()); }
const_iterator end() const { return (rrsets_.end)(); }
const_iterator begin() const { return (const_iterator(rrsets_.begin())); }
const_iterator end() const { return (const_iterator(rrsets_.end())); }
typedef std::vector<RRsetPtr>::iterator iterator;
iterator begin() { return (rrsets_.begin()); }
iterator end() { return (rrsets_.end)(); }
iterator begin() { return (iterator(rrsets_.begin())); }
iterator end() { return (iterator(rrsets_.end())); }
size_t size() const { return (rrsets_.size()); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment