Commit 76c63610 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[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.
parent 1414b51d
......@@ -323,6 +323,45 @@ 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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment