Parcourir la source

[2107] define "find rdataset" method as a static method of the class.

with notes about the intent.
JINMEI Tatuya il y a 12 ans
Parent
commit
7985ae6830

+ 52 - 39
src/lib/datasrc/memory/rdataset.h

@@ -194,6 +194,43 @@ public:
     static void destroy(util::MemorySegment& mem_sgmt, dns::RRClass rrclass,
                         RdataSet* rdataset);
 
+    /// \brief Find \c RdataSet of given RR type from a list (const version).
+    ///
+    /// This function is a convenient shortcut for commonly used operation of
+    /// finding a given type of \c RdataSet from a linked list of them.
+    ///
+    /// It follows the linked list of \c RdataSet objects (via their \c next
+    /// member) starting the given head, until it finds an object of the
+    /// given RR type.  If found, it returns a (bare) pointer to the object;
+    /// if not found in the entire list, it returns NULL.  The head pointer
+    /// can be NULL, in which case this function will simply return NULL.
+    ///
+    /// \note This function is defined as a (static) class method to
+    /// clarify its an operation for \c RdataSet objects and to make the
+    /// name shorter.  But its implementation does not depend on private
+    /// members of the class, and it should be kept if and when this method
+    /// needs to be extended, unless there's a reason other than simply
+    /// because it's already a member function.
+    ///
+    /// \param rdata_head A pointer to \c RdataSet from which the search
+    /// starts.  It can be NULL.
+    /// \param type The RRType of \c RdataSet to find.
+    /// \return A pointer to the found \c RdataSet or NULL if none found.
+    static const RdataSet*
+    find(const RdataSet* rdataset_head, const dns::RRType& type) {
+        return (find<const RdataSet>(rdataset_head, type));
+    }
+
+    /// \brief Find \c RdataSet of given RR type from a list (non const
+    /// version).
+    ///
+    /// This is similar to the const version, except it takes and returns non
+    /// const pointers.
+    static RdataSet*
+    find(RdataSet* rdataset_head, const dns::RRType& type) {
+        return (find<RdataSet>(rdataset_head, type));
+    }
+
     typedef boost::interprocess::offset_ptr<RdataSet> RdataSetPtr;
     typedef boost::interprocess::offset_ptr<const RdataSet> ConstRdataSetPtr;
 
@@ -307,6 +344,21 @@ private:
         return (reinterpret_cast<uint16_t*>(this + 1));
     }
 
+    // Shared by both mutable and immutable versions of find()
+    template <typename RdataSetType>
+    static RdataSetType*
+    find(RdataSetType* rdataset_head, const dns::RRType& type) {
+        for (RdataSetType* rdataset = rdataset_head;
+             rdataset != NULL;
+             rdataset = rdataset->getNext()) // use getNext() for efficiency
+        {
+            if (rdataset->type == type) {
+                return (rdataset);
+            }
+        }
+        return (NULL);
+    }
+
     /// \brief The constructor.
     ///
     /// An object of this class is always expected to be created by the
@@ -326,45 +378,6 @@ private:
     ~RdataSet() {}
 };
 
-// Shared by both mutable and immutable versions below
-template <typename RdataSetType>
-RdataSetType*
-findRdataSetOfType(RdataSetType* rdataset_head, dns::RRType type) {
-    for (RdataSetType* rdataset = rdataset_head;
-         rdataset != NULL;
-         rdataset = rdataset->getNext()) // use getNext() for efficiency
-    {
-        if (rdataset->type == type) {
-            return (rdataset);
-        }
-    }
-    return (NULL);
-}
-
-/// \brief Find \c RdataSet of given RR type from a list (const version).
-///
-/// This function is a convenient shortcut for commonly used operation of
-/// finding a given type of \c RdataSet from a linked list of them.
-///
-/// It follows the linked list of \c RdataSet objects (via their \c next
-/// member) starting the given head, until it finds an object of the
-/// given RR type.  If found, it returns a (bare) pointer to the object;
-/// if not found in the entire list, it returns NULL.  The head pointer
-/// can be NULL, in which case this function will simply return NULL.
-inline const RdataSet*
-findRdataSetOfType(const RdataSet* rdataset_head, dns::RRType type) {
-    return (findRdataSetOfType<const RdataSet>(rdataset_head, type));
-}
-
-/// \brief Find \c RdataSet of given RR type from a list (non const version).
-///
-/// This is similar to the const version, except it takes and returns non
-/// const pointers.
-inline RdataSet*
-findRdataSetOfType(RdataSet* rdataset_head, dns::RRType type) {
-    return (findRdataSetOfType<RdataSet>(rdataset_head, type));
-}
-
 } // namespace memory
 } // namespace datasrc
 } // namespace isc

+ 1 - 1
src/lib/datasrc/memory/tests/zone_data_unittest.cc

@@ -111,7 +111,7 @@ checkFindRdataSet(const ZoneTree& tree, const Name& name, RRType type,
     ZoneNode* node = NULL;
     tree.find(name, &node);
     ASSERT_NE(static_cast<ZoneNode*>(NULL), node);
-    EXPECT_EQ(expected_set, findRdataSetOfType(node->getData(), type));
+    EXPECT_EQ(expected_set, RdataSet::find(node->getData(), type));
 }
 
 TEST_F(ZoneDataTest, createNSEC3Data) {