Kea  2.1.7-git
rrclass.h
Go to the documentation of this file.
1 
8 // Copyright (C) 2010-2021 Internet Systems Consortium, Inc. ("ISC")
9 //
10 // This Source Code Form is subject to the terms of the Mozilla Public
11 // License, v. 2.0. If a copy of the MPL was not distributed with this
12 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 
14 #ifndef RRCLASS_H
15 #define RRCLASS_H 1
16 
17 #include <stdint.h>
18 
19 #include <string>
20 #include <ostream>
21 
22 #include <dns/exceptions.h>
23 
24 #include <boost/optional.hpp>
25 
26 // Undefine the macro IN which is defined in some operating systems
27 // but conflicts the IN RR class.
28 
29 #ifdef IN
30 #undef IN
31 #endif
32 
33 namespace isc {
34 namespace util {
35 class InputBuffer;
36 class OutputBuffer;
37 }
38 
39 namespace dns {
40 
41 // forward declarations
42 class AbstractMessageRenderer;
43 
48 class InvalidRRClass : public DNSTextError {
49 public:
50  InvalidRRClass(const char* file, size_t line, const char* what) :
51  DNSTextError(file, line, what) {}
52 };
53 
59 public:
60  IncompleteRRClass(const char* file, size_t line, const char* what) :
61  isc::dns::Exception(file, line, what) {}
62 };
63 
98 class RRClass {
99 public:
103 
104  explicit RRClass(uint16_t classcode) : classcode_(classcode) {}
135  explicit RRClass(const std::string& class_str);
146  explicit RRClass(isc::util::InputBuffer& buffer);
147 
180  static RRClass* createFromText(const std::string& class_str);
181 
184 
185 
191 
192  const std::string toText() const;
216  void toWire(AbstractMessageRenderer& renderer) const;
226  void toWire(isc::util::OutputBuffer& buffer) const;
228 
232 
233  uint16_t getCode() const { return (classcode_); }
240 
244 
245  bool equals(const RRClass& other) const
254  { return (classcode_ == other.classcode_); }
256  bool operator==(const RRClass& other) const { return (equals(other)); }
257 
264  bool nequals(const RRClass& other) const
265  { return (classcode_ != other.classcode_); }
267  bool operator!=(const RRClass& other) const { return (nequals(other)); }
268 
284  bool operator<(const RRClass& other) const
285  { return (classcode_ < other.classcode_); }
286 
287  // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS
288  static const RRClass& ANY();
289  static const RRClass& CH();
290  static const RRClass& HS();
291  static const RRClass& IN();
292  static const RRClass& NONE();
293  // END_WELL_KNOWN_CLASS_DECLARATIONS
294 
295 private:
296  uint16_t classcode_;
297 };
298 
299 // BEGIN_WELL_KNOWN_CLASS_DEFINITIONS
300 inline const RRClass&
301 RRClass::ANY() {
302  static RRClass rrclass(255);
303  return (rrclass);
304 }
305 
306 inline const RRClass&
307 RRClass::CH() {
308  static RRClass rrclass(3);
309  return (rrclass);
310 }
311 
312 inline const RRClass&
313 RRClass::HS() {
314  static RRClass rrclass(4);
315  return (rrclass);
316 }
317 
318 inline const RRClass&
319 RRClass::IN() {
320  static RRClass rrclass(1);
321  return (rrclass);
322 }
323 
324 inline const RRClass&
326  static RRClass rrclass(254);
327  return (rrclass);
328 }
329 
330 // END_WELL_KNOWN_CLASS_DEFINITIONS
331 
346 std::ostream&
347 operator<<(std::ostream& os, const RRClass& rrclass);
348 }
349 }
350 #endif // RRCLASS_H
351 
352 // Local Variables:
353 // mode: c++
354 // End:
Base class for all sorts of text parse errors.
A standard DNS module exception that is thrown if an RRClass object is being constructed from a incom...
Definition: rrclass.h:58
std::ostream & operator<<(std::ostream &os, const CSVRow &row)
Overrides standard output stream operator for CSVRow object.
Definition: csv_file.cc:100
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition: rrclass.h:48
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
IncompleteRRClass(const char *file, size_t line, const char *what)
Definition: rrclass.h:60
bool operator==(const RRClass &other) const
Same as equals().
Definition: rrclass.h:256
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
bool nequals(const RRClass &other) const
Return true iff two RRClasses are not equal.
Definition: rrclass.h:264
Defines the logger used by the top-level component of kea-lfc.
InvalidRRClass(const char *file, size_t line, const char *what)
Definition: rrclass.h:50
bool operator<(const RRClass &other) const
Less-than comparison for RRClass against other.
Definition: rrclass.h:284
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
bool operator!=(const RRClass &other) const
Same as nequals().
Definition: rrclass.h:267