Kea  2.3.5-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 <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 
38 namespace isc {
39 namespace 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 
74  ClientClass class_def_;
75 
77  ClientClass class_;
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  void insert(const ClientClass& class_name) {
129  static_cast<void>(container_.push_back(class_name));
130  }
131 
135  void erase(const ClientClass& class_name);
136 
138  bool empty() const {
139  return (container_.empty());
140  }
141 
146  size_t size() const {
147  return (container_.size());
148  }
149 
152  const_iterator cbegin() const {
153  return (container_.cbegin());
154  }
155  const_iterator begin() const {
156  return (container_.begin());
157  }
158  iterator begin() {
159  return (container_.begin());
160  }
162 
165  const_iterator cend() const {
166  return (container_.cend());
167  }
168  const_iterator end() const {
169  return (container_.end());
170  }
171  iterator end() {
172  return (container_.end());
173  }
175 
180  bool contains(const ClientClass& x) const;
181 
183  void clear() {
184  container_.clear();
185  }
186 
194  std::string toText(const std::string& separator = ", ") const;
195 
199  isc::data::ElementPtr toElement() const;
200 
201  private:
203  ClientClassContainer container_;
204  };
205 }
206 }
207 
208 #endif /* CLASSIFY_H */
Tag for the name index.
Definition: classify.h:84
size_t size() const
Returns the number of classes.
Definition: classify.h:146
Tag for the sequence index.
Definition: classify.h:45
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
const_iterator cbegin() const
Iterators to the first element.
Definition: classify.h:152
ClientClassContainer::const_iterator const_iterator
Type of iterators.
Definition: classify.h:112
Tag for the sequence index.
Definition: classify.h:81
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
SubClassRelation(const ClientClass &class_def, const ClientClass &subclass)
Constructor.
Definition: classify.h:69
ClientClass class_
The class or subclass name.
Definition: classify.h:77
void clear()
Clears containers.
Definition: classify.h:183
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
bool empty() const
Check if classes is empty.
Definition: classify.h:138
Defines the logger used by the top-level component of kea-lfc.
ClientClasses()
Default constructor.
Definition: classify.h:116
Defines a subclass to template class relation.
Definition: classify.h:67
ClientClassContainer::iterator iterator
Definition: classify.h:113
const_iterator begin() const
Definition: classify.h:155
const_iterator cend() const
Iterators to the past the end element.
Definition: classify.h:165
ClientClass class_def_
The class definition name.
Definition: classify.h:74
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:128
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
const_iterator end() const
Definition: classify.h:168
Container for storing client class names.
Definition: classify.h:108
Tag for the name index.
Definition: classify.h:48