rrset_collection_base.h 5.45 KB
 Mukund Sivaraman committed Dec 21, 2012 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ``````// Copyright (C) 2012 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. #ifndef RRSET_COLLECTION_BASE_H #define RRSET_COLLECTION_BASE_H 1 #include #include #include #include namespace isc { namespace dns { /// \brief Generic class to represent a set of RRsets. /// /// This is a generic container and the stored set of RRsets does not /// necessarily form a valid zone (e.g. there doesn't necessarily have /// to be an SOA at the "origin"). Instead, it will be used to represent /// a single zone for the purpose of zone loading/checking. It provides /// a simple find() method to find an RRset for the given name and type /// (and maybe class) and a way to iterate over all RRsets. /// /// See \c RRsetCollection for a simple libdns++ implementation using an /// STL container. libdatasrc will have another implementation. class RRsetCollectionBase { public: /// \brief Find a matching RRset in the collection. /// /// Returns the RRset in the collection that exactly matches the /// given \c name and \c rrtype. If no matching RRset is found, /// \c NULL is returned. /// /// \param name The name of the RRset to search for. /// \param rrtype The type of the RRset to search for. `````` 49 `````` /// \param rrclass The class of the RRset to search for. `````` Mukund Sivaraman committed Dec 21, 2012 50 `````` /// \returns A pointer to the RRset if found, \c NULL otherwise. `````` 51 52 `````` virtual const isc::dns::AbstractRRset* find (const isc::dns::Name& name, const isc::dns::RRType& rrtype, `````` Mukund Sivaraman committed Jan 01, 2013 53 `````` const isc::dns::RRClass& rrclass) `````` Mukund Sivaraman committed Dec 21, 2012 54 55 `````` const = 0; `````` Mukund Sivaraman committed Jan 01, 2013 56 57 58 `````` /// \brief Destructor virtual ~RRsetCollectionBase() {} `````` Mukund Sivaraman committed Dec 21, 2012 59 60 ``````protected: class Iter; // forward declaration `````` Mukund Sivaraman committed Jan 01, 2013 61 62 `````` /// \brief Wraps Iter with a reference count. `````` Mukund Sivaraman committed Dec 21, 2012 63 64 `````` typedef boost::shared_ptr IterPtr; `````` Mukund Sivaraman committed Jan 01, 2013 65 66 67 68 69 70 71 72 `````` /// \brief A helper iterator interface for \c RRsetCollectionBase. /// /// This is a protected iterator class that is a helper interface /// used by the public iterator. Derived classes of /// \c RRsetCollectionBase are supposed to implement this class and /// the \c getBeginning() and \c getEnd() methods, so that the /// public interator interface can be provided. This is a forward /// iterator only. `````` Mukund Sivaraman committed Dec 21, 2012 73 74 `````` class Iter { public: `````` Mukund Sivaraman committed Jan 01, 2013 75 76 `````` /// \brief Returns the \c AbstractRRset currently pointed to by /// the iterator. `````` Mukund Sivaraman committed Dec 21, 2012 77 `````` virtual const isc::dns::AbstractRRset& getValue() = 0; `````` Mukund Sivaraman committed Jan 01, 2013 78 79 80 `````` /// \brief Returns an \c IterPtr wrapping an Iter pointing to /// the next \c AbstractRRset in sequence in the collection. `````` Mukund Sivaraman committed Dec 21, 2012 81 `````` virtual IterPtr getNext() = 0; `````` Mukund Sivaraman committed Jan 01, 2013 82 83 84 85 86 87 88 89 90 91 `````` /// \brief Check if another iterator is equal to this one. /// /// Returns \c true if this iterator is equal to \c other, /// \c false otherwise. Note that if \c other is not the same /// type as \c this, or cannot be compared meaningfully, the /// method must return \c false. /// /// \param other The other iterator to compare against. /// \returns \c true if equal, \c false otherwise. `````` Mukund Sivaraman committed Dec 21, 2012 92 93 94 `````` virtual bool equals(Iter& other) = 0; }; `````` Mukund Sivaraman committed Jan 01, 2013 95 96 `````` /// \brief Returns an \c IterPtr wrapping an Iter pointing to the /// beginning of the collection. `````` Mukund Sivaraman committed Dec 21, 2012 97 `````` virtual IterPtr getBeginning() = 0; `````` Mukund Sivaraman committed Jan 01, 2013 98 99 100 `````` /// \brief Returns an \c IterPtr wrapping an Iter pointing past the /// end of the collection. `````` Mukund Sivaraman committed Dec 21, 2012 101 102 103 `````` virtual IterPtr getEnd() = 0; public: `````` Mukund Sivaraman committed Jan 01, 2013 104 105 106 107 `````` /// \brief A forward \c std::iterator for \c RRsetCollectionBase. /// /// It behaves like a \c std::iterator forward iterator, so please /// see its documentation for usage. `````` Mukund Sivaraman committed Jan 03, 2013 108 `````` class Iterator : std::iterator { public: `````` Mukund Sivaraman committed Jan 03, 2013 112 `````` explicit Iterator(IterPtr iter) : `````` Mukund Sivaraman committed Dec 21, 2012 113 114 115 116 117 118 119 `````` iter_(iter) {} reference operator*() { return (iter_->getValue()); } `````` Mukund Sivaraman committed Jan 03, 2013 120 `````` Iterator& operator++() { `````` Mukund Sivaraman committed Dec 21, 2012 121 122 123 124 `````` iter_ = iter_->getNext(); return (*this); } `````` Mukund Sivaraman committed Jan 03, 2013 125 126 `````` Iterator operator++(int) { Iterator tmp(iter_); `````` Mukund Sivaraman committed Dec 21, 2012 127 128 129 130 `````` ++*this; return (tmp); } `````` Mukund Sivaraman committed Jan 03, 2013 131 `````` bool operator==(const Iterator& other) const { `````` Mukund Sivaraman committed Dec 21, 2012 132 133 134 `````` return (iter_->equals(*other.iter_)); } `````` Mukund Sivaraman committed Jan 03, 2013 135 `````` bool operator!=(const Iterator& other) const { `````` Mukund Sivaraman committed Dec 21, 2012 136 137 138 139 140 141 142 `````` return (!iter_->equals(*other.iter_)); } private: IterPtr iter_; }; `````` Mukund Sivaraman committed Jan 01, 2013 143 144 `````` /// \brief Returns an iterator pointing to the beginning of the /// collection. `````` Mukund Sivaraman committed Jan 03, 2013 145 146 `````` Iterator begin() { return Iterator(getBeginning()); `````` Mukund Sivaraman committed Dec 21, 2012 147 148 `````` } `````` Mukund Sivaraman committed Jan 01, 2013 149 150 `````` /// \brief Returns an iterator pointing past the end of the /// collection. `````` Mukund Sivaraman committed Jan 03, 2013 151 152 `````` Iterator end() { return Iterator(getEnd()); `````` Mukund Sivaraman committed Dec 21, 2012 153 154 155 156 157 158 159 160 161 162 163 `````` } }; } // end of namespace dns } // end of namespace isc #endif // RRSET_COLLECTION_BASE_H // Local Variables: // mode: c++ // End:``````