diff --git a/src/lib/dhcp/classify.cc b/src/lib/dhcp/classify.cc index e234598e94..65cd8308ce 100644 --- a/src/lib/dhcp/classify.cc +++ b/src/lib/dhcp/classify.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2020 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 @@ -30,6 +30,12 @@ ClientClasses::ClientClasses(const std::string& class_names) } } +void +ClientClasses::erase(const ClientClass& class_name) { + list_.remove(class_name); + static_cast(set_.erase(class_name)); +} + std::string ClientClasses::toText(const std::string& separator) const { std::stringstream s; diff --git a/src/lib/dhcp/classify.h b/src/lib/dhcp/classify.h index 14614313fc..727e0cc402 100644 --- a/src/lib/dhcp/classify.h +++ b/src/lib/dhcp/classify.h @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2020 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 @@ -64,6 +64,11 @@ namespace dhcp { set_.insert(class_name); } + /// @brief Erase element by name. + /// + /// @param class_name The name of the class to erase. + void erase(const ClientClass& class_name); + /// @brief Check if classes is empty. bool empty() const { return (list_.empty()); diff --git a/src/lib/dhcp/tests/classify_unittest.cc b/src/lib/dhcp/tests/classify_unittest.cc index 14e9d58443..938379cc88 100644 --- a/src/lib/dhcp/tests/classify_unittest.cc +++ b/src/lib/dhcp/tests/classify_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2020 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 @@ -131,3 +131,21 @@ TEST(ClassifyTest, ClientClassesToText) { // Check non-standard separator. EXPECT_EQ("alpha.gamma.beta", classes.toText(".")); } + +// Check that selected class can be erased. +TEST(ClassifyTest, Erase) { + ClientClasses classes; + + classes.insert("alpha"); + classes.insert("beta"); + EXPECT_TRUE(classes.contains("alpha")); + EXPECT_TRUE(classes.contains("beta")); + + classes.erase("beta"); + EXPECT_TRUE(classes.contains("alpha")); + EXPECT_FALSE(classes.contains("beta")); + + classes.erase("alpha"); + EXPECT_FALSE(classes.contains("alpha")); + EXPECT_FALSE(classes.contains("beta")); +}