Kea  1.9.9-git
classify.cc
Go to the documentation of this file.
1 // Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 #include <dhcp/classify.h>
9 #include <util/strutil.h>
10 #include <boost/algorithm/string/classification.hpp>
11 #include <boost/algorithm/string/constants.hpp>
12 #include <boost/algorithm/string/split.hpp>
13 #include <sstream>
14 #include <vector>
15 
16 namespace isc {
17 namespace dhcp {
18 
19 ClientClasses::ClientClasses(const std::string& class_names)
20  : list_(), set_() {
21  std::vector<std::string> split_text;
22  boost::split(split_text, class_names, boost::is_any_of(","),
23  boost::algorithm::token_compress_off);
24  for (size_t i = 0; i < split_text.size(); ++i) {
25  std::string trimmed = util::str::trim(split_text[i]);
26  // Ignore empty class names.
27  if (!trimmed.empty()) {
28  insert(ClientClass(trimmed));
29  }
30  }
31 }
32 
33 void
34 ClientClasses::erase(const ClientClass& class_name) {
35  list_.remove(class_name);
36  static_cast<void>(set_.erase(class_name));
37 }
38 
39 std::string
40 ClientClasses::toText(const std::string& separator) const {
41  std::stringstream s;
42  for (const_iterator class_it = cbegin(); class_it != cend(); ++class_it) {
43  if (class_it != cbegin()) {
44  s << separator;
45  }
46  s << *class_it;
47  }
48  return (s.str());
49 }
50 
51 } // end of namespace isc::dhcp
52 } // end of namespace isc
Defines elements for storing the names of client classes.
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Definition: classify.h:47
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:91
Defines the logger used by the top-level component of kea-dhcp-ddns.
ClientClasses()
Default constructor.
Definition: classify.h:50
void erase(const ClientClass &class_name)
Erase element by name.
Definition: classify.cc:34
string trim(const string &instring)
Trim Leading and Trailing Spaces.
Definition: strutil.cc:53
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:62
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:86
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition: classify.cc:40