Kea 2.2.0
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
37namespace isc {
38
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
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
115 return (container_.cbegin());
116 }
118 return (container_.begin());
119 }
121 return (container_.begin());
122 }
124
128 return (container_.cend());
129 }
131 return (container_.end());
132 }
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
162
163 private:
165 ClientClassContainer container_;
166 };
167}
168
169}
170
171#endif /* CLASSIFY_H */
Container for storing client class names.
Definition: classify.h:70
void clear()
Clears containers.
Definition: classify.h:145
ClientClassContainer::iterator iterator
Definition: classify.h:75
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition: classify.h:74
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
Definition: classify.cc:49
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:90
const_iterator begin() const
Definition: classify.h:117
bool empty() const
Check if classes is empty.
Definition: classify.h:100
void erase(const ClientClass &class_name)
Erase element by name.
Definition: classify.cc:40
isc::data::ElementPtr toElement() const
Returns all class names as an ElementPtr of type ListElement.
Definition: classify.cc:67
ClientClasses()
Default constructor.
Definition: classify.h:78
const_iterator end() const
Definition: classify.h:130
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition: classify.cc:55
const_iterator cbegin() const
Iterators to the first element.
Definition: classify.h:114
const_iterator cend() const
Iterators to the past the end element.
Definition: classify.h:127
size_t size() const
Returns the number of classes.
Definition: classify.h:108
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
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
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