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
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/member.hpp>
14#include <boost/multi_index/hashed_index.hpp>
15#include <boost/multi_index/identity.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index/sequenced_index.hpp>
18
19#include <string>
20
37
38namespace isc {
39namespace 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
69 SubClassRelation(const ClientClass& class_def, const ClientClass& subclass) :
70 class_def_(class_def), class_(subclass) {
71 }
72
75
78 };
79
82
85
87 typedef boost::multi_index_container<
89 boost::multi_index::indexed_by<
90 // First index is the sequence one.
91 boost::multi_index::sequenced<
92 boost::multi_index::tag<TemplateClassSequenceTag>
93 >,
94 // Second index is the name hash one.
95 boost::multi_index::hashed_unique<
96 boost::multi_index::tag<TemplateClassNameTag>,
97 boost::multi_index::member<SubClassRelation,
100 >
101 >
103
109 public:
110
112 typedef ClientClassContainer::const_iterator const_iterator;
113 typedef ClientClassContainer::iterator iterator;
114
116 ClientClasses() : container_() {
117 }
118
123 ClientClasses(const std::string& class_names);
124
128 ClientClasses(const ClientClasses& other);
129
132
136 bool equals(const ClientClasses& other) const;
137
141 bool operator==(const ClientClasses& other) const {
142 return(equals(other));
143 }
144
148 bool operator!=(const ClientClasses& other) const {
149 return(!equals(other));
150 }
151
155 void insert(const ClientClass& class_name) {
156 static_cast<void>(container_.push_back(class_name));
157 }
158
162 void erase(const ClientClass& class_name);
163
165 bool empty() const {
166 return (container_.empty());
167 }
168
173 size_t size() const {
174 return (container_.size());
175 }
176
180 return (container_.cbegin());
181 }
183 return (container_.begin());
184 }
186 return (container_.begin());
187 }
189
193 return (container_.cend());
194 }
196 return (container_.end());
197 }
199 return (container_.end());
200 }
202
207 bool contains(const ClientClass& x) const;
208
210 void clear() {
211 container_.clear();
212 }
213
221 std::string toText(const std::string& separator = ", ") const;
222
227
236
237 private:
239 ClientClassContainer container_;
240 };
241}
242}
243
244#endif /* CLASSIFY_H */
Container for storing client class names.
Definition classify.h:108
bool equals(const ClientClasses &other) const
Compares two ClientClasses container for equality.
Definition classify.cc:104
void clear()
Clears containers.
Definition classify.h:210
ClientClassContainer::iterator iterator
Definition classify.h:113
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition classify.h:112
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:155
const_iterator begin() const
Definition classify.h:182
bool empty() const
Check if classes is empty.
Definition classify.h:165
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:109
bool operator==(const ClientClasses &other) const
Compares two ClientClasses containers for equality.
Definition classify.h:141
isc::data::ElementPtr toElement() const
Returns all class names as an ElementPtr of type ListElement.
Definition classify.cc:76
void fromElement(isc::data::ConstElementPtr list)
Sets contents from a ListElement.
Definition classify.cc:85
ClientClasses()
Default constructor.
Definition classify.h:116
const_iterator end() const
Definition classify.h:195
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition classify.cc:61
const_iterator cbegin() const
Iterators to the first element.
Definition classify.h:179
bool operator!=(const ClientClasses &other) const
Compares two ClientClasses container for inequality.
Definition classify.h:148
const_iterator cend() const
Iterators to the past the end element.
Definition classify.h:192
size_t size() const
Returns the number of classes.
Definition classify.h:173
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
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
std::string ClientClass
Defines a single class name.
Definition classify.h:42
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:102
Defines the logger used by the top-level component of kea-lfc.
Tag for the name index.
Definition classify.h:48
Tag for the sequence index.
Definition classify.h:45
Defines a subclass to template class relation.
Definition classify.h:67
ClientClass class_def_
The class definition name.
Definition classify.h:74
ClientClass class_
The class or subclass name.
Definition classify.h:77
SubClassRelation(const ClientClass &class_def, const ClientClass &subclass)
Constructor.
Definition classify.h:69
Tag for the name index.
Definition classify.h:84
Tag for the sequence index.
Definition classify.h:81