/* * This file is part of PowerDNS or dnsdist. * Copyright -- PowerDNS.COM B.V. and its contributors * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * In addition, for the avoidance of any doubt, permission is granted to * link this program with OpenSSL and to (re)distribute the binaries * produced as the result of such linking. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include "namespaces.hh" /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS', * 'CNAME' etcetera. These types have both a name and a number. This class can seamlessly move between * them. Use it like this: \code QType t; t="CNAME"; cout< names; const static map numbers; private: uint16_t code; }; // Define hash function on QType. See https://en.cppreference.com/w/cpp/utility/hash namespace std { template<> struct hash { std::size_t operator()(QType qtype) const noexcept { return std::hash{}(qtype.getCode()); } }; } // Used by e.g. boost multi-index inline size_t hash_value(const QType qtype) { return qtype.getCode(); } struct QClass { constexpr QClass(uint16_t code = 0) : qclass(code) {} constexpr operator uint16_t() const { return qclass; } constexpr uint16_t getCode() const { return qclass; } const std::string toString() const; static const QClass IN; static const QClass CHAOS; static const QClass NONE; static const QClass ANY; private: uint16_t qclass; }; constexpr QClass QClass::IN(1); constexpr QClass QClass::CHAOS(3); constexpr QClass QClass::NONE(254); constexpr QClass QClass::ANY(255); inline std::ostream& operator<<(std::ostream& s, QClass qclass) { return s << qclass.toString(); }