Kea  1.5.0
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:
isc::dns::InvalidRRTTL::InvalidRRTTL
InvalidRRTTL(const char *file, size_t line, const char *what)
Definition: rrttl.h:33
isc::dns::RRTTL::lthan
bool lthan(const RRTTL &other) const
Less-than comparison for RRTTL against other.
Definition: rrttl.h:242
isc::dns::RRTTL::gthan
bool gthan(const RRTTL &other) const
Greater-than comparison for RRTTL against other.
Definition: rrttl.h:256
isc::dns::RRTTL::createFromText
static RRTTL * createFromText(const std::string &ttlstr)
A separate factory of RRTTL from text.
Definition: rrttl.cc:176
isc::dns::InvalidRRTTL
A standard DNS module exception that is thrown if an RRTTL object is being constructed from an unreco...
Definition: rrttl.h:31
exceptions.h
isc::dns::AbstractMessageRenderer
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Definition: messagerenderer.h:68
isc::dns::RRTTL::RRTTL
RRTTL(uint32_t ttlval)
Constructor from an integer TTL value.
Definition: rrttl.h:68
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::dns::operator<<
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
isc::dns::RRTTL::getValue
uint32_t getValue() const
Returns the TTL value as a 32-bit unsigned integer.
Definition: rrttl.h:176
isc::dns::RRTTL::leq
bool leq(const RRTTL &other) const
Less-than or equal comparison for RRTTL against other.
Definition: rrttl.h:214
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
isc::dns::Exception
Definition: dns/exceptions.h:25
isc::dns::RRTTL::operator<
bool operator<(const RRTTL &other) const
Same as lthan()
Definition: rrttl.h:246
isc::dns::DNSTextError
Base class for all sorts of text parse errors.
Definition: dns/exceptions.h:34
isc::dns::RRTTL
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
isc::dns::RRTTL::nequals
bool nequals(const RRTTL &other) const
Return true iff two RRTTLs are not equal.
Definition: rrttl.h:202
isc::dns::RRTTL::toText
const std::string toText() const
Convert the RRTTL to a string.
Definition: rrttl.cc:192
isc::util::InputBuffer
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
isc::dns::RRTTL::operator<=
bool operator<=(const RRTTL &other) const
Same as leq()
Definition: rrttl.h:218
isc::dns::RRTTL::toWire
void toWire(AbstractMessageRenderer &renderer) const
Render the RRTTL in the wire format.
Definition: rrttl.cc:204
isc::dns::RRTTL::operator!=
bool operator!=(const RRTTL &other) const
Same as nequals().
Definition: rrttl.h:205
isc::dns::RRTTL::operator>=
bool operator>=(const RRTTL &other) const
Same as geq()
Definition: rrttl.h:232
isc::dns::IncompleteRRTTL
A standard DNS module exception that is thrown if an RRTTL object is being constructed from a incompl...
Definition: rrttl.h:41
isc::dns::RRTTL::geq
bool geq(const RRTTL &other) const
Greater-than or equal comparison for RRTTL against other.
Definition: rrttl.h:228
isc::dns::RRTTL::equals
bool equals(const RRTTL &other) const
Return true iff two RRTTLs are equal.
Definition: rrttl.h:192
isc::dns::RRTTL::operator>
bool operator>(const RRTTL &other) const
Same as gthan()
Definition: rrttl.h:260
isc::dns::RRTTL::MAX_TTL
static const RRTTL & MAX_TTL()
The TTL of the max allowable value, per RFC2181 Section 8.
Definition: rrttl.h:274
isc::dns::IncompleteRRTTL::IncompleteRRTTL
IncompleteRRTTL(const char *file, size_t line, const char *what)
Definition: rrttl.h:43
isc::dns::RRTTL::operator==
bool operator==(const RRTTL &other) const
Same as equals().
Definition: rrttl.h:195