Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
7985ae68
Commit
7985ae68
authored
Aug 28, 2012
by
JINMEI Tatuya
Browse files
[2107] define "find rdataset" method as a static method of the class.
with notes about the intent.
parent
44f92aeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/datasrc/memory/rdataset.h
View file @
7985ae68
...
...
@@ -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
...
...
src/lib/datasrc/memory/tests/zone_data_unittest.cc
View file @
7985ae68
...
...
@@ -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
,
find
RdataSet
OfType
(
node
->
getData
(),
type
));
EXPECT_EQ
(
expected_set
,
RdataSet
::
find
(
node
->
getData
(),
type
));
}
TEST_F
(
ZoneDataTest
,
createNSEC3Data
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment