Skip to content
GitLab
Menu
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
da1cc865
Verified
Commit
da1cc865
authored
May 06, 2022
by
Andrei Pavel
🐧
Browse files
[
#562
] add an ordered_unique index to ClientClassContainer
parent
9187be72
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcp/classify.h
View file @
da1cc865
...
...
@@ -7,10 +7,12 @@
#ifndef CLASSIFY_H
#define CLASSIFY_H
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index_container.hpp>
#include <string>
/// @file classify.h
...
...
@@ -55,6 +57,10 @@ namespace dhcp {
boost
::
multi_index
::
hashed_unique
<
boost
::
multi_index
::
tag
<
ClassNameTag
>
,
boost
::
multi_index
::
identity
<
ClientClass
>
>
,
// Third index orders lexicographically.
boost
::
multi_index
::
ordered_unique
<
boost
::
multi_index
::
identity
<
ClientClass
>
>
>
>
ClientClassContainer
;
...
...
@@ -131,6 +137,14 @@ namespace dhcp {
}
/// @}
/// @brief Returns an index that allows iteration through a sorted set
/// of all the client classes.
///
/// @return the index iterable through range-based for looping
ClientClassContainer
::
nth_index
<
2
>::
type
const
&
sorted
()
const
{
return
container_
.
get
<
2
>
();
}
/// @brief returns if class x belongs to the defined classes
///
/// @param x client class to be checked
...
...
src/lib/dhcp/tests/pkt4_unittest.cc
View file @
da1cc865
// Copyright (C) 2011-202
1
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011-202
2
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
...
...
@@ -1386,4 +1386,28 @@ TEST_F(Pkt4Test, testSkipThisOptionError) {
EXPECT_EQ
(
"def"
,
opstr
->
getValue
());
}
// Check that sorted() allows sorted iteration.
TEST_F
(
Pkt4Test
,
sortedClientClasses
)
{
// Add a bunch of classes to a packet.
Pkt4
packet
(
DHCPDISCOVER
,
1234
);
packet
.
addClass
(
"foo"
);
packet
.
addClass
(
"bar"
);
packet
.
addClass
(
"2"
);
packet
.
addClass
(
"10"
);
// Check that the usual iteration yields items in order of insertion.
std
::
string
client_classes
;
for
(
ClientClass
const
&
c
:
packet
.
getClasses
())
{
client_classes
+=
c
+
','
;
}
EXPECT_EQ
(
client_classes
,
"ALL,foo,bar,2,10,"
);
// Check sorted() yields sorted items.
std
::
string
sorted_client_classes
;
for
(
ClientClass
const
&
c
:
packet
.
getClasses
().
sorted
())
{
sorted_client_classes
+=
c
+
','
;
}
EXPECT_EQ
(
sorted_client_classes
,
"10,2,ALL,bar,foo,"
);
}
}
// end of anonymous namespace
src/lib/dhcp/tests/pkt6_unittest.cc
View file @
da1cc865
...
...
@@ -2115,4 +2115,28 @@ TEST_F(Pkt6Test, relayDataOption) {
EXPECT_EQ
(
orig_data
,
clone_data
);
}
// Check that sorted() allows sorted iteration.
TEST_F
(
Pkt6Test
,
sortedClientClasses
)
{
// Add a bunch of classes to a packet.
Pkt6
packet
(
DHCPV6_SOLICIT
,
1234
);
packet
.
addClass
(
"foo"
);
packet
.
addClass
(
"bar"
);
packet
.
addClass
(
"2"
);
packet
.
addClass
(
"10"
);
// Check that the usual iteration yields items in order of insertion.
std
::
string
client_classes
;
for
(
ClientClass
const
&
c
:
packet
.
getClasses
())
{
client_classes
+=
c
+
','
;
}
EXPECT_EQ
(
client_classes
,
"ALL,foo,bar,2,10,"
);
// Check sorted() yields sorted items.
std
::
string
sorted_client_classes
;
for
(
ClientClass
const
&
c
:
packet
.
getClasses
().
sorted
())
{
sorted_client_classes
+=
c
+
','
;
}
EXPECT_EQ
(
sorted_client_classes
,
"10,2,ALL,bar,foo,"
);
}
}
// namespace
Andrei Pavel
🐧
@andrei
mentioned in merge request
!1647 (merged)
·
May 20, 2022
mentioned in merge request
!1647 (merged)
mentioned in merge request !1647
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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