Kea: classify.h Source File

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