#pragma once
#include <cstddef>
#include <functional>
#include <string>
#include <string_view>
#include <utility>
namespace ddwaf {
using target_index = std::size_t;
inline target_index get_target_index(std::string_view address)
{
return std::hash<std::string_view>{}(address);
}
struct target_address {
explicit target_address(std::string name_)
: name(std::move(name_)), index(get_target_index(name))
{}
bool operator<(const target_address &o) const { return name < o.name; }
bool operator>(const target_address &o) const { return name > o.name; }
bool operator==(const target_address &o) const { return name == o.name; }
std::string name;
target_index index;
};
struct target_address_view {
target_address_view(const target_address &address) : name(address.name), index(address.index) {}
bool operator<(const target_address_view &o) const { return name < o.name; }
bool operator>(const target_address_view &o) const { return name > o.name; }
bool operator==(const target_address_view &o) const { return name == o.name; }
std::string_view name;
target_index index;
};
}
namespace std {
template <> struct hash<ddwaf::target_address> {
size_t operator()(const ddwaf::target_address &addr) const { return addr.index; }
};
template <> struct hash<ddwaf::target_address_view> {
size_t operator()(const ddwaf::target_address_view &addr) const { return addr.index; }
};
}