From: JINMEI Tatuya Date: Wed, 22 Aug 2012 21:33:40 +0000 (-0700) Subject: [2107] added a utility findRdataSetOfType function. X-Git-Tag: trac2351_base~109^2~1^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=76c6361071fcb50a3ef06b7072f840ca8bbdbe26;p=thirdparty%2Fkea.git [2107] added a utility findRdataSetOfType function. it will primarily be used for tests in this ticket, but I expect we'll need them in the main code in later tasks. --- diff --git a/src/lib/datasrc/memory/rdataset.h b/src/lib/datasrc/memory/rdataset.h index 6c893a75c2..e7c15f6c73 100644 --- a/src/lib/datasrc/memory/rdataset.h +++ b/src/lib/datasrc/memory/rdataset.h @@ -323,6 +323,45 @@ private: ~RdataSet() {} }; +// Shared by both mutable and immutable versions below +template +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(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_head, type)); +} + } // namespace memory } // namespace datasrc } // namespace isc