rrsetlist.h 3.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

// $Id$

#ifndef __RRSETLIST_H
#define __RRSETLIST_H 1

#include <iostream>
JINMEI Tatuya's avatar
JINMEI Tatuya committed
21
#include <iterator>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <vector>

#include <boost/shared_ptr.hpp>

#include "rrset.h"
#include "rrclass.h"
#include "rrtype.h"

namespace isc {
namespace dns {

class DuplicateRRset : public Exception {
public:
    DuplicateRRset(const char* file, size_t line, const char* what) :
        isc::Exception(file, line, what) {}
};

39
template <typename T, typename P, typename R>
JINMEI Tatuya's avatar
JINMEI Tatuya committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
    }
57
    R operator*() const
JINMEI Tatuya's avatar
JINMEI Tatuya committed
58
    {
59
        return (*it_);
JINMEI Tatuya's avatar
JINMEI Tatuya committed
60
    }
61
    P operator->() const
JINMEI Tatuya's avatar
JINMEI Tatuya committed
62
63
64
65
66
67
68
    {
        return (it_.operator->());
    }
    bool operator==(const RRsetListIterator& other)
    {
        return (it_ == other.it_);
    }
69
70
71
72
    bool operator!=(const RRsetListIterator& other)
    {
        return (it_ != other.it_);
    }
JINMEI Tatuya's avatar
JINMEI Tatuya committed
73
74
75
76
77
    
private:
    T it_;
};

78
79
class RRsetList {
public:
JINMEI Tatuya's avatar
JINMEI Tatuya committed
80
81
82
83
84
    void addRRset(RRsetPtr new_rrsetptr);
    RRsetPtr findRRset(const RRType& rrtype,
                            const RRClass& rrclass = RRClass::IN());
    RRsetPtr findRRset(ConstRRsetPtr rrsetptr);

85
    RRsetPtr operator[](const RRType& t) { return (this->findRRset(t)); }
86

87
88
89
90
91
92
    typedef RRsetListIterator<std::vector<RRsetPtr>::iterator,
                              RRsetPtr*,
                              RRsetPtr&> iterator;
    typedef RRsetListIterator<std::vector<RRsetPtr>::const_iterator,
                              const RRsetPtr*,
                              const RRsetPtr&> const_iterator;
93

JINMEI Tatuya's avatar
JINMEI Tatuya committed
94
95
    const_iterator begin() const { return (const_iterator(rrsets_.begin())); }
    const_iterator end() const { return (const_iterator(rrsets_.end())); }
96

JINMEI Tatuya's avatar
JINMEI Tatuya committed
97
98
    iterator begin() { return (iterator(rrsets_.begin())); }
    iterator end() { return (iterator(rrsets_.end())); }
99
100
101
102
103
104
105
106
107
108
109
110
111
112

    size_t size() const { return (rrsets_.size()); }

private:
    std::vector<RRsetPtr> rrsets_;
};

} // end of namespace dns
} // end of namespace isc
#endif  // __RRSETLIST_H

// Local Variables: 
// mode: c++
// End: