Kea  1.9.9-git
classify.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2021 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 #ifndef CLASSIFY_H
8 #define CLASSIFY_H
9 
10 #include <string>
11 #include <iterator>
12 #include <list>
13 #include <unordered_set>
14 
31 
32 namespace isc {
33 
34 namespace dhcp {
35 
37  typedef std::string ClientClass;
38 
43  class ClientClasses {
44  public:
45 
47  typedef std::list<ClientClass>::const_iterator const_iterator;
48 
50  ClientClasses() : list_(), set_() {
51  }
52 
57  ClientClasses(const ClientClass& class_names);
58 
62  void insert(const ClientClass& class_name) {
63  list_.push_back(class_name);
64  set_.insert(class_name);
65  }
66 
70  void erase(const ClientClass& class_name);
71 
73  bool empty() const {
74  return (list_.empty());
75  }
76 
81  size_t size() const {
82  return (list_.size());
83  }
84 
86  const_iterator cbegin() const {
87  return (list_.cbegin());
88  }
89 
91  const_iterator cend() const {
92  return (list_.cend());
93  }
94 
99  bool contains(const ClientClass& x) const {
100  return (set_.count(x) != 0);
101  }
102 
104  void clear() {
105  list_.clear();
106  set_.clear();
107  }
108 
114  std::string toText(const std::string& separator = ", ") const;
115 
116  private:
118  std::list<ClientClass> list_;
119 
121  std::unordered_set<ClientClass> set_;
122  };
123 
124 };
125 
126 };
127 
128 #endif /* CLASSIFY_H */
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Definition: classify.h:47
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition: classify.h:99
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:91
void clear()
Clears containers.
Definition: classify.h:104
size_t size() const
Returns the number of classes.
Definition: classify.h:81
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
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
bool empty() const
Check if classes is empty.
Definition: classify.h:73
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:86
Container for storing client class names.
Definition: classify.h:43
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition: classify.cc:40