Kea  1.9.9-git
rrttl.h
Go to the documentation of this file.
1 // Copyright (C) 2010-2015 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 RRTTL_H
8 #define RRTTL_H 1
9 
10 #include <dns/exceptions.h>
11 
12 #include <boost/optional.hpp>
13 
14 #include <stdint.h>
15 
16 namespace isc {
17 namespace util {
18 class InputBuffer;
19 class OutputBuffer;
20 }
21 
22 namespace dns {
23 
24 // forward declarations
25 class AbstractMessageRenderer;
26 
31 class InvalidRRTTL : public DNSTextError {
32 public:
33  InvalidRRTTL(const char* file, size_t line, const char* what) :
34  DNSTextError(file, line, what) {}
35 };
36 
42 public:
43  IncompleteRRTTL(const char* file, size_t line, const char* what) :
44  isc::dns::Exception(file, line, what) {}
45 };
46 
55 class RRTTL {
56 public:
62 
63  explicit RRTTL(uint32_t ttlval) : ttlval_(ttlval) {}
69 
84  explicit RRTTL(const std::string& ttlstr);
85 
96  explicit RRTTL(isc::util::InputBuffer& buffer);
97 
125  static RRTTL* createFromText(const std::string& ttlstr);
127 
128 
132 
133  const std::string toText() const;
154  void toWire(AbstractMessageRenderer& renderer) const;
164  void toWire(isc::util::OutputBuffer& buffer) const;
166 
170 
171  uint32_t getValue() const { return (ttlval_); }
178 
186 
187  bool equals(const RRTTL& other) const
193  { return (ttlval_ == other.ttlval_); }
195  bool operator==(const RRTTL& other) const
196  { return (ttlval_ == other.ttlval_); }
202  bool nequals(const RRTTL& other) const
203  { return (ttlval_ != other.ttlval_); }
205  bool operator!=(const RRTTL& other) const
206  { return (ttlval_ != other.ttlval_); }
214  bool leq(const RRTTL& other) const
215  { return (ttlval_ <= other.ttlval_); }
216 
218  bool operator<=(const RRTTL& other) const
219  { return (ttlval_ <= other.ttlval_); }
220 
228  bool geq(const RRTTL& other) const
229  { return (ttlval_ >= other.ttlval_); }
230 
232  bool operator>=(const RRTTL& other) const
233  { return (ttlval_ >= other.ttlval_); }
234 
242  bool lthan(const RRTTL& other) const
243  { return (ttlval_ < other.ttlval_); }
244 
246  bool operator<(const RRTTL& other) const
247  { return (ttlval_ < other.ttlval_); }
248 
256  bool gthan(const RRTTL& other) const
257  { return (ttlval_ > other.ttlval_); }
258 
260  bool operator>(const RRTTL& other) const
261  { return (ttlval_ > other.ttlval_); }
263 
267 
268  static const RRTTL& MAX_TTL() {
275  static const RRTTL max_ttl(0x7fffffff);
276  return (max_ttl);
277  }
279 
280 private:
281  uint32_t ttlval_;
282 };
283 
298 std::ostream&
299 operator<<(std::ostream& os, const RRTTL& rrttl);
300 }
301 }
302 #endif // RRTTL_H
303 
304 // Local Variables:
305 // mode: c++
306 // End:
bool leq(const RRTTL &other) const
Less-than or equal comparison for RRTTL against other.
Definition: rrttl.h:214
static const RRTTL & MAX_TTL()
The TTL of the max allowable value, per RFC2181 Section 8.
Definition: rrttl.h:274
bool operator<=(const RRTTL &other) const
Same as leq()
Definition: rrttl.h:218
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
Base class for all sorts of text parse errors.
bool operator>(const RRTTL &other) const
Same as gthan()
Definition: rrttl.h:260
bool equals(const RRTTL &other) const
Return true iff two RRTTLs are equal.
Definition: rrttl.h:192
bool operator<(const RRTTL &other) const
Same as lthan()
Definition: rrttl.h:246
void toWire(AbstractMessageRenderer &renderer) const
Render the RRTTL in the wire format.
Definition: rrttl.cc:204
bool operator!=(const RRTTL &other) const
Same as nequals().
Definition: rrttl.h:205
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
bool lthan(const RRTTL &other) const
Less-than comparison for RRTTL against other.
Definition: rrttl.h:242
bool gthan(const RRTTL &other) const
Greater-than comparison for RRTTL against other.
Definition: rrttl.h:256
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
uint32_t getValue() const
Returns the TTL value as a 32-bit unsigned integer.
Definition: rrttl.h:176
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool operator==(const RRTTL &other) const
Same as equals().
Definition: rrttl.h:195
static RRTTL * createFromText(const std::string &ttlstr)
A separate factory of RRTTL from text.
Definition: rrttl.cc:176
bool geq(const RRTTL &other) const
Greater-than or equal comparison for RRTTL against other.
Definition: rrttl.h:228
const std::string toText() const
Convert the RRTTL to a string.
Definition: rrttl.cc:192
bool operator>=(const RRTTL &other) const
Same as geq()
Definition: rrttl.h:232
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
InvalidRRTTL(const char *file, size_t line, const char *what)
Definition: rrttl.h:33
A standard DNS module exception that is thrown if an RRTTL object is being constructed from an unreco...
Definition: rrttl.h:31
bool nequals(const RRTTL &other) const
Return true iff two RRTTLs are not equal.
Definition: rrttl.h:202
IncompleteRRTTL(const char *file, size_t line, const char *what)
Definition: rrttl.h:43
A standard DNS module exception that is thrown if an RRTTL object is being constructed from a incompl...
Definition: rrttl.h:41
RRTTL(uint32_t ttlval)
Constructor from an integer TTL value.
Definition: rrttl.h:68