Kea  2.3.2-git
classify.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2022 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 <cc/data.h>
11 
12 #include <boost/multi_index_container.hpp>
13 #include <boost/multi_index/hashed_index.hpp>
14 #include <boost/multi_index/identity.hpp>
15 #include <boost/multi_index/ordered_index.hpp>
16 #include <boost/multi_index/sequenced_index.hpp>
17 
18 #include <string>
19 
36 
37 namespace isc {
38 
39 namespace dhcp {
40 
42  typedef std::string ClientClass;
43 
45  struct ClassSequenceTag { };
46 
48  struct ClassNameTag { };
49 
51  typedef boost::multi_index_container<
53  boost::multi_index::indexed_by<
54  // First index is the sequence one.
55  boost::multi_index::sequenced<
56  boost::multi_index::tag<ClassSequenceTag>
57  >,
58  // Second index is the name hash one.
59  boost::multi_index::hashed_unique<
60  boost::multi_index::tag<ClassNameTag>,
61  boost::multi_index::identity<ClientClass>
62  >
63  >
65 
70  class ClientClasses {
71  public:
72 
74  typedef ClientClassContainer::const_iterator const_iterator;
75  typedef ClientClassContainer::iterator iterator;
76 
78  ClientClasses() : container_() {
79  }
80 
85  ClientClasses(const ClientClass& class_names);
86 
90  void insert(const ClientClass& class_name) {
91  static_cast<void>(container_.push_back(class_name));
92  }
93 
97  void erase(const ClientClass& class_name);
98 
100  bool empty() const {
101  return (container_.empty());
102  }
103 
108  size_t size() const {
109  return (container_.size());
110  }
111 
114  const_iterator cbegin() const {
115  return (container_.cbegin());
116  }
117  const_iterator begin() const {
118  return (container_.begin());
119  }
120  iterator begin() {
121  return (container_.begin());
122  }
124 
127  const_iterator cend() const {
128  return (container_.cend());
129  }
130  const_iterator end() const {
131  return (container_.end());
132  }
133  iterator end() {
134  return (container_.end());
135  }
137 
142  bool contains(const ClientClass& x) const;
143 
145  void clear() {
146  container_.clear();
147  }
148 
156  std::string toText(const std::string& separator = ", ") const;
157 
161  isc::data::ElementPtr toElement() const;
162 
163  private:
165  ClientClassContainer container_;
166  };
167 }
168 
169 }
170 
171 #endif /* CLASSIFY_H */
size_t size() const
Returns the number of classes.
Definition: classify.h:108
Tag for the sequence index.
Definition: classify.h:45
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
const_iterator cbegin() const
Iterators to the first element.
Definition: classify.h:114
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition: classify.h:74
boost::multi_index_container< ClientClass, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< ClassSequenceTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< ClassNameTag >, boost::multi_index::identity< ClientClass > > > > ClientClassContainer
the client class multi-index.
Definition: classify.h:64
void clear()
Clears containers.
Definition: classify.h:145
bool empty() const
Check if classes is empty.
Definition: classify.h:100
Defines the logger used by the top-level component of kea-lfc.
ClientClasses()
Default constructor.
Definition: classify.h:78
ClientClassContainer::iterator iterator
Definition: classify.h:75
const_iterator begin() const
Definition: classify.h:117
const_iterator cend() const
Iterators to the past the end element.
Definition: classify.h:127
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:90
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
const_iterator end() const
Definition: classify.h:130
Container for storing client class names.
Definition: classify.h:70
Tag for the name index.
Definition: classify.h:48