Kea  1.5.0
option_space_container.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2017 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 OPTION_SPACE_CONTAINER_H
8 #define OPTION_SPACE_CONTAINER_H
9 
10 #include <list>
11 #include <string>
12 
13 namespace isc {
14 namespace dhcp {
15 
27 template<typename ContainerType, typename ItemType, typename Selector>
29 public:
30 
32  typedef boost::shared_ptr<ContainerType> ItemsContainerPtr;
33 
37  bool empty() const {
38  return (option_space_map_.empty());
39  }
40 
45  void addItem(const ItemType& item, const Selector& option_space) {
46  ItemsContainerPtr items = getItems(option_space);
47  items->push_back(item);
48  option_space_map_[option_space] = items;
49  }
50 
60  ItemsContainerPtr getItems(const Selector& option_space) const {
61  const typename OptionSpaceMap::const_iterator& items =
62  option_space_map_.find(option_space);
63  if (items == option_space_map_.end()) {
64  return (ItemsContainerPtr(new ContainerType()));
65  }
66  return (items->second);
67  }
68 
76  std::list<Selector> getOptionSpaceNames() const {
77  std::list<Selector> names;
78  for (typename OptionSpaceMap::const_iterator space =
79  option_space_map_.begin();
80  space != option_space_map_.end(); ++space) {
81  names.push_back(space->first);
82  }
83  return (names);
84  }
85 
87  void clearItems() {
88  option_space_map_.clear();
89  }
90 
100  bool equals(const OptionSpaceContainer& other) const {
101  for (typename OptionSpaceMap::const_iterator it =
102  option_space_map_.begin(); it != option_space_map_.end();
103  ++it) {
104 
105  typename OptionSpaceMap::const_iterator other_it =
106  other.option_space_map_.find(it->first);
107  if (other_it == other.option_space_map_.end()) {
108  return (false);
109  }
110 
111  // If containers have different sizes it is an indication that
112  // they are unequal.
113  if (it->second->size() != other_it->second->size()) {
114  return (false);
115  }
116 
117  // If they have the same sizes, we have to compare each element.
118  for (typename ContainerType::const_iterator items_it =
119  it->second->begin();
120  items_it != it->second->end(); ++items_it) {
121 
122  bool match_found = false;
123  for (typename ContainerType::const_iterator other_items_it =
124  other_it->second->begin();
125  other_items_it != other_it->second->end();
126  ++other_items_it) {
127  if (items_it->equals(*other_items_it)) {
128  match_found = true;
129  break;
130  }
131  }
132 
133  if (!match_found) {
134  return (false);
135  }
136  }
137  }
138  return (true);
139  }
140 
141 private:
142 
144  typedef std::map<Selector, ItemsContainerPtr> OptionSpaceMap;
145  OptionSpaceMap option_space_map_;
146 };
147 
148 
149 } // end of isc::dhcp namespace
150 } // end of isc namespace
151 
152 #endif // OPTION_SPACE_CONTAINER_H
isc::dhcp::OptionSpaceContainer::addItem
void addItem(const ItemType &item, const Selector &option_space)
Adds a new item to the option_space.
Definition: option_space_container.h:45
isc::dhcp::OptionSpaceContainer::equals
bool equals(const OptionSpaceContainer &other) const
Check if two containers are equal.
Definition: option_space_container.h:100
isc::dhcp::OptionSpaceContainer
Simple container for option spaces holding various items.
Definition: option_space_container.h:28
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::OptionSpaceContainer::ItemsContainerPtr
boost::shared_ptr< ContainerType > ItemsContainerPtr
Pointer to the container.
Definition: option_space_container.h:32
isc::dhcp::OptionSpaceContainer::clearItems
void clearItems()
Remove all items from the container.
Definition: option_space_container.h:87
isc::dhcp::OptionSpaceContainer::empty
bool empty() const
Indicates the container is empty.
Definition: option_space_container.h:37
isc::dhcp::OptionSpaceContainer::getOptionSpaceNames
std::list< Selector > getOptionSpaceNames() const
Get a list of existing option spaces.
Definition: option_space_container.h:76
isc::dhcp::OptionSpaceContainer::getItems
ItemsContainerPtr getItems(const Selector &option_space) const
Get all items for the particular option space.
Definition: option_space_container.h:60