Kea 3.3.1
classify.h
Go to the documentation of this file.
1// Copyright (C) 2014-2026 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 <functional>
21#include <string>
22#include <vector>
23
40
41namespace isc {
42namespace dhcp {
43
45typedef std::string ClientClass;
46
49
51struct ClassNameTag { };
52
54typedef boost::multi_index_container<
56 boost::multi_index::indexed_by<
57 // First index is the sequence one.
58 boost::multi_index::sequenced<
59 boost::multi_index::tag<ClassSequenceTag>
60 >,
61 // Second index is the name hash one.
62 boost::multi_index::hashed_unique<
63 boost::multi_index::tag<ClassNameTag>,
64 boost::multi_index::identity<ClientClass>
65 >
66 >
68
72 SubClassRelation(const ClientClass& class_def, const ClientClass& subclass) :
73 class_def_(class_def), class_(subclass) {
74 }
75
78
81};
82
85
88
90typedef boost::multi_index_container<
92 boost::multi_index::indexed_by<
93 // First index is the sequence one.
94 boost::multi_index::sequenced<
95 boost::multi_index::tag<TemplateClassSequenceTag>
96 >,
97 // Second index is the name hash one.
98 boost::multi_index::hashed_unique<
99 boost::multi_index::tag<TemplateClassNameTag>,
100 boost::multi_index::member<SubClassRelation,
103 >
104 >
106
112public:
113
115 typedef ClientClassContainer::const_iterator const_iterator;
116 typedef ClientClassContainer::iterator iterator;
117
119 ClientClasses() : container_() {
120 }
121
126 ClientClasses(const std::string& class_names);
127
129 virtual ~ClientClasses() {}
130
134 ClientClasses(const ClientClasses& other);
135
138
142 bool equals(const ClientClasses& other) const;
143
147 bool operator==(const ClientClasses& other) const {
148 return(equals(other));
149 }
150
154 bool operator!=(const ClientClasses& other) const {
155 return(!equals(other));
156 }
157
161 void insert(const ClientClass& class_name) {
162 static_cast<void>(container_.push_back(class_name));
163 }
164
168 void erase(const ClientClass& class_name);
169
171 bool empty() const {
172 return (container_.empty());
173 }
174
179 size_t size() const {
180 return (container_.size());
181 }
182
186 return (container_.cbegin());
187 }
188
190 return (container_.begin());
191 }
192
194 return (container_.begin());
195 }
196
197
201 return (container_.cend());
202 }
203
205 return (container_.end());
206 }
207
209 return (container_.end());
210 }
211
212
219 bool intersects(const ClientClasses& cclasses) const;
220
225 bool contains(const ClientClass& x) const;
226
228 void clear() {
229 container_.clear();
230 }
231
239 std::string toText(const std::string& separator = ", ") const;
240
244 virtual isc::data::ElementPtr toElement() const;
245
254
256 struct Hash {
261 size_t operator()(const ClientClasses& client_classes);
262 };
263
265 static const std::vector<bool> CLIENT_CLASS_VALID_CHARACTERS;
266
268 static constexpr char CLIENT_CLASS_ESCAPE = '%';
269
283 static std::string escape(const std::string& name,
284 bool escape_escape = true);
285
286private:
288 ClientClassContainer container_;
289};
290
300
301size_t hash_value(const ClientClasses& client_classes);
302
304typedef boost::shared_ptr<ClientClasses> ClientClassesPtr;
305
306}
307}
308
309#endif /* CLASSIFY_H */
Container for storing client class names.
Definition classify.h:111
bool equals(const ClientClasses &other) const
Compares two ClientClasses container for equality.
Definition classify.cc:120
void clear()
Clears containers.
Definition classify.h:228
ClientClassContainer::iterator iterator
Definition classify.h:116
static const std::vector< bool > CLIENT_CLASS_VALID_CHARACTERS
Valid character in a client class name boolean vector.
Definition classify.h:265
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition classify.h:115
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition classify.cc:52
void insert(const ClientClass &class_name)
Insert an element.
Definition classify.h:161
const_iterator begin() const
Definition classify.h:189
static std::string escape(const std::string &name, bool escape_escape=true)
Escape a client class name.
Definition classify.cc:164
virtual ~ClientClasses()
Destructor.
Definition classify.h:129
bool empty() const
Check if classes is empty.
Definition classify.h:171
void erase(const ClientClass &class_name)
Erase element by name.
Definition classify.cc:43
ClientClasses & operator=(const ClientClasses &other)
Assigns the contents of on container to another.
Definition classify.cc:125
bool operator==(const ClientClasses &other) const
Compares two ClientClasses containers for equality.
Definition classify.h:147
static constexpr char CLIENT_CLASS_ESCAPE
Escape character.
Definition classify.h:268
virtual isc::data::ElementPtr toElement() const
Returns all class names as an ElementPtr of type ListElement.
Definition classify.cc:92
void fromElement(isc::data::ConstElementPtr list)
Sets contents from a ListElement.
Definition classify.cc:101
bool intersects(const ClientClasses &cclasses) const
returns whether this container has at least one class in common with a given container.
Definition classify.cc:58
ClientClasses()
Default constructor.
Definition classify.h:119
const_iterator end() const
Definition classify.h:204
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition classify.cc:77
const_iterator cbegin() const
Iterators to the first element.
Definition classify.h:185
bool operator!=(const ClientClasses &other) const
Compares two ClientClasses container for inequality.
Definition classify.h:154
const_iterator cend() const
Iterators to the past the end element.
Definition classify.h:200
size_t size() const
Returns the number of classes.
Definition classify.h:179
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
std::string ClientClass
Defines a single class name.
Definition classify.h:45
boost::shared_ptr< ClientClasses > ClientClassesPtr
Smart pointer to ClientClasses object.
Definition classify.h:304
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:105
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:67
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:51
Tag for the sequence index.
Definition classify.h:48
Hash enabling use in the unordered containers.
Definition classify.h:256
size_t operator()(const ClientClasses &client_classes)
A hashing operator.
Definition classify.cc:135
Defines a subclass to template class relation.
Definition classify.h:70
ClientClass class_def_
The class definition name.
Definition classify.h:77
ClientClass class_
The class or subclass name.
Definition classify.h:80
SubClassRelation(const ClientClass &class_def, const ClientClass &subclass)
Constructor.
Definition classify.h:72
Tag for the name index.
Definition classify.h:87
Tag for the sequence index.
Definition classify.h:84