Browse Source

[2432] Remove RRsetCollection::find() that returns an AbstractRRset

Instead, make the one that returns ConstRRsetPtr virtual.
Mukund Sivaraman 12 years ago
parent
commit
dd444334eb

+ 0 - 11
src/lib/dns/rrset_collection.cc

@@ -74,17 +74,6 @@ RRsetCollection::RRsetCollection(std::istream& input_stream, const Name& origin,
     constructHelper<std::istream&>(input_stream, origin, rrclass);
     constructHelper<std::istream&>(input_stream, origin, rrclass);
 }
 }
 
 
-const AbstractRRset*
-RRsetCollection::find(const Name& name, const RRType& rrtype,
-                      const RRClass& rrclass) const {
-    const CollectionKey key(rrclass, rrtype, name);
-    CollectionMap::const_iterator it = rrsets_.find(key);
-    if (it != rrsets_.end()) {
-        return (&(*it->second));
-    }
-    return (NULL);
-}
-
 RRsetPtr
 RRsetPtr
 RRsetCollection::find(const Name& name, const RRClass& rrclass,
 RRsetCollection::find(const Name& name, const RRClass& rrclass,
                       const RRType& rrtype) {
                       const RRType& rrtype) {

+ 9 - 16
src/lib/dns/rrset_collection.h

@@ -97,32 +97,25 @@ public:
     /// \brief Find a matching RRset in the collection.
     /// \brief Find a matching RRset in the collection.
     ///
     ///
     /// Returns the RRset in the collection that exactly matches the
     /// 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.
+    /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
+    /// is found, \c NULL is returned.
     ///
     ///
     /// \param name The name of the RRset to search for.
     /// \param name The name of the RRset to search for.
-    /// \param rrtype The type of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.
-    /// \returns A pointer to the RRset if found, \c NULL otherwise.
-    virtual const isc::dns::AbstractRRset* find
-        (const isc::dns::Name& name, const isc::dns::RRType& rrtype,
-         const isc::dns::RRClass& rrclass)
-        const;
+    /// \param rrtype The type of the RRset to search for.
+    /// \returns The RRset if found, \c NULL otherwise.
+    virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name& name,
+                                         const isc::dns::RRClass& rrclass,
+                                         const isc::dns::RRType& rrtype) const;
 
 
-    /// \brief Find a matching RRset in the collection.
+    /// \brief Find a matching RRset in the collection (non-const
+    /// variant).
     ///
     ///
     /// See above for a description of the method and arguments.
     /// See above for a description of the method and arguments.
     isc::dns::RRsetPtr find(const isc::dns::Name& name,
     isc::dns::RRsetPtr find(const isc::dns::Name& name,
                             const isc::dns::RRClass& rrclass,
                             const isc::dns::RRClass& rrclass,
                             const isc::dns::RRType& rrtype);
                             const isc::dns::RRType& rrtype);
 
 
-    /// \brief Find a matching RRset in the collection (const variant).
-    ///
-    /// See above for a description of the method and arguments.
-    isc::dns::ConstRRsetPtr find(const isc::dns::Name& name,
-                                 const isc::dns::RRClass& rrclass,
-                                 const isc::dns::RRType& rrtype) const;
-
 private:
 private:
     template<typename T>
     template<typename T>
     void constructHelper(T source, const isc::dns::Name& origin,
     void constructHelper(T source, const isc::dns::Name& origin,

+ 6 - 6
src/lib/dns/rrset_collection_base.h

@@ -41,16 +41,16 @@ public:
     /// \brief Find a matching RRset in the collection.
     /// \brief Find a matching RRset in the collection.
     ///
     ///
     /// Returns the RRset in the collection that exactly matches the
     /// 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.
+    /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
+    /// is found, \c NULL is returned.
     ///
     ///
     /// \param name The name of the RRset to search for.
     /// \param name The name of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.
-    /// \returns A pointer to the RRset if found, \c NULL otherwise.
-    virtual const isc::dns::AbstractRRset* find
-        (const isc::dns::Name& name, const isc::dns::RRType& rrtype,
-         const isc::dns::RRClass& rrclass)
+    /// \returns The RRset if found, \c NULL otherwise.
+    virtual isc::dns::ConstRRsetPtr find
+        (const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
+         const isc::dns::RRType& rrtype)
         const = 0;
         const = 0;
 
 
     /// \brief Destructor
     /// \brief Destructor

+ 4 - 34
src/lib/dns/tests/rrset_collection_unittest.cc

@@ -55,34 +55,6 @@ TEST_F(RRsetCollectionTest, istreamConstructor) {
     EXPECT_TRUE(iter2 == collection2.end());
     EXPECT_TRUE(iter2 == collection2.end());
 }
 }
 
 
-TEST_F(RRsetCollectionTest, findBase) {
-    // Test the find() that returns isc::dns::AbstractRRset*
-    const AbstractRRset* rrset = collection.find(Name("www.example.org"),
-                                                 RRType::A(), rrclass);
-    EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
-    EXPECT_EQ(RRType::A(), rrset->getType());
-    EXPECT_EQ(RRTTL(3600), rrset->getTTL());
-    EXPECT_EQ(RRClass("IN"), rrset->getClass());
-    EXPECT_EQ(Name("www.example.org"), rrset->getName());
-
-    // foo.example.org doesn't exist
-    rrset = collection.find(Name("foo.example.org"), RRType::A(), rrclass);
-    EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
-
-    // www.example.org exists, but not with MX
-    rrset = collection.find(Name("www.example.org"), RRType::MX(), rrclass);
-    EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
-
-    // www.example.org exists, with AAAA
-    rrset = collection.find(Name("www.example.org"), RRType::AAAA(), rrclass);
-    EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
-
-    // www.example.org with AAAA does not exist in RRClass::CH()
-    rrset = collection.find(Name("www.example.org"), RRType::AAAA(),
-                            RRClass::CH());
-    EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
-}
-
 template <typename T, typename TP>
 template <typename T, typename TP>
 void doFind(T& collection, const RRClass& rrclass) {
 void doFind(T& collection, const RRClass& rrclass) {
     // Test the find() that returns ConstRRsetPtr
     // Test the find() that returns ConstRRsetPtr
@@ -211,12 +183,10 @@ public:
     MyRRsetCollection()
     MyRRsetCollection()
     {}
     {}
 
 
-    virtual const isc::dns::AbstractRRset* find
-        (const isc::dns::Name&, const isc::dns::RRType&,
-         const isc::dns::RRClass&)
-        const
-    {
-        return (NULL);
+    virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name&,
+                                         const isc::dns::RRClass&,
+                                         const isc::dns::RRType&) const {
+        return (ConstRRsetPtr());
     }
     }
 
 
     typedef std::list<isc::dns::RRset> MyCollection;
     typedef std::list<isc::dns::RRset> MyCollection;