Kea  2.1.6-git
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 <boost/multi_index/hashed_index.hpp>
11 #include <boost/multi_index/identity.hpp>
12 #include <boost/multi_index/sequenced_index.hpp>
13 #include <boost/multi_index_container.hpp>
14 #include <string>
15 
32 
33 namespace isc {
34 
35 namespace dhcp {
36 
38  typedef std::string ClientClass;
39 
41  struct ClassSequenceTag { };
42 
44  struct ClassNameTag { };
45 
47  typedef boost::multi_index_container<
49  boost::multi_index::indexed_by<
50  // First index is the sequence one.
51  boost::multi_index::sequenced<
52  boost::multi_index::tag<ClassSequenceTag>
53  >,
54  // Second index is the name hash one.
55  boost::multi_index::hashed_unique<
56  boost::multi_index::tag<ClassNameTag>,
57  boost::multi_index::identity<ClientClass>
58  >
59  >
61 
66  class ClientClasses {
67  public:
68 
70  typedef ClientClassContainer::const_iterator const_iterator;
71 
73  ClientClasses() : container_() {
74  }
75 
80  ClientClasses(const ClientClass& class_names);
81 
85  void insert(const ClientClass& class_name) {
86  static_cast<void>(container_.push_back(class_name));
87  }
88 
92  void erase(const ClientClass& class_name);
93 
95  bool empty() const {
96  return (container_.empty());
97  }
98 
103  size_t size() const {
104  return (container_.size());
105  }
106 
108  const_iterator cbegin() const {
109  return (container_.cbegin());
110  }
111 
113  const_iterator cend() const {
114  return (container_.cend());
115  }
116 
121  bool contains(const ClientClass& x) const;
122 
124  void clear() {
125  container_.clear();
126  }
127 
133  std::string toText(const std::string& separator = ", ") const;
134 
135  private:
137  ClientClassContainer container_;
138  };
139 }
140 
141 }
142 
143 #endif /* CLASSIFY_H */
size_t size() const
Returns the number of classes.
Definition: classify.h:103
Tag for the sequence index.
Definition: classify.h:41
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:108
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition: classify.h:70
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:60
void clear()
Clears containers.
Definition: classify.h:124
bool empty() const
Check if classes is empty.
Definition: classify.h:95
Defines the logger used by the top-level component of kea-lfc.
ClientClasses()
Default constructor.
Definition: classify.h:73
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:113
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:85
std::string ClientClass
Defines a single class name.
Definition: classify.h:38
Container for storing client class names.
Definition: classify.h:66
Tag for the name index.
Definition: classify.h:44