|
@@ -15,10 +15,12 @@
|
|
|
#ifndef RRTTL_H
|
|
|
#define RRTTL_H 1
|
|
|
|
|
|
-#include <stdint.h>
|
|
|
-
|
|
|
#include <exceptions/exceptions.h>
|
|
|
|
|
|
+#include <boost/optional.hpp>
|
|
|
+
|
|
|
+#include <stdint.h>
|
|
|
+
|
|
|
namespace isc {
|
|
|
namespace util {
|
|
|
class InputBuffer;
|
|
@@ -30,6 +32,16 @@ namespace dns {
|
|
|
// forward declarations
|
|
|
class AbstractMessageRenderer;
|
|
|
|
|
|
+class RRTTL; // forward declaration to define MaybeRRTTL
|
|
|
+
|
|
|
+/// \brief A shortcut for a compound type to represent RRTTL-or-not.
|
|
|
+///
|
|
|
+/// A value of this type can be interpreted in a boolean context, whose
|
|
|
+/// value is \c true if and only if it contains a valid RRTTL object.
|
|
|
+/// And, if it contains a valid RRTTL object, its value is accessible
|
|
|
+/// using \c operator*, just like a bare pointer to \c RRTTL.
|
|
|
+typedef boost::optional<RRTTL> MaybeRRTTL;
|
|
|
+
|
|
|
///
|
|
|
/// \brief A standard DNS module exception that is thrown if an RRTTL object
|
|
|
/// is being constructed from an unrecognized string.
|
|
@@ -104,31 +116,35 @@ public:
|
|
|
/// A separate factory of RRTTL from text.
|
|
|
///
|
|
|
/// This static method is similar to the constructor that takes a string
|
|
|
- /// object, but works as a factory and reports parsing failure in return
|
|
|
- /// value. Normally the constructor version should suffice, but in some
|
|
|
- /// cases the caller may have to expect mixture of valid and invalid input,
|
|
|
- /// and may want to minimize the overhead of possible exception handling.
|
|
|
- /// This version is provided for such purpose.
|
|
|
- ///
|
|
|
- /// When the \c placeholder parameter is NULL, it creates a new RRTTL
|
|
|
- /// object, allocating memory for it; the caller is responsible for
|
|
|
- /// releasing the memory using the \c delete operator. If \c placeholder
|
|
|
- /// is non NULL, it will override the placeholder object with an RRTTL
|
|
|
- /// corresponding to the given text and return a pointer to the placeholder
|
|
|
- /// object. This way, the caller can also minimize the overhead of memory
|
|
|
- /// allocation if it needs to call this method many times.
|
|
|
- ///
|
|
|
- /// If the given text does not represent a valid RRTTL, it returns NULL;
|
|
|
- /// if \c placeholder is non NULL, it will be intact.
|
|
|
+ /// object, but works as a factory and reports parsing failure in the
|
|
|
+ /// form of the return value. Normally the constructor version should
|
|
|
+ /// suffice, but in some cases the caller may have to expect mixture of
|
|
|
+ /// valid and invalid input, and may want to minimize the overhead of
|
|
|
+ /// possible exception handling. This version is provided for such
|
|
|
+ /// purpose.
|
|
|
+ ///
|
|
|
+ /// If the given text represents a valid RRTTL, it returns a \c MaybeRRTTL
|
|
|
+ /// object that stores a corresponding \c RRTTL object, which is
|
|
|
+ /// accessible via \c operator*(). In this case the returned object will
|
|
|
+ /// be interpreted as \c true in a boolean context. If the given text
|
|
|
+ /// does not represent a valid RRTTL, it returns a \c MaybeRRTTL object
|
|
|
+ /// which is interpreted as \c false in a boolean context.
|
|
|
+ ///
|
|
|
+ /// One main purpose of this function is to minimize the overhead
|
|
|
+ /// when the given text does not represent a valid RR TTL. For this
|
|
|
+ /// reason this function intentionally omits the capability of delivering
|
|
|
+ /// details reason for the parse failure, such as in the \c want()
|
|
|
+ /// string when exception is thrown from the constructor (it will
|
|
|
+ /// internally require a creation of string object, which is relatively
|
|
|
+ /// expensive). If such detailed information is necessary, the constructor
|
|
|
+ /// version should be used to catch the resulting exception.
|
|
|
///
|
|
|
/// This function never throws the \c InvalidRRTTL exception.
|
|
|
///
|
|
|
/// \param ttlstr A string representation of the \c RRTTL.
|
|
|
- /// \param placeholder If non NULL, an RRTTL object to be overridden
|
|
|
- /// with an RRTTL for \c ttlstr.
|
|
|
- /// \return A pointer to the created or overridden RRTTL object.
|
|
|
- static RRTTL* createFromText(const std::string& ttlstr,
|
|
|
- RRTTL* placeholder);
|
|
|
+ /// \return An MaybeRRTTL object either storing an RRTTL object for
|
|
|
+ /// the given text or a \c false value.
|
|
|
+ static MaybeRRTTL createFromText(const std::string& ttlstr);
|
|
|
///
|
|
|
//@}
|
|
|
|