Kea 3.1.1
classify.h
Go to the documentation of this file.
1// Copyright (C) 2014-2025 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#include <cc/cfg_to_element.h>
12
13#include <boost/multi_index_container.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/multi_index/hashed_index.hpp>
16#include <boost/multi_index/identity.hpp>
17#include <boost/multi_index/ordered_index.hpp>
18#include <boost/multi_index/sequenced_index.hpp>
19
20#include <string>
21#include <functional>
22
39
40namespace isc {
41namespace dhcp {
42
44typedef std::string ClientClass;
45
48
50struct ClassNameTag { };
51
53typedef boost::multi_index_container<
55 boost::multi_index::indexed_by<
56 // First index is the sequence one.
57 boost::multi_index::sequenced<
58 boost::multi_index::tag<ClassSequenceTag>
59 >,
60 // Second index is the name hash one.
61 boost::multi_index::hashed_unique<
62 boost::multi_index::tag<ClassNameTag>,
63 boost::multi_index::identity<ClientClass>
64 >
65 >
67
71 SubClassRelation(const ClientClass& class_def, const ClientClass& subclass) :
72 class_def_(class_def), class_(subclass) {
73 }
74
77
80};
81
84
87
89typedef boost::multi_index_container<
91 boost::multi_index::indexed_by<
92 // First index is the sequence one.
93 boost::multi_index::sequenced<
94 boost::multi_index::tag<TemplateClassSequenceTag>
95 >,
96 // Second index is the name hash one.
97 boost::multi_index::hashed_unique<
98 boost::multi_index::tag<TemplateClassNameTag>,
99 boost::multi_index::member<SubClassRelation,
102 >
103 >
105
111public:
112
114 typedef ClientClassContainer::const_iterator const_iterator;
115 typedef ClientClassContainer::iterator iterator;
116
118 ClientClasses() : container_() {
119 }
120
125 ClientClasses(const std::string& class_names);
126
128 virtual ~ClientClasses() {}
129
133 ClientClasses(const ClientClasses& other);
134
137
141 bool equals(const ClientClasses& other) const;
142
146 bool operator==(const ClientClasses& other) const {
147 return(equals(other));
148 }
149
153 bool operator!=(const ClientClasses& other) const {
154 return(!equals(other));
155 }
156
160 void insert(const ClientClass& class_name) {
161 static_cast<void>(container_.push_back(class_name));
162 }
163
167 void erase(const ClientClass& class_name);
168
170 bool empty() const {
171 return (container_.empty());
172 }
173
178 size_t size() const {
179 return (container_.size());
180 }
181
185 return (container_.cbegin());
186 }
187
189 return (container_.begin());
190 }
191
193 return (container_.begin());
194 }
195
196
200 return (container_.cend());
201 }
202
204 return (container_.end());
205 }
206
208 return (container_.end());
209 }
210
211
218 bool intersects(const ClientClasses& cclasses) const;
219
224 bool contains(const ClientClass& x) const;
225
227 void clear() {
228 container_.clear();
229 }
230
238 std::string toText(const std::string& separator = ", ") const;
239
243 virtual isc::data::ElementPtr toElement() const;
244
253
255 struct Hash {
260 size_t operator()(const ClientClasses& client_classes);
261 };
262
263private:
265 ClientClassContainer container_;
266};
267
277
278size_t hash_value(const ClientClasses& client_classes);
279
281typedef boost::shared_ptr<ClientClasses> ClientClassesPtr;
282
283}
284}
285
286#endif /* CLASSIFY_H */
Container for storing client class names.
Definition classify.h:110
bool equals(const ClientClasses &other) const
Compares two ClientClasses container for equality.
Definition classify.cc:123
void clear()
Clears containers.
Definition classify.h:227
ClientClassContainer::iterator iterator
Definition classify.h:115
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition classify.h:114
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition classify.cc:55
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:160
const_iterator begin() const
Definition classify.h:188
virtual ~ClientClasses()
Destructor.
Definition classify.h:128
bool empty() const
Check if classes is empty.
Definition classify.h:170
void erase(const ClientClass &class_name)
Erase element by name.
Definition classify.cc:46
ClientClasses & operator=(const ClientClasses &other)
Assigns the contents of on container to another.
Definition classify.cc:128
bool operator==(const ClientClasses &other) const
Compares two ClientClasses containers for equality.
Definition classify.h:146
virtual isc::data::ElementPtr toElement() const
Returns all class names as an ElementPtr of type ListElement.
Definition classify.cc:95
void fromElement(isc::data::ConstElementPtr list)
Sets contents from a ListElement.
Definition classify.cc:104
bool intersects(const ClientClasses &cclasses) const
returns whether this container has at least one class in common with a given container.
Definition classify.cc:61
ClientClasses()
Default constructor.
Definition classify.h:118
const_iterator end() const
Definition classify.h:203
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition classify.cc:80
const_iterator cbegin() const
Iterators to the first element.
Definition classify.h:184
bool operator!=(const ClientClasses &other) const
Compares two ClientClasses container for inequality.
Definition classify.h:153
const_iterator cend() const
Iterators to the past the end element.
Definition classify.h:199
size_t size() const
Returns the number of classes.
Definition classify.h:178
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::string ClientClass
Defines a single class name.
Definition classify.h:44
boost::shared_ptr< ClientClasses > ClientClassesPtr
Smart pointer to ClientClasses object.
Definition classify.h:281
boost::multi_index_container< SubClassRelation, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< TemplateClassSequenceTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< TemplateClassNameTag >, boost::multi_index::member< SubClassRelation, ClientClass, &SubClassRelation::class_def_ > > > > SubClassRelationContainer
the subclass multi-index.
Definition classify.h:104
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:66
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Tag for the name index.
Definition classify.h:50
Tag for the sequence index.
Definition classify.h:47
Hash enabling use in the unordered containers.
Definition classify.h:255
size_t operator()(const ClientClasses &client_classes)
A hashing operator.
Definition classify.cc:138
Defines a subclass to template class relation.
Definition classify.h:69
ClientClass class_def_
The class definition name.
Definition classify.h:76
ClientClass class_
The class or subclass name.
Definition classify.h:79
SubClassRelation(const ClientClass &class_def, const ClientClass &subclass)
Constructor.
Definition classify.h:71
Tag for the name index.
Definition classify.h:86
Tag for the sequence index.
Definition classify.h:83