12#ifndef OPENVPN_ADDR_POOL_H
13#define OPENVPN_ADDR_POOL_H
18#include <unordered_map>
28template <
typename ADDR>
40 for (
const auto &
address : range)
49 auto [iter, inserted] =
map.try_emplace(addr,
false);
69 [[nodiscard]]
size_t n_free() const noexcept
86 throw Exception(
"PoolType: address in freelist doesn't exist in map");
111 if (optional_iterator)
113 (*optional_iterator)->second =
true;
125 if (optional_iterator)
128 (*optional_iterator)->second =
false;
140 for (
const auto &e :
map)
144 ret += e.first.to_string();
155 std::unordered_map<ADDR, bool>
map;
164 auto it =
map.find(addr);
165 if (it !=
map.end() && !it->second)
177 if (
auto it =
map.find(addr); it !=
map.end())
size_t n_free() const noexcept
Returns number of free pool addresses.
void add_range(const RangeType< ADDR > &range)
Adds range of addresses to pool (pool will own the addresses).
std::string to_string() const
auto is_address_available(const ADDR &addr) -> std::optional< decltype(map.begin())>
Checks if address is available (free)
void add_addr(const ADDR &addr)
bool acquire_addr(ADDR &dest)
virtual ~PoolType()=default
bool acquire_specific_addr(const ADDR &addr)
Acquires a specific address from the pool.
std::deque< ADDR > freelist
void release_addr(const ADDR &addr)
size_t n_in_use() const noexcept
Returns number of pool addresses currently in use.
std::unordered_map< ADDR, bool > map
virtual void freelist_fill()
auto is_address_in_use(const ADDR &addr) -> std::optional< decltype(map.begin())>
Checks if address is in use.
designed to represent and manage a range of IP addresses.
PoolType< IP::Addr > Pool