Kea 2.7.5
classify.h
Go to the documentation of this file.
1// Copyright (C) 2014-2024 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
38
39namespace isc {
40namespace dhcp {
41
43typedef std::string ClientClass;
44
47
49struct ClassNameTag { };
50
52typedef boost::multi_index_container<
54 boost::multi_index::indexed_by<
55 // First index is the sequence one.
56 boost::multi_index::sequenced<
57 boost::multi_index::tag<ClassSequenceTag>
58 >,
59 // Second index is the name hash one.
60 boost::multi_index::hashed_unique<
61 boost::multi_index::tag<ClassNameTag>,
62 boost::multi_index::identity<ClientClass>
63 >
64 >
66
70 SubClassRelation(const ClientClass& class_def, const ClientClass& subclass) :
71 class_def_(class_def), class_(subclass) {
72 }
73
76
79};
80
83
86
88typedef boost::multi_index_container<
90 boost::multi_index::indexed_by<
91 // First index is the sequence one.
92 boost::multi_index::sequenced<
93 boost::multi_index::tag<TemplateClassSequenceTag>
94 >,
95 // Second index is the name hash one.
96 boost::multi_index::hashed_unique<
97 boost::multi_index::tag<TemplateClassNameTag>,
98 boost::multi_index::member<SubClassRelation,
101 >
102 >
104
110public:
111
113 typedef ClientClassContainer::const_iterator const_iterator;
114 typedef ClientClassContainer::iterator iterator;
115
117 ClientClasses() : container_() {
118 }
119
124 ClientClasses(const std::string& class_names);
125
127 virtual ~ClientClasses() {}
128
132 ClientClasses(const ClientClasses& other);
133
136
140 bool equals(const ClientClasses& other) const;
141
145 bool operator==(const ClientClasses& other) const {
146 return(equals(other));
147 }
148
152 bool operator!=(const ClientClasses& other) const {
153 return(!equals(other));
154 }
155
159 void insert(const ClientClass& class_name) {
160 static_cast<void>(container_.push_back(class_name));
161 }
162
166 void erase(const ClientClass& class_name);
167
169 bool empty() const {
170 return (container_.empty());
171 }
172
177 size_t size() const {
178 return (container_.size());
179 }
180
184 return (container_.cbegin());
185 }
186
188 return (container_.begin());
189 }
190
192 return (container_.begin());
193 }
195
199 return (container_.cend());
200 }
201
203 return (container_.end());
204 }
205
207 return (container_.end());
208 }
210
217 bool intersects(const ClientClasses& cclasses) const;
218
223 bool contains(const ClientClass& x) const;
224
226 void clear() {
227 container_.clear();
228 }
229
237 std::string toText(const std::string& separator = ", ") const;
238
242 virtual isc::data::ElementPtr toElement() const;
243
252
253private:
255 ClientClassContainer container_;
256};
257
258}
259}
260
261#endif /* CLASSIFY_H */
Container for storing client class names.
Definition classify.h:109
bool equals(const ClientClasses &other) const
Compares two ClientClasses container for equality.
Definition classify.cc:123
void clear()
Clears containers.
Definition classify.h:226
ClientClassContainer::iterator iterator
Definition classify.h:114
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition classify.h:113
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:159
const_iterator begin() const
Definition classify.h:187
virtual ~ClientClasses()
Destructor.
Definition classify.h:127
bool empty() const
Check if classes is empty.
Definition classify.h:169
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:145
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:117
const_iterator end() const
Definition classify.h:202
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:183
bool operator!=(const ClientClasses &other) const
Compares two ClientClasses container for inequality.
Definition classify.h:152
const_iterator cend() const
Iterators to the past the end element.
Definition classify.h:198
size_t size() const
Returns the number of classes.
Definition classify.h:177
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:43
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:103
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:65
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:49
Tag for the sequence index.
Definition classify.h:46
Defines a subclass to template class relation.
Definition classify.h:68
ClientClass class_def_
The class definition name.
Definition classify.h:75
ClientClass class_
The class or subclass name.
Definition classify.h:78
SubClassRelation(const ClientClass &class_def, const ClientClass &subclass)
Constructor.
Definition classify.h:70
Tag for the name index.
Definition classify.h:85
Tag for the sequence index.
Definition classify.h:82