Kea  1.5.0
classify.cc
Go to the documentation of this file.
1 // Copyright (C) 2014-2017 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 std::string
34 ClientClasses::toText(const std::string& separator) const {
35  std::stringstream s;
36  for (const_iterator class_it = cbegin(); class_it != cend(); ++class_it) {
37  if (class_it != cbegin()) {
38  s << separator;
39  }
40  s << *class_it;
41  }
42  return (s.str());
43 }
44 
45 } // end of namespace isc::dhcp
46 } // end of namespace isc
classify.h
Defines elements for storing the names of client classes.
isc::util::str::trim
string trim(const string &instring)
Trim Leading and Trailing Spaces.
Definition: strutil.cc:53
isc::dhcp::ClientClasses::toText
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition: classify.cc:34
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
strutil.h
isc::dhcp::ClientClasses::cbegin
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:81
isc::dhcp::ClientClasses::const_iterator
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Definition: classify.h:47
isc::dhcp::ClientClass
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
isc::dhcp::ClientClasses::insert
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:62
isc::dhcp::ClientClasses::ClientClasses
ClientClasses()
Default constructor.
Definition: classify.h:50
isc::dhcp::ClientClasses::cend
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:86